Commit Graph

435 Commits

Author SHA1 Message Date
cal
a481c5361a Merge branch 'main' into issue/149-feat-add-limit-pagination-to-scout-claims-endpoint 2026-03-24 12:04:26 +00:00
Cal Corum
87c200d62b feat: add limit/pagination to paperdex endpoint (#143)
Closes #143

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 07:02:47 -05:00
Cal Corum
9d471ec1de feat: add limit/pagination to gamerewards endpoint (#144)
Closes #144

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 06:32:10 -05:00
Cal Corum
2da984f1eb feat: add limit/pagination to gauntletrewards endpoint (#145)
Closes #145

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 06:02:02 -05:00
Cal Corum
4f693b1228 feat: add limit/pagination to stratgame (games) endpoint (#138)
Closes #138

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 05:32:28 -05:00
Cal Corum
15aac6cb73 feat: add limit/pagination to results endpoint (#137)
Closes #137

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 05:02:35 -05:00
Cal Corum
9391591263 feat: add limit/pagination to mlbplayers endpoint (#141)
Closes #141

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 04:32:15 -05:00
Cal Corum
2f56942721 feat: add limit/pagination to pitchingcardratings endpoint (#136)
Closes #136

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 04:02:46 -05:00
Cal Corum
dc88b1539c feat: add limit/pagination to battingcardratings endpoint (#135)
Closes #135

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 03:03:13 -05:00
Cal Corum
8c9aa55609 feat: add limit/pagination to pitstats endpoint (#134)
Closes #134

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 02:32:10 -05:00
Cal Corum
e328ad639a feat: add limit/pagination to awards endpoint (#132)
Add optional limit query param (default 100, max 500) to GET /api/v2/awards.
Clamped via max(0, min(limit, 500)) to guard negative values and upper bound.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 02:01:50 -05:00
Cal Corum
0f884a3516 feat: add limit/pagination to events endpoint (#147)
Closes #147

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 01:32:19 -05:00
Cal Corum
6034b4f173 feat: add limit/pagination to batstats endpoint (#133)
Closes #133

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 01:03:12 -05:00
Cal Corum
f9817b3d04 feat: add limit/pagination to scout_opportunities endpoint (#148)
Closes #148

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 00:32:27 -05:00
cal
6a217f97ee Merge pull request 'ci: database CI catchup — local buildx cache + dev tag trigger' (#153) from ci/database-ci-catchup into main
All checks were successful
Build Docker Image / build (push) Successful in 7m53s
2026-03-24 05:17:04 +00:00
Cal Corum
d0f45d5d38 ci: switch buildx cache from registry to local volume
Replaces type=registry cache (which causes 400 errors from Docker Hub
due to stale buildx builders) with type=local backed by a named Docker
volume on the runner. Adds cache rotation step to prevent unbounded growth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 00:15:38 -05:00
Cal Corum
c185d72f1b ci: add dev tag trigger to Docker build workflow
Allows deploying to dev environment by pushing a "dev" tag.
Dev tags build with :dev Docker tag instead of :production.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 00:15:38 -05:00
Cal Corum
890625e770 feat: add limit/pagination to rewards endpoint (#139)
Closes #139

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 00:02:08 -05:00
Cal Corum
f3aab6fb73 feat: add limit/pagination to scout_claims endpoint (#149)
Closes #149

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:32:01 -05:00
Cal Corum
426d559387 feat: add limit/pagination to notifications endpoint (#140)
Closes #140

Adds optional `limit` query param to `GET /api/v2/notifs` with default
100 and max 500. Limit is applied after all filters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:02:18 -05:00
Cal Corum
e12dac347e ci: switch buildx cache from registry to local volume
All checks were successful
Build Docker Image / build (push) Successful in 10m39s
Replaces type=registry cache (which causes 400 errors from Docker Hub
due to stale buildx builders) with type=local backed by a named Docker
volume on the runner. Adds cache rotation step to prevent unbounded growth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 21:16:00 -05:00
Cal Corum
d4d93cd95e ci: add dev tag trigger to Docker build workflow
Some checks are pending
Build Docker Image / build (push) Waiting to run
Allows deploying to dev environment by pushing a "dev" tag.
Dev tags build with :dev Docker tag instead of :production.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 16:05:17 -05:00
cal
6a7400484e Merge pull request 'refactor: rename Evolution system to Refractor' (#131) from refactor/evolution-to-refractor-rename into main 2026-03-23 19:23:49 +00:00
Cal Corum
dc937dcabc fix: update stale evolution comment in cards.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 14:23:00 -05:00
Cal Corum
500a8f3848 fix: complete remaining evolution→refractor renames from review
- Rename route /{team_id}/evolutions → /{team_id}/refractors
- Rename function initialize_card_evolution → initialize_card_refractor
- Rename index names in migration SQL
- Update all test references

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 14:17:03 -05:00
Cal Corum
b7dec3f231 refactor: rename evolution system to refractor
Complete rename of the card progression system from "Evolution" to
"Refractor" across all code, routes, models, services, seeds, and tests.

- Route prefix: /api/v2/evolution → /api/v2/refractor
- Model classes: EvolutionTrack → RefractorTrack, etc.
- 12 files renamed, 8 files content-edited
- New migration to rename DB tables
- 117 tests pass, no logic changes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:31:55 -05:00
cal
0b6e85fff9 Merge pull request 'feat: Card Evolution Phase 1 — full backend implementation' (#130) from card-evolution into main 2026-03-23 18:20:20 +00:00
cal
c3b616dcfa Merge branch 'main' into card-evolution 2026-03-23 18:20:07 +00:00
Cal Corum
5ea4c7c86a fix: replace datetime.utcnow() with datetime.now() in evaluator
All checks were successful
Build Docker Image / build (pull_request) Successful in 8m36s
Fixes regression from PR #118 — utcnow() was reintroduced in
evolution_evaluator.py.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 12:54:01 -05:00
Cal Corum
d15fc97afb fix: add pitcher_id null guard in _get_player_pairs
All checks were successful
Build Docker Image / build (pull_request) Successful in 8m53s
Prevents (None, team_id) tuples from being added to pitching_pairs
when a StratPlay row has no pitcher (edge case matching the existing
batter_id guard).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 12:50:16 -05:00
cal
9ca9ea4f80 Merge pull request 'ci: switch to tag-based Docker builds' (#129) from ci/tag-based-docker-builds into main 2026-03-23 17:22:07 +00:00
Cal Corum
bdc61b4e2f ci: switch to tag-based Docker builds
Replace branch/PR-triggered Docker builds with tag-only triggers.
Images are now built only when a CalVer tag is pushed
(git tag YYYY.M.BUILD && git push origin YYYY.M.BUILD).

- Remove calver, docker-tags, and gitea-tag reusable actions
- Add inline version extraction from tag ref
- Add build cache (was missing)
- Update CLAUDE.md: remove stale next-release release workflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:49:23 -05:00
cal
1b2f8a7302 Merge pull request 'fix: remove SQLite references from CLAUDE.md (#123)' (#127) from ai/paper-dynasty-database#123 into main
All checks were successful
Build Docker Image / build (push) Successful in 8m50s
2026-03-23 13:32:14 +00:00
Cal Corum
30a6e003e8 fix: remove SQLite references from CLAUDE.md (#123)
All checks were successful
Build Docker Image / build (pull_request) Successful in 8m15s
Closes #123

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 00:01:53 -05:00
cal
b68e280c64 Merge pull request 'refactor: full recalculation for season stats + fix evaluator bugs' (#111) from feature/season-stats-full-recalc into card-evolution
All checks were successful
Build Docker Image / build (pull_request) Successful in 8m11s
Reviewed-on: #111
2026-03-19 15:35:42 +00:00
Cal Corum
d10276525e docs: update stale docstrings to reflect full-recalculation approach
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 10:34:55 -05:00
Cal Corum
46c85e6874 fix: stale docstring + add decision-only pitcher test
- evaluate_card() docstring: "Override for PlayerSeasonStats" →
  "Override for BattingSeasonStats/PitchingSeasonStats"
- New test_decision_only_pitcher: exercises the edge case where a pitcher
  has a Decision row but no StratPlay rows, verifying _get_player_pairs()
  correctly includes them via the Decision table scan

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 10:31:16 -05:00
Cal Corum
4211bd69e0 fix: address PR review — correct Peewee DISTINCT syntax and Decision-only pitchers
- fn.COUNT(fn.DISTINCT(expr)) → fn.COUNT(expr.distinct()) for correct
  COUNT(DISTINCT ...) SQL on PostgreSQL
- _get_player_pairs() now also scans Decision table to include pitchers
  who have a Decision row but no StratPlay rows (rare edge case)
- Updated stale docstring references to PlayerSeasonStats and r.k

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 10:23:47 -05:00
Cal Corum
1b4eab9d99 refactor: replace incremental delta upserts with full recalculation in season stats
The previous approach accumulated per-game deltas into season stats rows,
which was fragile — partial processing corrupted stats, upsert bugs
compounded, and there was no self-healing mechanism.

Now update_season_stats() recomputes full season totals from all StratPlay
rows for each affected player whenever a game is processed. The result
replaces whatever was stored, eliminating double-counting and enabling
self-healing via force=True.

Also fixes:
- evolution_evaluator.py: broken PlayerSeasonStats import → queries
  BattingSeasonStats or PitchingSeasonStats based on card_type
- evolution_evaluator.py: r.k → r.strikeouts
- test_evolution_models.py, test_postgame_evolution.py: PlayerSeasonStats
  → BattingSeasonStats (model never existed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 10:17:13 -05:00
cal
6b6359c6bb Merge pull request 'feat(WP-13): post-game callback endpoints for season stats and evolution' (#109) from feature/wp-13-postgame-callbacks into card-evolution
Merge PR #109: WP-13 post-game callback API endpoints
2026-03-18 21:05:37 +00:00
Cal Corum
a2d2aa3d31 feat(WP-13): post-game callback endpoints for season stats and evolution
Implements two new API endpoints the bot calls after a game completes:

  POST /api/v2/season-stats/update-game/{game_id}
    Delegates to update_season_stats() service (WP-05). Returns
    {"updated": N, "skipped": bool} with idempotency via ProcessedGame ledger.

  POST /api/v2/evolution/evaluate-game/{game_id}
    Finds all (player_id, team_id) pairs from the game's StratPlay rows,
    calls evaluate_card() for each pair that has an EvolutionCardState,
    and returns {"evaluated": N, "tier_ups": [...]} with full tier-up detail.

New files:
  app/services/evolution_evaluator.py — evaluate_card() service (WP-08)
  tests/test_postgame_evolution.py    — 10 integration tests (all pass)

Modified files:
  app/routers_v2/season_stats.py — rewritten to delegate to the service
  app/routers_v2/evolution.py    — evaluate-game endpoint added
  app/main.py                    — season_stats router registered

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 16:05:21 -05:00
cal
e66a1ea9c4 Merge pull request 'feat(WP-07): Card State API endpoints (#72)' (#108) from feature/wp-07-card-state-api into card-evolution
Merge PR #108: WP-07 card state API endpoints
2026-03-18 20:33:18 +00:00
Cal Corum
503e570da5 fix: add missing pg_conn fixture to conftest.py
Session-scoped psycopg2 fixture that skips gracefully when
POSTGRES_HOST is absent (local dev) and connects in CI. Required
by seeded_data/seeded_tracks fixtures in evolution API tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:33:02 -05:00
Cal Corum
583bde73a9 feat(WP-07): card state API endpoints — closes #72
Add two endpoints for reading EvolutionCardState:

  GET /api/v2/teams/{team_id}/evolutions
    - Optional filters: card_type, tier
    - Pagination: page / per_page (default 10, max 100)
    - Joins EvolutionTrack so card_type filter is a single query
    - Returns {count, items} with full card state + threshold context

  GET /api/v2/evolution/cards/{card_id}
    - Resolves card_id -> (player_id, team_id) via Card table
    - Duplicate cards for same player+team share one state row
    - Returns 404 when card missing or has no evolution state

Both endpoints:
  - Require bearer token auth (valid_token dependency)
  - Embed the EvolutionTrack in each item (not just the FK id)
  - Compute next_threshold: threshold for tier above current (null at T4)
  - Share _build_card_state_response() helper in evolution.py

Also cleans up 30 pre-existing ruff violations in teams.py that were
blocking the pre-commit hook: F541 bare f-strings, E712 boolean
comparisons (now noqa where Peewee ORM requires == False/True),
and F841 unused variable assignments.

Tests: tests/test_evolution_state_api.py — 10 integration tests that
skip automatically without POSTGRES_HOST, following the same pattern as
test_evolution_track_api.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 15:33:02 -05:00
cal
f5b24cf8f2 Merge pull request 'feat(WP-10): pack opening hook — evolution_card_state initialization' (#107) from feature/wp10-pack-opening-hook into card-evolution
Merge PR #107: WP-10 pack opening hook — evolution_card_state initialization
2026-03-18 20:31:59 +00:00
cal
55f98b8246 Merge pull request 'feat: WP-08 evaluate endpoint and evolution evaluator service (#73)' (#98) from ai/paper-dynasty-database#73 into card-evolution
Merge PR #98: WP-08 evaluate endpoint and evolution evaluator service
2026-03-18 20:31:53 +00:00
Cal Corum
64b6225c41 fix: align naming between evaluator, formula engine, and DB models
- Rename _CareerTotals.k → .strikeouts to match formula engine's
  stats.strikeouts Protocol
- Update test stubs: TrackStub fields t1→t1_threshold etc. to match
  EvolutionTrack model
- Fix fully_evolved logic: derive from post-max current_tier, not
  new_tier (prevents contradictory state on tier regression)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:31:44 -05:00
Cal Corum
fe3dc0e4d2 feat: WP-08 evaluate endpoint and evolution evaluator service (#73)
Closes #73

Adds POST /api/v2/evolution/cards/{card_id}/evaluate — force-recalculates
a card's evolution state from career totals (SUM across all
player_season_stats rows for the player-team pair).

Changes:
- app/services/evolution_evaluator.py: evaluate_card() function that
  aggregates career stats, delegates to formula engine for value/tier
  computation, updates evolution_card_state with no-regression guarantee
- app/routers_v2/evolution.py: POST /cards/{card_id}/evaluate endpoint
  plus existing GET /tracks and GET /tracks/{id} endpoints (WP-06)
- tests/test_evolution_evaluator.py: 15 unit tests covering tier
  assignment, advancement, partial progress, idempotency, fully evolved,
  no regression, multi-season aggregation, missing state error, and
  return shape
- tests/__init__.py, tests/conftest.py: shared test infrastructure

All 15 tests pass. Models and formula engine are lazily imported so
this module is safely importable before WP-01/WP-05/WP-07/WP-09 merge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 15:31:44 -05:00
cal
c69082e3ee Merge pull request 'feat: add ProcessedGame ledger for full idempotency in update_season_stats() (#105)' (#106) from ai/paper-dynasty-database#105 into card-evolution
Merge PR #106: ProcessedGame ledger for full idempotency in update_season_stats()
2026-03-18 20:30:35 +00:00
Cal Corum
d1d9159edf fix: restore Dockerfile to match card-evolution base after retarget
PR retargeted from next-release to card-evolution. Restore the
Dockerfile with correct COPY path and CMD from card-evolution base.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 15:30:01 -05:00