- Correct idempotency guard docstring in update_season_stats() to
accurately describe the last_game FK check limitation: only detects
replay of the most-recently-processed game; out-of-order re-delivery
(game G after G+1) bypasses the guard. References issue #105 for the
planned ProcessedGame ledger fix.
- Fix migration card_type comment: 'batting' or 'pitching' → 'batter',
'sp', or 'rp' to match actual seeded values.
- Remove local rarity fixture in test_season_stats_update.py that
shadowed the conftest.py fixture; remove unused rarity parameter from
player_batter and player_pitcher fixtures.
- Update test_double_count_prevention docstring to note the known
out-of-order re-delivery limitation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- CRITICAL: Fix migration FK refs player(id) → player(player_id)
- Remove dead is_start flag from pitching groups (no starts column)
- Fix hr → homerun in test make_play helper
- Add explanatory comment to ruff.toml
- Replace print() with logging in seed script
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
JSON definitions and idempotent seed function for the 3 universal
evolution tracks (Batter, Starting Pitcher, Relief Pitcher) with
locked threshold values.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implement update_season_stats(game_id) in app/services/season_stats.py.
Aggregates StratPlay batting/pitching stats and Decision win/loss/save
data into PlayerSeasonStats with idempotency guard and dual-backend
upsert (PostgreSQL EXCLUDED increments, SQLite read-modify-write).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Creates player_season_stats, evolution_track, evolution_card_state,
evolution_tier_boost, and evolution_cosmetic tables with IF NOT EXISTS
guards, appropriate indexes, and rollback statements. Also extends card,
battingcard, and pitchingcard with variant and image_url columns.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds the PlayerSeasonStats model to db_engine.py with 14 batting stat
fields, 11 pitching stat fields, last_game/last_updated_at meta fields,
and composite indexes: UNIQUE(player,team,season), (team,season),
(player,season). Also simplifies ruff.toml to a global ignore for
F403/F405 (intentional peewee star import pattern).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add EvolutionTrack, EvolutionCardState, EvolutionTierBoost, and
EvolutionCosmetic models to db_engine.py with composite unique indexes
and create_tables blocks. Also includes PlayerSeasonStats (WP-02).
Add ruff.toml to suppress pre-existing F403/F405 from intentional
`from peewee import *` wildcard import pattern in db_engine.py.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Resolve conflicts in app/main.py and app/routers_v2/players.py:
keep main's render pipeline optimization (Phase 0) with asyncio.Lock,
error-tolerant shutdown, and --no-sandbox launch args. The next-release
browser code was an earlier version of the same feature.
Add evolution router import and inclusion from next-release.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract shared pitcher value computation into _pitcher_value() helper.
Consolidate duplicated column lists and index helper in season stats tests.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Separate batting and pitching into distinct tables with descriptive column
names. Eliminates naming collisions (so/k ambiguity) and column mismatches
between the ORM model and raw SQL. Each table now covers all aggregatable
fields from its source (BattingStat/PitchingStat) including sac, ibb, gidp,
earned_runs, runs_allowed, wild_pitches, balks, and games_started.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The single-letter `k` field was ambiguous and too short for comfortable use.
Rename to `so_pitcher` for clarity, and `so` to `so_batter` to distinguish
batting strikeouts from pitching strikeouts in the same model.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Registry cache export consistently fails with 400 Bad Request from
Docker Hub, likely due to blob size limits on the free tier after the
base image change. Removing cache-from/cache-to entirely — builds are
fast enough without it (~2 min), and we can re-add with a local cache
backend later if needed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mode=max pushes all intermediate layers to Docker Hub as cache, which
exceeds blob size limits when the base image changes. mode=min only
caches final image layers — smaller push, still provides cache hits
for the most common rebuild scenario (code changes, same base).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The tiangolo/uvicorn-gunicorn-fastapi image moved to Debian Trixie
(testing) which Playwright doesn't support — install-deps fails on
renamed font packages. The tiangolo image only adds uvicorn/gunicorn
which are already in requirements.txt, so switch to the official Python
slim-bookworm image directly. Also removes the old commented-out Chrome
manual install block that hasn't been used since the Playwright migration.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The tiangolo base image recently moved to Debian Trixie (testing), which
Playwright doesn't support yet. `playwright install-deps` fails because
ttf-unifont and ttf-ubuntu-font-family packages were renamed/removed in
Trixie. Pinning to slim-bookworm (Debian 12) restores compatibility.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace per-request Chromium launch/teardown with a module-level
persistent browser. get_browser() lazy-initializes with is_connected()
auto-reconnect; shutdown_browser() is wired into FastAPI lifespan for
clean teardown. Pages are created per-request and closed in a finally
block to prevent leaks.
Also fixed pre-existing ruff errors in staged files (E402 noqa comments,
F541 f-string prefix removal, F841 unused variable rename) that were
blocking the pre-commit hook.
Closes#89
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Address two review findings from PR #94:
1. Race condition: concurrent requests could both launch Chromium when
_browser is None. Wrap the init check in asyncio.Lock so only one
coroutine creates the browser process.
2. Font duplication: the WOFF2 files are variable fonts covering all
needed weights. Consolidate 5 @font-face blocks (3x Open Sans,
2x Source Sans 3) into 2 using CSS font-weight range syntax,
saving ~163KB of redundant base64 per render.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Closes#71
Adds GET /api/v2/evolution/tracks and GET /api/v2/evolution/tracks/{track_id}
endpoints for browsing evolution tracks and their thresholds. Both endpoints
require Bearer token auth and return a track dict with formula and t1-t4
threshold fields. The card_type query param filters the list endpoint.
EvolutionTrack is lazy-imported inside each handler so the app can start
before WP-01 (EvolutionTrack model) is merged into next-release.
Also suppresses pre-existing E402/F541 ruff warnings in app/main.py via
pyproject.toml per-file-ignores so the pre-commit hook does not block
unrelated future commits to that file.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Closes#74
Adds app/services/formula_engine.py with three pure formula functions
(compute_batter_value, compute_sp_value, compute_rp_value), a dispatch
helper (compute_value_for_track), and a tier classifier (tier_from_value).
Tier boundaries and thresholds match the locked seed data from WP-03.
Note: pitcher formulas use stats.k (not stats.so) to match the
PlayerSeasonStats model field name introduced in WP-02.
19 unit tests in tests/test_formula_engine.py — all pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Evolution models (EvolutionTrack, EvolutionCardState, EvolutionTierBoost,
EvolutionCosmetic), their re-export module, and tests were included in
this PR without disclosure. Removed to keep this PR scoped to
PlayerSeasonStats (WP-02) only per review feedback.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When no position filters are applied, `final_players` is a lazy Peewee queryset
with `ORDER BY RANDOM() LIMIT n`. Iterating it twice (once to build player_ids,
once for the response loop) executes two separate DB queries with different random
seeds, causing dex_by_player to be built for a different player set than returned,
silently producing empty paperdex for all players.
Add `final_players = list(final_players)` before building player_ids to ensure
both iterations operate on the same materialized result. Also fix pre-existing
syntax error in import statement and minor ruff lint issues in the same file.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Starters face both LHH and RHH, so the OPS aggregation formula should
penalise the weaker platoon split (higher OPS allowed) rather than
reward the stronger one. Changed min(ops_vl, ops_vr) → max(ops_vl, ops_vr)
in both get_total_ops (line 621) and sort_starters (line 703) and
replaced the TODO comment with an explanatory note.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The /live-update/pitching POST endpoint was a placeholder that only
validated auth and returned the input unchanged. No pitching processing
logic existed anywhere in the codebase. Removed the dead endpoint.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace per-player/card Paperdex.select().where() calls with a single
batched query grouped by player_id. Eliminates N+1 queries in:
- players list endpoint (get_players, with inc_dex flag)
- players by team endpoint
- cards list endpoint (also materializes query to avoid double count())
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>