-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathattributes.py
More file actions
96 lines (86 loc) · 2.52 KB
/
attributes.py
File metadata and controls
96 lines (86 loc) · 2.52 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
from typing import Optional
from pydantic import Field, field_validator
from mlbstatsapi.models.base import MLBBaseModel
from mlbstatsapi.models.people import Person, Position
class RunnerCredits(MLBBaseModel):
"""
A class to represent a runner's credit.
Attributes
----------
player : Person
The player.
position : Position
The position.
credit : str
The credit.
"""
player: Person
position: Position
credit: str
class RunnerMovement(MLBBaseModel):
"""
A class to represent a play runner movement.
Attributes
----------
is_out : bool
Was the running movement an out.
out_number : int
What is the out number (None if not an out).
origin_base : str
Original base.
start : str
What base the runner started from.
end : str
What base the runner ended at.
out_base : str
Base runner was made out.
"""
is_out: bool = Field(default=False, alias="isOut")
out_number: Optional[int] = Field(default=None, alias="outNumber")
origin_base: Optional[str] = Field(default=None, alias="originBase")
start: Optional[str] = None
end: Optional[str] = None
out_base: Optional[str] = Field(default=None, alias="outBase")
@field_validator("is_out", mode="before")
@classmethod
def _coerce_is_out(cls, v):
# MLB API occasionally returns null for isOut.
if v is None:
return False
return v
class RunnerDetails(MLBBaseModel):
"""
A class to represent a play runner details.
Attributes
----------
event : str
Runner event.
event_type : str
Runner event type.
runner : Person
Who the runner is.
is_scoring_event : bool
Was this a scoring event.
rbi : bool
Was this an RBI.
earned : bool
Was it earned.
team_unearned : bool
Was it unearned.
play_index : int
Play index.
movement_reason : str
Reason for the movement.
responsible_pitcher : Person
Who was the responsible pitcher.
"""
event: str
event_type: str = Field(alias="eventType")
runner: Person
is_scoring_event: bool = Field(alias="isScoringEvent")
rbi: bool
earned: bool
team_unearned: bool = Field(alias="teamUnearned")
play_index: int = Field(alias="playIndex")
movement_reason: Optional[str] = Field(default=None, alias="movementReason")
responsible_pitcher: Optional[Person] = Field(default=None, alias="responsiblePitcher")