WP-02: PlayerSeasonStats Peewee Model #67

Closed
opened 2026-03-12 20:55:11 +00:00 by cal · 1 comment
Owner

Description

Define the player_season_stats Peewee model with all batting and pitching aggregate columns. This table is the materialized aggregate updated incrementally after each game. Career totals are derived by summing across seasons at query time.

Repo: database
Phase: 1a (Schema & Data Foundation)
Dependencies: None
Complexity: S

Key Columns

Batting: games_batting, pa, ab, hits, hr, doubles, triples, bb, hbp, so, rbi, runs, sb, cs
Pitching: games_pitching, outs (raw — IP = outs/3 computed in formula engine), so (K), bb_allowed, hits_allowed, hr_allowed, wins, losses, saves, holds, blown_saves
Meta: last_game_id (FK), last_updated_at

Note: team_wins and quality_starts are NOT included (removed from scope).

Files

  • Create: database/app/models/season_stats.py
  • Modify: database/app/db_engine.py — register model

Tests (write first in database/tests/test_season_stats_model.py)

  • Unit: column completeness
  • Unit: default values (all ints default to 0)
  • Integration: unique constraint on (player_id, team_id, season)
  • Integration: delta update pattern
  • Integration: index existence on (team_id, season) and (player_id, season)

Acceptance Criteria

  1. Model matches PRD schema exactly
  2. UNIQUE on (player_id, team_id, season) enforced
  3. All stat columns default to 0
  4. last_game_id is nullable FK to StratGame

Plan reference: docs/prd-evolution/PHASE1_PROJECT_PLAN.md WP-02

## Description Define the `player_season_stats` Peewee model with all batting and pitching aggregate columns. This table is the materialized aggregate updated incrementally after each game. Career totals are derived by summing across seasons at query time. **Repo:** `database` **Phase:** 1a (Schema & Data Foundation) **Dependencies:** None **Complexity:** S ## Key Columns Batting: `games_batting`, `pa`, `ab`, `hits`, `hr`, `doubles`, `triples`, `bb`, `hbp`, `so`, `rbi`, `runs`, `sb`, `cs` Pitching: `games_pitching`, `outs` (raw — IP = outs/3 computed in formula engine), `so` (K), `bb_allowed`, `hits_allowed`, `hr_allowed`, `wins`, `losses`, `saves`, `holds`, `blown_saves` Meta: `last_game_id` (FK), `last_updated_at` Note: `team_wins` and `quality_starts` are NOT included (removed from scope). ## Files - **Create:** `database/app/models/season_stats.py` - **Modify:** `database/app/db_engine.py` — register model ## Tests (write first in `database/tests/test_season_stats_model.py`) - [ ] Unit: column completeness - [ ] Unit: default values (all ints default to 0) - [ ] Integration: unique constraint on (player_id, team_id, season) - [ ] Integration: delta update pattern - [ ] Integration: index existence on (team_id, season) and (player_id, season) ## Acceptance Criteria 1. Model matches PRD schema exactly 2. UNIQUE on `(player_id, team_id, season)` enforced 3. All stat columns default to 0 4. `last_game_id` is nullable FK to `StratGame` **Plan reference:** `docs/prd-evolution/PHASE1_PROJECT_PLAN.md` WP-02
cal added this to the Card Evolution Phase 1 milestone 2026-03-12 20:59:08 +00:00
cal added the
evolution
phase-1a
labels 2026-03-12 20:59:22 +00:00
Claude added the
ai-working
label 2026-03-12 21:31:35 +00:00
Claude added the
ai-pr-opened
label 2026-03-12 21:35:27 +00:00
Collaborator

PR opened: #82

Added PlayerSeasonStats to db_engine.py with all batting/pitching/meta columns, UNIQUE constraint on (player_id, team_id, season), and two supporting indexes. Re-export module added at app/models/season_stats.py. 17 tests written and passing.

Note: The spec's pitching so (K) column is named k in the model to avoid collision with the batting so column — WP-09 should access stats.k for pitcher strikeout counts.

PR opened: https://git.manticorum.com/cal/paper-dynasty-database/pulls/82 Added `PlayerSeasonStats` to `db_engine.py` with all batting/pitching/meta columns, UNIQUE constraint on `(player_id, team_id, season)`, and two supporting indexes. Re-export module added at `app/models/season_stats.py`. 17 tests written and passing. **Note**: The spec's pitching `so (K)` column is named `k` in the model to avoid collision with the batting `so` column — WP-09 should access `stats.k` for pitcher strikeout counts.
Claude removed the
ai-working
label 2026-03-12 21:35:37 +00:00
cal closed this issue 2026-03-16 16:13:09 +00:00
Sign in to join this conversation.
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-database#67
No description provided.