WP-13: Post-Game Callback Integration #78

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

Description

After a game completes, trigger: (1) update player_season_stats with game deltas, (2) evaluate evolution state for all participating cards. Hooks into complete_game() in the bot at ~line 4348.

Repo: discord-app (hook) + database (API endpoints)
Phase: 1c (Bot Integration)
Dependencies: WP-05, WP-08
Complexity: L

New API Endpoints

POST /v2/season-stats/update-game/{game_id}
  Response: {"updated": N}

POST /v2/evolution/evaluate-game/{game_id}
  Response: {"evaluated": N, "tier_ups": [...]}

Bot Hook (in complete_game)

try:
    await db_post(f"season-stats/update-game/{db_game['id']}")
    evo_result = await db_post(f"evolution/evaluate-game/{db_game['id']}")
    if evo_result and evo_result.get("tier_ups"):
        for tier_up in evo_result["tier_ups"]:
            await notify_tier_completion(interaction.channel, tier_up)
except Exception as e:
    logger.warning(f"Post-game evolution failed: {e}")

Evolution failure must NOT prevent game completion.

Tests

  • Integration: season stats updated after game (database)
  • Integration: evolution evaluated after game (database)
  • Integration: tier advancement on game completion (database)
  • Integration: no advancement when stats insufficient (database)
  • Unit: bot hook calls both endpoints (discord-app)
  • Unit: bot hook failure is non-fatal (discord-app)

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

## Description After a game completes, trigger: (1) update `player_season_stats` with game deltas, (2) evaluate evolution state for all participating cards. Hooks into `complete_game()` in the bot at ~line 4348. **Repo:** `discord-app` (hook) + `database` (API endpoints) **Phase:** 1c (Bot Integration) **Dependencies:** WP-05, WP-08 **Complexity:** L ## New API Endpoints ``` POST /v2/season-stats/update-game/{game_id} Response: {"updated": N} POST /v2/evolution/evaluate-game/{game_id} Response: {"evaluated": N, "tier_ups": [...]} ``` ## Bot Hook (in complete_game) ```python try: await db_post(f"season-stats/update-game/{db_game['id']}") evo_result = await db_post(f"evolution/evaluate-game/{db_game['id']}") if evo_result and evo_result.get("tier_ups"): for tier_up in evo_result["tier_ups"]: await notify_tier_completion(interaction.channel, tier_up) except Exception as e: logger.warning(f"Post-game evolution failed: {e}") ``` Evolution failure must NOT prevent game completion. ## Tests - [ ] Integration: season stats updated after game (database) - [ ] Integration: evolution evaluated after game (database) - [ ] Integration: tier advancement on game completion (database) - [ ] Integration: no advancement when stats insufficient (database) - [ ] Unit: bot hook calls both endpoints (discord-app) - [ ] Unit: bot hook failure is non-fatal (discord-app) **Plan reference:** `docs/prd-evolution/PHASE1_PROJECT_PLAN.md` WP-13
cal added this to the Card Evolution Phase 1 milestone 2026-03-12 20:59:15 +00:00
cal added the
evolution
phase-1c
labels 2026-03-12 20:59:27 +00:00
Claude added the
ai-working
label 2026-03-13 12:31:39 +00:00
Author
Owner

Schema change notice: PlayerSeasonStats has been split into BattingSeasonStats and PitchingSeasonStats.

Relevant commits on next-release:

  • bd8e457 — refactor: split PlayerSeasonStats into BattingSeasonStats and PitchingSeasonStats
  • 6580c1b — refactor: deduplicate pitcher formula and test constants

Impact on this WP:

  • The draft router at app/routers_v2/season_stats.py has already been updated — batting upserts go to batting_season_stats, pitching upserts go to pitching_season_stats
  • All SQL column names now match the ORM model fields (the previous version had mismatches like w/wins, hr_p/hr_allowed, etc.)
  • The router is not yet wired into main.py — that's still part of this WP's scope
**Schema change notice:** `PlayerSeasonStats` has been split into `BattingSeasonStats` and `PitchingSeasonStats`. Relevant commits on `next-release`: - `bd8e457` — refactor: split PlayerSeasonStats into BattingSeasonStats and PitchingSeasonStats - `6580c1b` — refactor: deduplicate pitcher formula and test constants Impact on this WP: - The draft router at `app/routers_v2/season_stats.py` has already been updated — batting upserts go to `batting_season_stats`, pitching upserts go to `pitching_season_stats` - All SQL column names now match the ORM model fields (the previous version had mismatches like `w`/`wins`, `hr_p`/`hr_allowed`, etc.) - The router is not yet wired into `main.py` — that's still part of this WP's scope
cal closed this issue 2026-03-18 21:05:38 +00:00
Sign in to join this conversation.
No project
No Assignees
1 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#78
No description provided.