-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathpitching.py
More file actions
1028 lines (915 loc) · 31.7 KB
/
pitching.py
File metadata and controls
1028 lines (915 loc) · 31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from typing import Optional, List, Any, ClassVar
from pydantic import Field, field_validator
from mlbstatsapi.models.base import MLBBaseModel
from mlbstatsapi.models.people import Person, Pitcher, Batter
from mlbstatsapi.models.teams import Team
from mlbstatsapi.models.game import Game
from mlbstatsapi.models.data import Count, PlayDetails
from .stats import Sabermetrics, ExpectedStatistics, Split
from .hitting import SimpleHittingSplit
class SimplePitchingSplit(MLBBaseModel):
"""
A class to represent simple pitching statistics.
Attributes
----------
summary : str
Summary of stats for the pitcher.
games_played : int
The games played by the pitcher.
games_started : int
The games started by the pitcher.
flyouts : int
The number of flyouts for the pitcher.
groundouts : int
The number of groundouts for the pitcher.
airouts : int
The number of airouts for the pitcher.
runs : int
The number of runs given up by the pitcher.
doubles : int
The number of doubles given up by the pitcher.
triples : int
The number of triples given up by the pitcher.
home_runs : int
The number of home runs given up by the pitcher.
strikeouts : int
The number of strike outs performed by the pitcher.
base_on_balls : int
The number of base on balls (walks) performed by the pitcher.
intentional_walks : int
The number of intentional walks performed by the pitcher.
hits : int
The number of hits given up by the pitcher.
hit_by_pitch : int
The number of batters hit by the pitcher.
avg : str
The batting avg against the pitcher.
at_bats : int
The at bats pitched by the pitcher.
obp : str
The on base percentage against the pitcher.
slg : str
The slugging percentage against the pitcher.
ops : str
The on base slugging against the pitcher.
caught_stealing : int
The number of runners caught stealing against the pitcher.
stolen_bases : int
The number of stolen bases while pitching.
stolen_base_percentage : str
The stolen base percentage while pitching.
ground_into_double_play : int
The number of double plays hit into.
number_of_pitches : int
The number of pitches thrown.
era : str
The earned run average of the pitcher.
innings_pitched : str
The number of innings pitched by the pitcher.
wins : int
The number of wins by the pitcher.
losses : int
The number of losses by the pitcher.
saves : int
The number of saves by the pitcher.
save_opportunities : int
The number of save opportunities by the pitcher.
holds : int
The number of holds by the pitcher.
blown_saves : int
The number of blown saves performed by the pitcher.
earned_runs : int
The number of earned runs given up by the pitcher.
whip : str
The number of walks and hits per inning pitched.
outs : int
The number of outs.
games_pitched : int
The number of games pitched.
complete_games : int
The number of complete games pitched.
shutouts : int
The number of shut outs pitched.
strikes : int
The number of strikes thrown by the pitcher.
hit_batsmen : int
The number of batters hit by a pitch.
strike_percentage : str
The strike percentage thrown by the pitcher.
wild_pitches : int
The number of wild pitches thrown by the pitcher.
balks : int
The number of balks committed by the pitcher.
total_bases : int
The total bases given up by the pitcher.
pickoffs : int
The number of pick offs performed by the pitcher.
win_percentage : str
The win percentage of the pitcher.
groundouts_to_airouts : str
The groundout-to-airout ratio of the pitcher.
games_finished : int
The number of games finished by the pitcher.
pitches_per_inning : str
The number of pitches thrown per inning by the pitcher.
strikeouts_per_9_inn : str
The number of strike outs per 9 innings by the pitcher.
strikeout_walk_ratio : str
The strike out to walk ratio of the pitcher.
hits_per_9_inn : str
The number of hits per 9 innings pitched.
walks_per_9_inn : str
The number of walks per 9 innings pitched.
home_runs_per_9 : str
The number of home runs per 9 innings pitched.
runs_scored_per_9 : str
The number of runs scored per 9 innings pitched.
sac_bunts : int
The number of sac bunts given up when pitched.
catchers_interference : int
The number of times a runner has reached from catchers interference.
batters_faced : int
The number of batters faced by the pitcher.
sac_flies : int
The number of sac flies given up by the pitcher.
inherited_runners_scored : int
The number of inherited runners scored by the pitcher.
inherited_runners : int
The number of inherited runners for the pitcher.
age : int
The age of the pitcher.
caught_stealing_percentage : str
The caught stealing percentage for the pitcher.
"""
summary: Optional[str] = None
age: Optional[int] = None
games_played: Optional[int] = Field(default=None, alias="gamesPlayed")
games_started: Optional[int] = Field(default=None, alias="gamesStarted")
flyouts: Optional[int] = None
groundouts: Optional[int] = None
airouts: Optional[int] = None
runs: Optional[int] = None
doubles: Optional[int] = None
triples: Optional[int] = None
home_runs: Optional[int] = Field(default=None, alias="homeRuns")
strikeouts: Optional[int] = Field(default=None, alias="strikeOuts")
base_on_balls: Optional[int] = Field(default=None, alias="baseOnBalls")
intentional_walks: Optional[int] = Field(default=None, alias="intentionalWalks")
hits: Optional[int] = None
hit_by_pitch: Optional[int] = Field(default=None, alias="hitByPitch")
avg: Optional[str] = None
at_bats: Optional[int] = Field(default=None, alias="atBats")
obp: Optional[str] = None
slg: Optional[str] = None
ops: Optional[str] = None
caught_stealing: Optional[int] = Field(default=None, alias="caughtStealing")
caught_stealing_percentage: Optional[str] = Field(default=None, alias="caughtStealingPercentage")
stolen_bases: Optional[int] = Field(default=None, alias="stolenBases")
stolen_base_percentage: Optional[str] = Field(default=None, alias="stolenBasePercentage")
ground_into_double_play: Optional[int] = Field(default=None, alias="groundIntoDoublePlay")
number_of_pitches: Optional[int] = Field(default=None, alias="numberOfPitches")
era: Optional[str] = None
innings_pitched: Optional[str] = Field(default=None, alias="inningsPitched")
wins: Optional[int] = None
losses: Optional[int] = None
saves: Optional[int] = None
save_opportunities: Optional[int] = Field(default=None, alias="saveOpportunities")
holds: Optional[int] = None
blown_saves: Optional[int] = Field(default=None, alias="blownSaves")
earned_runs: Optional[int] = Field(default=None, alias="earnedRuns")
whip: Optional[str] = None
outs: Optional[int] = None
games_pitched: Optional[int] = Field(default=None, alias="gamesPitched")
complete_games: Optional[int] = Field(default=None, alias="completeGames")
shutouts: Optional[int] = None
strikes: Optional[int] = None
strike_percentage: Optional[str] = Field(default=None, alias="strikePercentage")
hit_batsmen: Optional[int] = Field(default=None, alias="hitBatsmen")
balks: Optional[int] = None
wild_pitches: Optional[int] = Field(default=None, alias="wildPitches")
pickoffs: Optional[int] = None
total_bases: Optional[int] = Field(default=None, alias="totalBases")
groundouts_to_airouts: Optional[str] = Field(default=None, alias="groundoutsToAirouts")
win_percentage: Optional[str] = Field(default=None, alias="winPercentage")
pitches_per_inning: Optional[str] = Field(default=None, alias="pitchesPerInning")
games_finished: Optional[int] = Field(default=None, alias="gamesFinished")
strikeout_walk_ratio: Optional[str] = Field(default=None, alias="strikeoutWalkRatio")
strikeouts_per_9_inn: Optional[str] = Field(default=None, alias="strikeoutsPer9Inn")
walks_per_9_inn: Optional[str] = Field(default=None, alias="walksPer9Inn")
hits_per_9_inn: Optional[str] = Field(default=None, alias="hitsPer9Inn")
runs_scored_per_9: Optional[str] = Field(default=None, alias="runsScoredPer9")
home_runs_per_9: Optional[str] = Field(default=None, alias="homeRunsPer9")
catchers_interference: Optional[int] = Field(default=None, alias="catchersInterference")
sac_bunts: Optional[int] = Field(default=None, alias="sacBunts")
sac_flies: Optional[int] = Field(default=None, alias="sacFlies")
batters_faced: Optional[int] = Field(default=None, alias="battersFaced")
inherited_runners: Optional[int] = Field(default=None, alias="inheritedRunners")
inherited_runners_scored: Optional[int] = Field(default=None, alias="inheritedRunnersScored")
balls: Optional[int] = None
outs_pitched: Optional[int] = Field(default=None, alias="outsPitched")
rbi: Optional[int] = None
class AdvancedPitchingSplit(MLBBaseModel):
"""
A class to represent advanced pitching statistics.
Attributes
----------
age : int
The age of the pitcher.
winning_percentage : str
The winning percentage of the pitcher.
runs_scored_per_9 : str
The number of runs scored per 9 innings.
batters_faced : int
The number of batters faced.
babip : str
The BABIP of the pitcher.
obp : str
The on base percentage against the pitcher.
slg : str
The slugging percentage against the pitcher.
ops : str
The on base slugging against the pitcher.
strikeouts_per_9 : str
The number of strike outs per 9 innings.
base_on_balls_per_9 : str
The number of base on balls per 9 innings.
home_runs_per_9 : str
The number of home runs per 9 innings.
hits_per_9 : str
The number of hits per 9 innings.
strikeouts_to_walks : str
The strike out to walk ratio.
stolen_bases : int
The number of stolen bases while pitching.
caught_stealing : int
The number of runners caught stealing.
quality_starts : int
The number of quality starts.
games_finished : int
The number of games finished.
doubles : int
The number of doubles given up.
triples : int
The number of triples given up.
gidp : int
The amount of hits that lead to a double play.
gidp_opp : int
The amount of GIDP opportunities.
wild_pitches : int
The number of wild pitches thrown.
balks : int
The number of balks committed.
pickoffs : int
The number of pick offs attempted.
total_swings : int
The number of swings against the pitcher.
swing_and_misses : int
The number of swing and misses.
balls_in_play : int
The number of balls put into play.
run_support : int
The number of run support.
strike_percentage : str
The strike percentage thrown.
pitches_per_inning : str
The number of pitches per inning.
pitches_per_plate_appearance : str
The avg number of pitches per plate appearance.
walks_per_plate_appearance : str
The number of walks per plate appearance.
strikeouts_per_plate_appearance : str
The strike outs per plate appearance.
home_runs_per_plate_appearance : str
The home runs per plate appearance.
walks_per_strikeout : str
The walk per strike out ratio.
iso : str
Isolated power.
flyouts : int
The number of fly outs given up.
popouts : int
The number of pop outs given up.
lineouts : int
The number of line outs given up.
groundouts : int
The number of ground outs given up.
fly_hits : int
The number of fly hits given up.
pop_hits : int
The number of pop hits given up.
line_hits : int
The number of line hits given up.
ground_hits : int
The number of ground hits given up.
inherited_runners : int
The number of inherited runners.
inherited_runners_scored : int
The number of inherited runners scored.
bequeathed_runners : int
The number of bequeathed runners.
bequeathed_runners_scored : int
The number of bequeathed runners scored.
"""
age: Optional[int] = None
winning_percentage: Optional[str] = Field(default=None, alias="winningPercentage")
runs_scored_per_9: Optional[str] = Field(default=None, alias="runsScoredPer9")
batters_faced: Optional[int] = Field(default=None, alias="battersFaced")
babip: Optional[str] = None
obp: Optional[str] = None
slg: Optional[str] = None
ops: Optional[str] = None
strikeouts_per_9: Optional[str] = Field(default=None, alias="strikeoutsPer9")
base_on_balls_per_9: Optional[str] = Field(default=None, alias="baseOnBallsPer9")
home_runs_per_9: Optional[str] = Field(default=None, alias="homeRunsPer9")
hits_per_9: Optional[str] = Field(default=None, alias="hitsPer9")
strikeouts_to_walks: Optional[str] = Field(default=None, alias="strikeoutsToWalks")
stolen_bases: Optional[int] = Field(default=None, alias="stolenBases")
caught_stealing: Optional[int] = Field(default=None, alias="caughtStealing")
quality_starts: Optional[int] = Field(default=None, alias="qualityStarts")
games_finished: Optional[int] = Field(default=None, alias="gamesFinished")
doubles: Optional[int] = None
triples: Optional[int] = None
gidp: Optional[int] = None
gidp_opp: Optional[int] = Field(default=None, alias="gidpOpp")
wild_pitches: Optional[int] = Field(default=None, alias="wildPitches")
balks: Optional[int] = None
pickoffs: Optional[int] = None
total_swings: Optional[int] = Field(default=None, alias="totalSwings")
swing_and_misses: Optional[int] = Field(default=None, alias="swingAndMisses")
strikeouts_minus_walks_percentage: Optional[str] = Field(default=None, alias="strikeoutsMinusWalksPercentage")
gidp_percentage: Optional[str] = Field(default=None, alias="gidpPercentage")
batters_faced_per_game: Optional[str] = Field(default=None, alias="battersFacedPerGame")
bunts_failed: Optional[int] = Field(default=None, alias="buntsFailed")
bunts_missed_tipped: Optional[int] = Field(default=None, alias="buntsMissedTipped")
whiff_percentage: Optional[str] = Field(default=None, alias="whiffPercentage")
balls_in_play: Optional[int] = Field(default=None, alias="ballsInPlay")
run_support: Optional[int] = Field(default=None, alias="runSupport")
strike_percentage: Optional[str] = Field(default=None, alias="strikePercentage")
pitches_per_inning: Optional[str] = Field(default=None, alias="pitchesPerInning")
pitches_per_plate_appearance: Optional[str] = Field(default=None, alias="pitchesPerPlateAppearance")
walks_per_plate_appearance: Optional[str] = Field(default=None, alias="walksPerPlateAppearance")
strikeouts_per_plate_appearance: Optional[str] = Field(default=None, alias="strikeoutsPerPlateAppearance")
home_runs_per_plate_appearance: Optional[str] = Field(default=None, alias="homeRunsPerPlateAppearance")
walks_per_strikeout: Optional[str] = Field(default=None, alias="walksPerStrikeout")
iso: Optional[str] = None
flyouts: Optional[int] = None
popouts: Optional[int] = None
lineouts: Optional[int] = None
groundouts: Optional[int] = None
fly_hits: Optional[int] = Field(default=None, alias="flyHits")
pop_hits: Optional[int] = Field(default=None, alias="popHits")
line_hits: Optional[int] = Field(default=None, alias="lineHits")
ground_hits: Optional[int] = Field(default=None, alias="groundHits")
inherited_runners: Optional[int] = Field(default=None, alias="inheritedRunners")
inherited_runners_scored: Optional[int] = Field(default=None, alias="inheritedRunnersScored")
bequeathed_runners: Optional[int] = Field(default=None, alias="bequeathedRunners")
bequeathed_runners_scored: Optional[int] = Field(default=None, alias="bequeathedRunnersScored")
innings_pitched_per_game: Optional[str] = Field(default=None, alias="inningsPitchedPerGame")
flyball_percentage: Optional[str] = Field(default=None, alias="flyballPercentage")
class PitchingSabermetrics(Split):
"""
A class to represent pitching sabermetric statistics.
Attributes
----------
stat : Sabermetrics
The sabermetric statistics.
"""
_stat: ClassVar[List[str]] = ['sabermetrics']
stat: Sabermetrics
class PitchingSeason(Split):
"""
A class to represent a pitching season statistic.
Attributes
----------
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['season', 'statsSingleSeason']
stat: SimplePitchingSplit
class PitchingCareer(Split):
"""
A class to represent a pitching career statistic.
Attributes
----------
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['career']
stat: SimplePitchingSplit
class PitchingCareerAdvanced(Split):
"""
A class to represent a pitching careerAdvanced statistic.
Attributes
----------
stat : AdvancedPitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['careerAdvanced']
stat: AdvancedPitchingSplit
class PitchingYearByYear(Split):
"""
A class to represent a pitching yearByYear statistic.
Attributes
----------
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['yearByYear']
stat: SimplePitchingSplit
class PitchingYearByYearPlayoffs(Split):
"""
A class to represent a pitching yearByYearPlayoffs statistic.
Attributes
----------
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['yearByYearPlayoffs']
stat: SimplePitchingSplit
class PitchingYearByYearAdvanced(Split):
"""
A class to represent a pitching yearByYearAdvanced statistic.
Attributes
----------
stat : AdvancedPitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['yearByYearAdvanced']
stat: AdvancedPitchingSplit
class PitchingSeasonAdvanced(Split):
"""
A class to represent a pitching seasonAdvanced statistic.
Attributes
----------
stat : AdvancedPitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['seasonAdvanced']
stat: AdvancedPitchingSplit
class PitchingSingleSeasonAdvanced(Split):
"""
A class to represent a pitching statsSingleSeasonAdvanced statistic.
Attributes
----------
stat : AdvancedPitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['statsSingleSeasonAdvanced']
stat: AdvancedPitchingSplit
class PitchingGameLog(Split):
"""
A class to represent a gamelog stat for a pitcher.
Attributes
----------
is_home : bool
Bool to hold is home.
is_win : bool
Bool to hold is win.
game : Game
Game of the log.
date : str
Date of the log.
opponent : Team
Team of the opponent.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['gameLog']
is_home: bool = Field(alias="isHome")
is_win: bool = Field(alias="isWin")
game: Game
date: str
opponent: Team
stat: SimplePitchingSplit
class PitchingPlay(MLBBaseModel):
"""
A class to represent a play stat for a pitcher.
Attributes
----------
details : PlayDetails
Play details.
count : Count
The count.
pitch_number : int
Pitch number.
at_bat_number : int
At bat number.
is_pitch : bool
Is pitch bool.
play_id : str
Play ID.
"""
details: PlayDetails
count: Count
pitch_number: int = Field(alias="pitchNumber")
at_bat_number: int = Field(alias="atBatNumber")
is_pitch: bool = Field(alias="isPitch")
play_id: str = Field(alias="playId")
class PitchingLog(Split):
"""
A class to represent a pitchLog stat for a pitcher.
Attributes
----------
stat : PitchingPlay
Information regarding the play for the stat.
season : str
Season for the stat.
opponent : Team
Opponent.
date : str
Date of log.
is_home : bool
Is the game at home bool.
pitcher : Pitcher
Pitcher of the log.
batter : Batter
Batter of the log.
game : Game
The game of the log.
"""
_stat: ClassVar[List[str]] = ['pitchLog']
stat: PitchingPlay
season: str
opponent: Team
date: str
is_home: bool = Field(alias="isHome")
pitcher: Pitcher
batter: Batter
game: Game
@field_validator('stat', mode='before')
@classmethod
def extract_play(cls, v: Any) -> Any:
"""Extract play from stat dict."""
if isinstance(v, dict) and 'play' in v:
return v['play']
return v
class PitchingPlayLog(Split):
"""
A class to represent a playLog stat for a pitcher.
Attributes
----------
stat : PitchingPlay
Information regarding the play for the stat.
season : str
Season for the stat.
opponent : Team
Opponent.
date : str
Date of log.
is_home : bool
Is the game at home bool.
pitcher : Pitcher
Pitcher of the log.
batter : Batter
Batter of the log.
game : Game
The game of the log.
"""
_stat: ClassVar[List[str]] = ['playLog']
stat: PitchingPlay
season: str
opponent: Team
date: str
is_home: bool = Field(alias="isHome")
pitcher: Pitcher
batter: Batter
game: Game
@field_validator('stat', mode='before')
@classmethod
def extract_play(cls, v: Any) -> Any:
"""Extract play from stat dict."""
if isinstance(v, dict) and 'play' in v:
return v['play']
return v
class PitchingByDateRange(Split):
"""
A class to represent a byDateRange stat for a pitcher.
Attributes
----------
day_of_week : int
The day of the week.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byDateRange']
stat: SimplePitchingSplit
day_of_week: Optional[int] = Field(default=None, alias="dayOfWeek")
class PitchingByDateRangeAdvanced(Split):
"""
A class to represent a byDateRangeAdvanced stat for a pitcher.
Attributes
----------
day_of_week : int
The day of the week.
stat : AdvancedPitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byDateRangeAdvanced']
stat: AdvancedPitchingSplit
day_of_week: Optional[int] = Field(default=None, alias="dayOfWeek")
class PitchingByMonth(Split):
"""
A class to represent a byMonth stat for a pitcher.
Attributes
----------
month : int
The month.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byMonth']
month: int
stat: SimplePitchingSplit
class PitchingByMonthPlayoffs(Split):
"""
A class to represent a byMonthPlayoffs stat for a pitcher.
Attributes
----------
month : int
The month.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byMonthPlayoffs']
month: int
stat: SimplePitchingSplit
class PitchingByDayOfWeek(Split):
"""
A class to represent a byDayOfWeek stat for a pitcher.
Attributes
----------
day_of_week : int
The day of the week.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byDayOfWeek']
stat: SimplePitchingSplit
day_of_week: Optional[int] = Field(default=None, alias="dayOfWeek")
class PitchingByDayOfWeekPlayOffs(Split):
"""
A class to represent a byDayOfWeekPlayoffs stat for a pitcher.
Attributes
----------
day_of_week : int
The day of the week.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['byDayOfWeekPlayoffs']
stat: SimplePitchingSplit
day_of_week: Optional[int] = Field(default=None, alias="dayOfWeek")
class PitchingHomeAndAway(Split):
"""
A class to represent a homeAndAway stat for a pitcher.
Attributes
----------
is_home : bool
Is home bool.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['homeAndAway']
is_home: bool = Field(alias="isHome")
stat: SimplePitchingSplit
class PitchingHomeAndAwayPlayoffs(Split):
"""
A class to represent a homeAndAwayPlayoffs stat for a pitcher.
Attributes
----------
is_home : bool
Is home bool.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['homeAndAwayPlayoffs']
is_home: bool = Field(alias="isHome")
stat: SimplePitchingSplit
class PitchingWinLoss(Split):
"""
A class to represent a winLoss stat for a pitcher.
Attributes
----------
is_win : bool
Is win bool.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['winLoss']
is_win: bool = Field(alias="isWin")
stat: SimplePitchingSplit
class PitchingWinLossPlayoffs(Split):
"""
A class to represent a winLossPlayoffs stat for a pitcher.
Attributes
----------
is_win : bool
Is win bool.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['winLossPlayoffs']
is_win: bool = Field(alias="isWin")
stat: SimplePitchingSplit
class PitchingRankings(Split):
"""
A class to represent a rankingsByYear stat for a pitcher.
Attributes
----------
outs_pitched : int
Outs pitched.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['rankingsByYear']
stat: SimplePitchingSplit
outs_pitched: Optional[int] = Field(default=None, alias="outsPitched")
class PitchingOpponentsFaced(Split):
"""
A class to represent an opponentsFaced stat for a pitcher.
Attributes
----------
group : str
The stat group.
pitcher : Pitcher
The pitcher.
batter : Batter
The batter.
batting_team : Team
The batting team.
"""
_stat: ClassVar[List[str]] = ['opponentsFaced']
group: str
pitcher: Pitcher
batter: Batter
batting_team: Team = Field(alias="battingTeam")
class PitchingExpectedStatistics(Split):
"""
A class to represent an expectedStatistics stat for a pitcher.
Attributes
----------
stat : ExpectedStatistics
The expected statistics.
"""
_stat: ClassVar[List[str]] = ['expectedStatistics']
stat: ExpectedStatistics
class PitchingVsPlayer5Y(Split):
"""
A class to represent a vsPlayer5Y pitching statistic.
Requires the use of opposingPlayerId params.
Attributes
----------
opponent : Team
The opponent team.
batter : Batter
The batter.
pitcher : Pitcher
The pitcher.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['vsPlayer5Y']
opponent: Team
stat: SimplePitchingSplit
batter: Optional[Batter] = None
pitcher: Optional[Pitcher] = None
@field_validator('batter', 'pitcher', mode='before')
@classmethod
def empty_dict_to_none(cls, v: Any) -> Any:
"""Convert empty dicts to None."""
if isinstance(v, dict) and not v:
return None
return v
class PitchingVsPlayer(Split):
"""
A class to represent a vsPlayer pitching statistic.
Requires the use of opposingPlayerId params.
Attributes
----------
opponent : Team
The opponent team.
batter : Batter
The batter.
pitcher : Pitcher
The pitcher.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['vsPlayer']
opponent: Team
stat: SimplePitchingSplit
batter: Optional[Batter] = None
pitcher: Optional[Pitcher] = None
@field_validator('batter', 'pitcher', mode='before')
@classmethod
def empty_dict_to_none(cls, v: Any) -> Any:
"""Convert empty dicts to None."""
if isinstance(v, dict) and not v:
return None
return v
class PitchingVsPlayerTotal(Split):
"""
A class to represent a vsPlayerTotal pitching statistic.
Requires the use of opposingPlayerId params.
Attributes
----------
opponent : Team
The opponent team.
batter : Batter
The batter.
pitcher : Pitcher
The pitcher.
stat : SimplePitchingSplit
The pitching split stat.
"""
_stat: ClassVar[List[str]] = ['vsPlayerTotal']
stat: SimplePitchingSplit
opponent: Optional[Team] = None
batter: Optional[Batter] = None
pitcher: Optional[Pitcher] = None
@field_validator('opponent', 'batter', 'pitcher', mode='before')
@classmethod
def empty_dict_to_none(cls, v: Any) -> Any:
"""Convert empty dicts to None."""
if isinstance(v, dict) and not v:
return None
return v
# These stat_types return a hitting stat for a pitching stat group
class PitchingVsTeam(Split):
"""
A class to represent a vsTeam pitching statistic.
Attributes
----------
opponent : Team
The opponent team.
batter : Batter
The batter.
pitcher : Pitcher
The pitcher.
stat : SimpleHittingSplit
The hitting split stat.
"""
_stat: ClassVar[List[str]] = ['vsTeam']
opponent: Team
stat: SimpleHittingSplit
batter: Optional[Batter] = None
pitcher: Optional[Pitcher] = None
@field_validator('batter', 'pitcher', mode='before')
@classmethod
def empty_dict_to_none(cls, v: Any) -> Any:
"""Convert empty dicts to None."""
if isinstance(v, dict) and not v:
return None
return v
class PitchingVsTeamTotal(Split):
"""
A class to represent a vsTeamTotal pitching statistic.
Attributes
----------
opponent : Team
The opponent team.
batter : Batter
The batter.
pitcher : Pitcher
The pitcher.
stat : SimpleHittingSplit
The hitting split stat.
"""
_stat: ClassVar[List[str]] = ['vsTeamTotal']
opponent: Team
stat: SimpleHittingSplit
batter: Optional[Batter] = None
pitcher: Optional[Pitcher] = None
@field_validator('batter', 'pitcher', mode='before')
@classmethod
def empty_dict_to_none(cls, v: Any) -> Any:
"""Convert empty dicts to None."""
if isinstance(v, dict) and not v:
return None
return v