paper-dynasty-card-creation/pd_cards/commands/retrosheet.py
Cal Corum 2e28d29ced Add pd-cards CLI skeleton with Typer
Introduces new pd-cards CLI tool for all card creation workflows:
- custom: manage fictional character cards via YAML profiles
- live-series: live season card updates (stub)
- retrosheet: historical data processing (stub)
- scouting: scouting report generation (stub)
- upload: S3 card image upload (stub)

Key features:
- Typer-based CLI with auto-generated help and shell completion
- YAML profiles for custom characters (replaces per-character Python scripts)
- Preview, submit, new, and list commands for custom cards
- First character migrated: Kalin Young

Install with: uv pip install -e .
Run with: pd-cards --help

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 16:08:32 -06:00

108 lines
3.7 KiB
Python

"""
Retrosheet historical data processing commands.
Commands for generating cards from historical Retrosheet play-by-play data.
"""
from pathlib import Path
from typing import Optional
import typer
from rich.console import Console
app = typer.Typer(no_args_is_help=True)
console = Console()
@app.command()
def process(
year: int = typer.Argument(..., help="Season year to process (e.g., 2005)"),
cardset_id: int = typer.Option(..., "--cardset-id", "-c", help="Target cardset ID"),
description: str = typer.Option("Live", "--description", "-d", help="Player description (e.g., 'Live', 'June PotM')"),
start_date: Optional[str] = typer.Option(None, "--start", help="Start date YYYYMMDD (defaults to season start)"),
end_date: Optional[str] = typer.Option(None, "--end", help="End date YYYYMMDD (defaults to season end)"),
events_file: Optional[Path] = typer.Option(None, "--events", "-e", help="Retrosheet events CSV file"),
dry_run: bool = typer.Option(False, "--dry-run", "-n", help="Preview without saving to database"),
):
"""
Process Retrosheet data and create player cards.
Generates batting and pitching cards from historical play-by-play data.
"""
console.print()
console.print("=" * 70)
console.print(f"[bold]RETROSHEET PROCESSING - {year}[/bold]")
console.print("=" * 70)
console.print(f"Cardset ID: {cardset_id}")
console.print(f"Description: {description}")
if start_date:
console.print(f"Start Date: {start_date}")
if end_date:
console.print(f"End Date: {end_date}")
if dry_run:
console.print("[yellow]DRY RUN - no changes will be made[/yellow]")
# TODO: Migrate logic from retrosheet_data.py
console.print()
console.print("[yellow]Not yet implemented - run legacy script:[/yellow]")
console.print(" python retrosheet_data.py")
console.print()
console.print("[dim]Configure settings in retrosheet_data.py before running[/dim]")
raise typer.Exit(0)
@app.command()
def arms(
year: int = typer.Argument(..., help="Season year"),
events_file: Path = typer.Option(..., "--events", "-e", help="Retrosheet events CSV file"),
output: Optional[Path] = typer.Option(None, "--output", "-o", help="Output CSV file"),
):
"""
Generate outfield arm ratings from Retrosheet data.
Analyzes play-by-play events to calculate OF arm strength ratings.
"""
console.print()
console.print("=" * 70)
console.print(f"[bold]OUTFIELD ARM RATINGS - {year}[/bold]")
console.print("=" * 70)
if output is None:
output = Path(f"data-output/retrosheet_arm_ratings_{year}.csv")
console.print(f"Events file: {events_file}")
console.print(f"Output: {output}")
# TODO: Migrate logic from generate_arm_ratings_csv.py
console.print()
console.print("[yellow]Not yet implemented - run legacy script:[/yellow]")
console.print(f" python generate_arm_ratings_csv.py --year {year} --events {events_file}")
raise typer.Exit(0)
@app.command()
def validate(
cardset_id: int = typer.Argument(..., help="Cardset ID to validate"),
api_url: str = typer.Option("https://pd.manticorum.com/api", "--api", help="API URL"),
):
"""
Validate positions for a cardset.
Checks for anomalous DH counts and missing outfield positions.
"""
console.print()
console.print("=" * 70)
console.print(f"[bold]POSITION VALIDATION - Cardset {cardset_id}[/bold]")
console.print("=" * 70)
# TODO: Migrate logic from scripts/check_positions.sh
console.print()
console.print("[yellow]Not yet implemented - run legacy script:[/yellow]")
console.print(f" ./scripts/check_positions.sh {cardset_id} {api_url}")
raise typer.Exit(0)