paper-dynasty-database/app/routers_v2
Cal Corum 264c7dc73c feat(WP-10): pack opening hook — evolution_card_state initialization
Closes #75.

New file app/services/evolution_init.py:
- _determine_card_type(player): pure fn mapping pos_1 to 'batter'/'sp'/'rp'
- initialize_card_evolution(player_id, team_id, card_type): get_or_create
  EvolutionCardState with current_tier=0, current_value=0.0, fully_evolved=False
- Safe failure: all exceptions caught and logged, never raises
- Idempotent: duplicate calls for same (player_id, team_id) are no-ops
  and do NOT reset existing evolution progress

Modified app/routers_v2/cards.py:
- Add WP-10 hook after Card.bulk_create in the POST endpoint
- For each card posted, call _determine_card_type + initialize_card_evolution
- Wrapped in try/except so evolution failures cannot block pack opening
- Fix pre-existing lint violations (unused lc_id, bare f-string, unused e)

New file tests/test_evolution_init.py (16 tests, all passing):
- Unit: track assignment for batter / SP / RP / CP positions
- Integration: first card creates state with zeroed fields
- Integration: duplicate card is a no-op (progress not reset)
- Integration: different players on same team get separate states
- Integration: card_type routes to correct EvolutionTrack
- Integration: missing track returns None gracefully

Fix tests/test_evolution_models.py: correct PlayerSeasonStats import/usage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 13:41:05 -05:00
..
__init__.py Initial Commit with /current 2023-09-13 14:44:26 -05:00
admin.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
awards.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
batstats.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
battingcardratings.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
battingcards.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
cardpositions.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
cards.py feat(WP-10): pack opening hook — evolution_card_state initialization 2026-03-18 13:41:05 -05:00
cardsets.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
current.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
decisions.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
events.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
evolution.py feat: Track Catalog API endpoints (WP-06) (#71) 2026-03-12 20:40:38 -05:00
gamerewards.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
gauntletrewards.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
gauntletruns.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
mlbplayers.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
notifications.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
packs.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
packtypes.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
paperdex.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
pitchingcardratings.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
pitchingcards.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
pitstats.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
players.py feat: persistent browser instance for card rendering (#89) 2026-03-16 11:20:42 -05:00
rarity.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
results.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
rewards.py fix: replace broad except Exception blocks with DoesNotExist (#15) 2026-03-05 15:32:53 -06:00
scout_claims.py feat: add scout_opportunities and scout_claims tables and API endpoints (#44) 2026-03-05 03:45:38 +00:00
scout_opportunities.py feat: add scout_opportunities and scout_claims tables and API endpoints (#44) 2026-03-05 03:45:38 +00:00
scouting.py fix: remove stub live_update_pitching endpoint (#11) 2026-03-07 01:37:52 -06:00
season_stats.py refactor: split PlayerSeasonStats into BattingSeasonStats and PitchingSeasonStats 2026-03-17 09:43:22 -05:00
stratgame.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
stratplays.py fix: remove plaintext bearer token from warning logs (#7) 2026-03-05 03:43:27 +00:00
teams.py Merge pull request 'fix: use max() for pitcher OPS split weighting (#6)' (#60) from ai/paper-dynasty-database#6 into next-release 2026-03-10 14:42:59 +00:00