Commit Graph

230 Commits

Author SHA1 Message Date
f485241dd7 Merge branch 'main' into ai/paper-dynasty-card-creation#10 2026-03-23 03:53:10 +00:00
6d0497431f Merge pull request 'fix: remove dead LAST_WEEK_RATIO ternary — both branches are 0.0 (#19)' (#45) from ai/paper-dynasty-card-creation-19 into main 2026-03-23 03:52:58 +00:00
f5cb72cc26 Merge branch 'main' into ai/paper-dynasty-card-creation-19 2026-03-23 03:52:52 +00:00
f67d111a66 Merge pull request 'fix: remove test_positions_df non-test that always passes (#16)' (#43) from ai/paper-dynasty-card-creation-16 into main 2026-03-23 03:52:48 +00:00
230f3e79ce Merge branch 'main' into ai/paper-dynasty-card-creation-16 2026-03-23 03:52:41 +00:00
ecc62a0521 Merge pull request 'fix: correct get_of() opposite-field direction for switch hitters' (#40) from ai/paper-dynasty-card-creation#5 into main 2026-03-23 03:52:38 +00:00
992feba79e Merge branch 'main' into ai/paper-dynasty-card-creation#5 2026-03-23 03:52:32 +00:00
57c379a8e0 Merge branch 'main' into ai/paper-dynasty-card-creation#10 2026-03-23 03:52:23 +00:00
e413fd5cc8 Merge pull request 'fix: return default 8 on XBT% parse error in running() (#8)' (#37) from ai/paper-dynasty-card-creation#8 into main 2026-03-23 03:52:19 +00:00
6a6767f5d8 Merge branch 'main' into ai/paper-dynasty-card-creation#8 2026-03-23 03:52:13 +00:00
2b955dd8f7 Merge pull request 'fix: resolve unreachable duplicate elif 'DO*' branch in result_string() (#6)' (#39) from ai/paper-dynasty-card-creation#6 into main 2026-03-23 03:51:33 +00:00
0e66ff71e7 Merge branch 'main' into ai/paper-dynasty-card-creation-19 2026-03-23 03:51:06 +00:00
b55820eec8 Merge branch 'main' into ai/paper-dynasty-card-creation-16 2026-03-23 03:51:01 +00:00
b4a3e4b865 Merge branch 'main' into ai/paper-dynasty-card-creation#5 2026-03-23 03:50:56 +00:00
bb546c6ded Merge branch 'main' into ai/paper-dynasty-card-creation#10 2026-03-23 03:50:51 +00:00
5c7c613813 Merge branch 'main' into ai/paper-dynasty-card-creation#8 2026-03-23 03:50:47 +00:00
cbfcba5e26 Merge branch 'main' into ai/paper-dynasty-card-creation#6 2026-03-23 03:50:40 +00:00
006b48e60f Merge pull request 'fix: use player_id instead of key_bbref in create_pit_position() (#7)' (#38) from ai/paper-dynasty-card-creation#7 into main 2026-03-23 03:50:38 +00:00
5e135ff554 Merge branch 'main' into ai/paper-dynasty-card-creation#7 2026-03-23 03:50:35 +00:00
602151fb16 Merge pull request 'Remove hardcoded secrets, load API token from env' (#29) from fix/2-3-security-hardcoded-secrets into main 2026-03-23 03:50:07 +00:00
6c20f93901 Merge branch 'main' into fix/2-3-security-hardcoded-secrets 2026-03-23 03:50:00 +00:00
Cal Corum
937620e2e9 fix: remove dead LAST_WEEK_RATIO ternary — both branches are 0.0 (#19)
Closes #19

The conditional `0.0 if PLAYER_DESCRIPTION == 'Live' else 0.0` is dead
code: both branches evaluate to the same value. Simplified to a direct
assignment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 07:03:38 -05:00
Cal Corum
5b8d027d46 fix: remove test_positions_df non-test that always passes (#16)
Closes #16

Deleted test_positions_df which called an async function synchronously
(returning a coroutine, not a DataFrame) and asserted True == True.
Zero coverage. Also removed the now-unused pd_positions_df import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 02:02:10 -05:00
Cal Corum
a2e374cd4f fix: correct get_of() opposite-field direction for switch hitters
Switch hitters batting vs LHP hit right-handed (pull=lf, oppo=rf).
Switch hitters batting vs RHP hit left-handed (pull=rf, oppo=lf).
Copy-paste error had both pull_side branches returning the same value.

Closes #5

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 00:02:01 -05:00
Cal Corum
b52c5418db fix: resolve unreachable duplicate elif 'DO*' branch in result_string() (#6)
The second `elif "DO*" in data_string` was dead code — the first always
matched, so `spaces -= 2` for the DO** variant was silently skipped.
Fix: check "DO**" first (spaces -= 2), then "DO*" (spaces -= 1).

Closes #6

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 23:33:06 -05:00
Cal Corum
1d96223c78 fix: use player_id instead of key_bbref in create_pit_position() (#7)
Closes #7

The fallback branch of create_pit_position() used `int(df_data["key_bbref"])`
which always raises ValueError for string IDs like 'verlaju01'. The exception
was silently swallowed, causing pitchers without defensive stats to receive no
position record at all.

Fix: use `int(float(df_data["player_id"]))` to match the pattern used in
create_pitching_card() on the same file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 23:03:43 -05:00
Cal Corum
8e24b4e686 fix: return default 8 on XBT% parse error in running() (#8)
Closes #8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 21:32:14 -05:00
Cal Corum
46fdde3d02 fix: narrow swallowed exception in get_pitching_peripherals() (#10)
Closes #10

Replace `except Exception: pass` with `except KeyError: pass` so only
the expected missing-attribute case (`cell["data-append-csv"]` not
present) is silently skipped. Network errors, encoding issues, and
other unexpected exceptions will now propagate instead of being hidden.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 20:02:55 -05:00
Cal Corum
e3220bf337 Remove hardcoded secrets, load API token from environment
- Replace hardcoded PD API bearer token in db_calls.py with dotenv/env var
- Delete scripts/supabase_doodling.py (dead scratch file with hardcoded Supabase JWT)
- Add python-dotenv dependency and .env.example template
- Consolidate check_prod_missing_ratings.py to import AUTH_TOKEN from db_calls
- Hard fail if PD_API_TOKEN is missing to prevent silent auth failures

Fixes #2, Fixes #3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 12:38:01 -05:00
cal
f1ca14791d Merge pull request 'feat: render pipeline optimization (Phase 0)' (#28) from feature/render-pipeline-optimization into main
Reviewed-on: #28
2026-03-17 15:58:39 +00:00
Cal Corum
81622cceb3 docs: update Phase 0 status with PR references
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 10:13:18 -05:00
Cal Corum
8bddf31bf6 feat: configurable API URL for local high-concurrency card rendering
Allow upload scripts to target a local API server instead of the remote
production server, enabling 32x+ concurrency for dramatically faster
full-cardset uploads (~30-45s vs ~2-3min for 800 cards).

- pd_cards/core/upload.py: add api_url param to upload_cards_to_s3(),
  refresh_card_images(), and check_card_images()
- pd_cards/commands/upload.py: add --api-url CLI option to upload s3
- check_cards_and_upload.py: read PD_API_URL env var with prod fallback
- Update CLAUDE.md, CLI reference, and Phase 0 project plan docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 10:27:16 -05:00
cal
6e20a98226 Merge pull request 'feat: Phase 0 concurrent upload pipeline and benchmarks' (#27) from feature/render-pipeline-optimization into main
Reviewed-on: #27
2026-03-13 15:56:18 +00:00
Cal Corum
ed1daa20b0 fix: use get_running_loop() instead of deprecated get_event_loop()
get_event_loop() is deprecated in Python 3.10+ when called inside
a running coroutine. get_running_loop() is the correct replacement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 08:50:51 -05:00
Cal Corum
979f3080d5 feat: concurrent upload pipeline and benchmarks (Phase 0)
- Replace sequential upload loop with asyncio.gather + Semaphore(8) (WP-04)
- Offload synchronous boto3 S3 calls to thread pool executor
- Increase fetch_card_image timeout from 6s to 10s
- Add --concurrency/-j CLI flag to pd-cards upload
- Add progress reporting every 20 completions
- Individual card failures no longer abort batch
- Apply same concurrency pattern to legacy check_cards_and_upload.py (WP-05)
- Add benchmark script for render pipeline measurements (WP-00)

Target: 800-card upload from ~40 min to <5 min (with server-side
persistent browser deployed).

Refs: #87, #91, #92

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 23:53:56 -05:00
cal
336014b689 Merge pull request 'Fix hold rating formula and format codebase' (#23) from fix/hold-rating-and-formatting into main
Reviewed-on: #23
2026-03-10 15:47:58 +00:00
Cal Corum
c2f7181f5b Remove unused defenders/creation.py stub
Single-line file with invalid syntax, not imported anywhere.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:24:33 -05:00
Cal Corum
0a17745389 Run black and ruff across entire codebase
Standardize formatting with black and apply ruff auto-fixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:24:33 -05:00
Cal Corum
7fd691690c Fix pitcher hold rating: change pickoffs from override to bonus modifier
Pickoffs were using min(pick_cap, hold_num) which let high pickoff counts
completely override bad CS%, giving 31% of pitchers a -3 hold rating.
Now pickoffs act as a 1-3 point bonus on top of the CS%-based rating.
Pitchers with no CS data default to +2 (capped at -1 with pickoff bonus)
instead of the old +9.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:24:24 -05:00
cal
a4e56f6062 Merge pull request 'Fix SLG formula in extracted card rating models' (#22) from feature/fullcard-migration into main
Reviewed-on: #22
2026-03-03 21:59:06 +00:00
Cal Corum
931416a7c7 Add FullCard migration status doc for session continuity
Documents current branch state, what's built, what's left,
known bugs, and decision points so the next session can pick
up without re-investigating.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 23:58:55 -06:00
Cal Corum
db3822565c Add offense_col resolver for retrosheet pipeline to fix 883 silent KeyErrors
The FullCard migration requires offense_col and player_id on each player's
DataFrame row. The retrosheet pipeline calculates ratings before posting,
so both fields were missing — causing silent card layout builder failures.

Adds a three-tier resolution: CSV cache → API bulk fetch → deterministic
hash fallback. Also includes player_id fallback in both calcs modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 15:37:59 -06:00
Cal Corum
32cadb1c49 Fix two bugs in pitcher card builder dispatch logic
Fix duplicate elif branch in HR overflow cascade that prevented
single_one from receiving excess chances, and reorder single_two
secondary dispatch to check flyout full_name before groundout
short_name to prevent false 'B' matches on fly ball results.
Also add missing new_ratings.flyout_cf_b increment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 12:04:51 -06:00
Cal Corum
2bf3a6cee7 Fix SLG formula drift in extracted rating models
The extracted batting and pitching models used malformed SLG equations that double-counted and omitted outcomes, skewing slash lines. Align formulas with canonical weighting and add regression tests to prevent recurrence.

Co-Authored-By: Claude GPT-5.3-Codex <noreply@anthropic.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-26 07:47:15 -06:00
Cal Corum
39c652e55c Extract BattingCardRatingsModel and PitchingCardRatingsModel into models.py files
Move each ratings model class (and, for batters, the helper functions it
depends on) into a dedicated models.py so that calcs_*.py can import from
card_builder.py at module level without circular imports.

- batters/models.py: BattingCardRatingsModel + bp_singles, wh_singles,
  one_singles, bp_homeruns, triples, two_doubles, hit_by_pitch, strikeouts,
  flyout_a, flyout_bq, flyout_b, groundball_a, groundball_c
- pitchers/models.py: PitchingCardRatingsModel (no helper deps needed)
- batters/calcs_batter.py: imports model + build_batter_full_cards at top
- pitchers/calcs_pitcher.py: imports model + build_pitcher_full_cards at top
- batters/card_builder.py: imports from batters.models
- pitchers/card_builder.py: imports from pitchers.models
- tests/test_batter_calcs.py: import bp_singles, wh_singles from batters.models

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-25 16:42:51 -06:00
Cal Corum
a72abc01a3 Add FullCard/CardColumn/CardResult models and card builder pipeline
- card_layout.py: Port PlayResult, PLAY_RESULTS, EXACT_CHANCES, get_chances(),
  CardResult, CardColumn, FullCard, FullBattingCard, FullPitchingCard from
  database/app/card_creation.py. card_output() uses col_* key names.
  get_chances() always returns Decimal to avoid float/Decimal type errors.

- batters/card_builder.py: Port get_batter_card_data() algorithm as
  build_batter_full_cards(ratings_vl, ratings_vr, offense_col, player_id, hand).
  assign_bchances() returns float tuples for compatibility with float-based
  BattingCardRatingsModel fields.

- pitchers/card_builder.py: Port get_pitcher_card_data() algorithm as
  build_pitcher_full_cards(). assign_pchances() returns float tuples.
  Includes card.add_fatigue() at end of each card iteration.

- batters/calcs_batter.py: Integrate card builder in get_batter_ratings().
  After computing raw ratings, call build_batter_full_cards() and merge
  9 col_* rendered column fields into each ratings dict. Lazy import to
  avoid circular dependency.

- pitchers/calcs_pitcher.py: Same integration for get_pitcher_ratings().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-25 16:21:26 -06:00
cal
7c967b6119 Merge pull request 'Add card generation pipeline agents' (#1) from add-card-pipeline-agents into main
Reviewed-on: #1
2026-02-16 20:18:37 +00:00
Cal Corum
fe91de905a Add card generation pipeline agents and refresh scouting data
- Add retrosheet-card-update agent (8-step pipeline with validation gates)
- Add live-series-card-update agent (7-step pipeline with PotM support)
- Both agents: dev/prod S3 guard, environment verification, groundball_b validation
- Restore db_calls.py to production (alt_database = None)
- Refresh scouting reports (6303 batters, 7164 pitchers)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 14:16:50 -06:00
Cal Corum
923edd0eeb Update 2005 Live cardset through mid-August (73% season)
790 players (397 batters, 393 pitchers) processed from Retrosheet data
through 2005-08-15 with 0.728 season percentage. Includes updated scouting
reports, card deltas, and FanGraphs scrape script.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 18:56:19 -06:00
Cal Corum
9e8dc4ef96 Rename Sippie Swartzel to Sippie Swartzel Sr 2026-01-25 22:50:34 -06:00