Commit d05731c
committed
refactor: migrate stats module to Pydantic
Models converted (8 files, 80+ classes):
stats.py (base classes):
- Stat, Split, PitchArsenalSplit, ExpectedStatistics, Sabermetrics
- ZoneCodes, Zones, HotColdZones, Chart, SprayCharts
- PitchArsenal, OutsAboveAverage, PlayerGameLogStat
hitting.py:
- SimpleHittingSplit, AdvancedHittingSplit, HittingPlay
- HittingWinLoss, HittingHomeAndAway, HittingCareer, HittingSeason
- HittingGameLog, HittingPlayLog, HittingPitchLog, HittingByMonth
- HittingVsTeam, HittingVsPlayer, HittingExpectedStatistics, etc.
pitching.py:
- SimplePitchingSplit, AdvancedPitchingSplit, PitchingPlay
- PitchingSeason, PitchingCareer, PitchingGameLog, PitchingLog
- PitchingByMonth, PitchingHomeAndAway, PitchingWinLoss
- PitchingVsTeam, PitchingVsPlayer, PitchingRankings, etc.
fielding.py:
- SimpleFieldingSplit, FieldingSeason, FieldingCareer
- FieldingHomeAndAway, FieldingGameLog, FieldingByMonth, etc.
catching.py:
- SimpleCatchingSplit, CatchingSeason, CatchingCareer
- CatchingGameLog, CatchingHomeAndAway, CatchingWinLoss, etc.
running.py:
- RunningOpponentsFaced
game.py:
- SimpleGameStats, SeasonGame, CareerGame
- CareerRegularSeasonGame, CareerPlayoffsGame
Key changes:
- All fields use snake_case with aliases for API compatibility
- Fixed type mismatches: stolenbasepercentage, groundoutstoairouts,
atbatsperhomerun, whiffpercentage are strings not ints
- Game model fields made optional for stats endpoint compatibility
- Field validators handle empty dicts from API as None
- Updated all stats tests to use new Pythonic field names
(totalsplits -> total_splits)1 parent f12ee76 commit d05731c
16 files changed
Lines changed: 1946 additions & 1978 deletions
File tree
- mlbstatsapi/models
- game
- stats
- tests
- external_tests/stats
- mock_tests/stats
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments