Commit Graph

232 Commits

Author SHA1 Message Date
cal
2a1d017aa6 Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:08:28 +00:00
cal
ae834692aa Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:08:13 +00:00
cal
623e93c38a Merge branch 'main' into issue/138-feat-add-limit-pagination-to-stratgame-games-endpo 2026-03-24 12:08:04 +00:00
cal
3bbf364a74 Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:07:58 +00:00
cal
556d18f64c Merge branch 'main' into issue/137-feat-add-limit-pagination-to-results-endpoint 2026-03-24 12:07:37 +00:00
cal
11e8fba6c5 Merge pull request 'feat: add limit/pagination to scout_opportunities endpoint (#148)' (#154) from issue/148-feat-add-limit-pagination-to-scout-opportunities-e into main 2026-03-24 12:07:32 +00:00
cal
d470a132e2 Merge branch 'main' into issue/138-feat-add-limit-pagination-to-stratgame-games-endpo 2026-03-24 12:07:22 +00:00
cal
cc98a3b368 Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:07:18 +00:00
cal
a23757bb8e Merge branch 'main' into issue/132-feat-add-limit-pagination-to-awards-endpoint 2026-03-24 12:07:10 +00:00
cal
aeb37c20f2 Merge branch 'main' into issue/148-feat-add-limit-pagination-to-scout-opportunities-e 2026-03-24 12:06:57 +00:00
cal
01c7b19137 Merge branch 'main' into issue/137-feat-add-limit-pagination-to-results-endpoint 2026-03-24 12:06:51 +00:00
cal
67bcaa1b9b Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:06:48 +00:00
cal
77179d3c9c fix: clamp limit lower bound to 1 to prevent silent empty responses
Addresses reviewer feedback: max(0,...) admitted limit=0 which would
silently return no results even when matching records exist.
Changed to max(1,...) consistent with feedback on PRs #149 and #152.
2026-03-24 12:06:37 +00:00
cal
fe4d22f28a Merge branch 'main' into issue/132-feat-add-limit-pagination-to-awards-endpoint 2026-03-24 12:06:35 +00:00
cal
3a65d84682 Merge branch 'main' into issue/141-feat-add-limit-pagination-to-mlbplayers-endpoint 2026-03-24 12:06:30 +00:00
cal
9a8558db3a Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:06:08 +00:00
cal
8f29c34985 Merge branch 'main' into issue/137-feat-add-limit-pagination-to-results-endpoint 2026-03-24 12:05:53 +00:00
cal
38a06ca4e9 Merge branch 'main' into issue/132-feat-add-limit-pagination-to-awards-endpoint 2026-03-24 12:05:50 +00:00
cal
042392ca18 Merge branch 'main' into issue/144-feat-add-limit-pagination-to-gamerewards-endpoint 2026-03-24 12:05:48 +00:00
cal
e696a9af1a Merge branch 'main' into issue/138-feat-add-limit-pagination-to-stratgame-games-endpo 2026-03-24 12:05:43 +00:00
cal
fd5d44c3ce Merge branch 'main' into issue/144-feat-add-limit-pagination-to-gamerewards-endpoint 2026-03-24 12:05:03 +00:00
cal
7c69a56b30 Merge branch 'main' into issue/141-feat-add-limit-pagination-to-mlbplayers-endpoint 2026-03-24 12:05:01 +00:00
cal
425b602c1c Merge branch 'main' into issue/137-feat-add-limit-pagination-to-results-endpoint 2026-03-24 12:04:55 +00:00
cal
6b5fe3a440 Merge branch 'main' into issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:04:53 +00:00
cal
2486d85112 Merge branch 'main' into issue/138-feat-add-limit-pagination-to-stratgame-games-endpo 2026-03-24 12:04:53 +00:00
cal
cf668703ed Merge branch 'main' into issue/135-feat-add-limit-pagination-to-battingcardratings-en 2026-03-24 12:04:49 +00:00
cal
f784963f79 Merge branch 'main' into issue/132-feat-add-limit-pagination-to-awards-endpoint 2026-03-24 12:04:44 +00:00
cal
630b334528 Merge pull request 'feat: add limit/pagination to batstats endpoint (#133)' (#155) from issue/133-feat-add-limit-pagination-to-batstats-endpoint into main 2026-03-24 12:04:40 +00:00
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
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
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
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
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 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
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 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 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 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 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