From 0fe549449d095218d316d90f946b6df1dba512d1 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sun, 21 Dec 2025 16:38:12 -0600 Subject: [PATCH] Add recency bias CLI flags to retrosheet command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add --last-week-ratio, --last-twoweeks-ratio, --last-month-ratio flags - Auto-enable 0.2 recency bias for last 2 weeks on Live series after May 30 - Fix main() call to pass empty args list (legacy parameter required) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- pd_cards/commands/retrosheet.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pd_cards/commands/retrosheet.py b/pd_cards/commands/retrosheet.py index 07a4e0e..6890901 100644 --- a/pd_cards/commands/retrosheet.py +++ b/pd_cards/commands/retrosheet.py @@ -29,6 +29,9 @@ def process( min_pa_vr: int = typer.Option(None, "--min-pa-vr", help="Minimum PA vs RHP (default: 40 Live, 1 PotM)"), post_data: bool = typer.Option(True, "--post/--no-post", help="Post data to database"), dry_run: bool = typer.Option(False, "--dry-run", "-n", help="Preview without saving to database"), + last_week_ratio: float = typer.Option(0.0, "--last-week-ratio", help="Recency bias: weight for last week's stats (0.0-1.0)"), + last_twoweeks_ratio: Optional[float] = typer.Option(None, "--last-twoweeks-ratio", help="Recency bias: weight for last 2 weeks' stats (0.0-1.0, default: 0.2 for Live after May 30)"), + last_month_ratio: float = typer.Option(0.0, "--last-month-ratio", help="Recency bias: weight for last month's stats (0.0-1.0)"), ): """ Process Retrosheet data and create player cards. @@ -62,6 +65,15 @@ def process( if data_input is None: data_input = f"data-input/{year} Live Cardset/" + # Auto-enable recency bias for Live series after May 30 + if last_twoweeks_ratio is None: + end_mmdd = int(end_date[4:]) # Extract MMDD from YYYYMMDD + if is_live and end_mmdd > 530: + last_twoweeks_ratio = 0.2 + console.print(f"[cyan]Auto-enabled recency bias (end date > May 30)[/cyan]") + else: + last_twoweeks_ratio = 0.0 + console.print(f"Cardset ID: {cardset_id}") console.print(f"Description: {description}") console.print(f"Date Range: {start_date} - {end_date}") @@ -69,6 +81,8 @@ def process( console.print(f"Min PA: vL={min_pa_vl}, vR={min_pa_vr}") console.print(f"Events: {events_file}") console.print(f"Input: {data_input}") + if last_week_ratio > 0 or last_twoweeks_ratio > 0 or last_month_ratio > 0: + console.print(f"Recency Bias: week={last_week_ratio}, 2weeks={last_twoweeks_ratio}, month={last_month_ratio}") console.print() if dry_run: @@ -99,12 +113,15 @@ def process( rd.POST_DATA = post_data rd.EVENTS_FILENAME = events_file rd.DATA_INPUT_FILE_PATH = data_input + rd.LAST_WEEK_RATIO = last_week_ratio + rd.LAST_TWOWEEKS_RATIO = last_twoweeks_ratio + rd.LAST_MONTH_RATIO = last_month_ratio console.print("[bold]Starting Retrosheet processing...[/bold]") console.print() - # Run the main function - asyncio.run(rd.main()) + # Run the main function (args is legacy, pass empty list) + asyncio.run(rd.main([])) console.print() console.print("=" * 70)