Add recency bias CLI flags to retrosheet command

- 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 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-12-21 16:38:12 -06:00
parent 5b75a3d38f
commit 0fe549449d

View File

@ -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)