Skip to content

Commit c65db52

Browse files
authored
Merge pull request #203 from zero-sum-seattle/patch
Version 0.5.16
2 parents 9f289b2 + 4d30a02 commit c65db52

3 files changed

Lines changed: 35 additions & 59 deletions

File tree

mlbstatsapi/models/game/livedata/boxscore/boxscore.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1-
from typing import Union, List
1+
from typing import Union, List, Any, Optional
22
from dataclasses import dataclass, field
33

4-
from .attributes import BoxScoreTeams, BoxScoreOffical, BoxScoreVL
4+
from .attributes import BoxScoreTeams, BoxScoreOffical, BoxScoreVL, PlayersDictPerson
5+
6+
7+
8+
@dataclass
9+
class TopPerformer:
10+
"""
11+
A class to represent this games topperformer
12+
13+
Attributes
14+
----------
15+
player : Player
16+
Player
17+
type : str
18+
The officials for this game
19+
gamescore : int
20+
gamescore
21+
hittinggamescore : int
22+
hitting game score
23+
"""
24+
player: Union[PlayersDictPerson, dict]
25+
type: str
26+
gamescore: int
27+
hittinggamescore: Optional[int] = None
28+
pitchinggamescore: Optional[int] = None
29+
30+
def __post_init__(self):
31+
self.player = PlayersDictPerson(**self.player)
532

633
@dataclass
734
class BoxScore:
@@ -19,12 +46,17 @@ class BoxScore:
1946
pitchingnotes : List[str]
2047
Pitching notes for this game
2148
"""
49+
2250
teams: Union[BoxScoreTeams, dict]
2351
officials: Union[List[BoxScoreOffical], List[dict]]
2452
info: Union[List[BoxScoreVL], List[dict]]
2553
pitchingnotes: List[str]
54+
topperformers: Optional[List[Union[TopPerformer, dict]]] = field(default_factory=list)
2655

2756
def __post_init__(self):
2857
self.teams = BoxScoreTeams(**self.teams)
2958
self.officials = [BoxScoreOffical(**official) for official in self.officials]
3059
self.info = [BoxScoreVL(**infos) for infos in self.info]
60+
self.topperformers = [TopPerformer(**topperformer) for topperformer in self.topperformers]
61+
62+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python-mlb-statsapi"
7-
version = "0.5.14"
7+
version = "0.5.16"
88

99
authors = [
1010
{ name="Matthew Spah", email="spahmatthew@gmail.com" },

tests/external_tests/stats/test_player_game_stats.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,15 @@ class TestHittingStats(unittest.TestCase):
99
def setUpClass(cls) -> None:
1010
cls.mlb = Mlb()
1111
cls.al_team = 133
12-
cls.shoei_ohtani = 660271
1312
cls.ty_france = 664034
14-
cls.shoei_game_id = 531368
1513
cls.ty_game_id = 715757
1614
cls.cal_realeigh = 663728
1715
cls.cal_game_id = 715757
18-
cls.archie_bradley = 605151
19-
cls.archie_game_id = 531368
2016

2117
@classmethod
2218
def tearDownClass(cls) -> None:
2319
pass
2420

25-
26-
def test_get_players_stats_for_shoei_ohtana(self):
27-
"""return player stat objects"""
28-
29-
game_stats = self.mlb.get_players_stats_for_game(person_id=self.shoei_ohtani,
30-
game_id=self.shoei_game_id)
31-
32-
# game stats should not be None
33-
self.assertIsNotNone(game_stats)
34-
35-
# game_stats should be a dict
36-
self.assertIsInstance(game_stats, dict)
37-
38-
print(game_stats)
39-
# game_stats should have hitting stats
40-
self.assertTrue(game_stats['pitching'])
41-
42-
# game_stats should have vsplayer5y and playlog stats
43-
self.assertTrue(game_stats['pitching']['vsplayer5y'])
44-
45-
stat = game_stats['pitching']['vsplayer5y']
46-
47-
for split in stat.splits:
48-
self.assertTrue(split.team)
49-
self.assertTrue(split.stat)
5021

5122
def test_get_players_stats_for_ty_france(self):
5223
"""return player stat objects"""
@@ -94,32 +65,5 @@ def test_get_players_stats_for_cal_r(self):
9465
self.assertTrue(game_stats['hitting']['playlog'])
9566
self.assertTrue(game_stats['stats']['gamelog'])
9667

97-
stat = game_stats['stats']['gamelog']
98-
99-
100-
def test_get_players_stats_for_archie(self):
101-
"""return player stat objects"""
102-
103-
self.game_stats = self.mlb.get_players_stats_for_game(person_id=self.archie_bradley,
104-
game_id=self.archie_game_id)
105-
106-
# game stats should not be None
107-
self.assertIsNotNone(self.game_stats)
10868

109-
# game_stats should be a dict
110-
self.assertIsInstance(self.game_stats, dict)
11169

112-
# game_stats should have hitting stats
113-
self.assertTrue(self.game_stats['pitching'])
114-
115-
# game_stats should have vsplayer5y and playlog stats
116-
self.assertTrue(self.game_stats['pitching']['vsplayer5y'])
117-
self.assertTrue(self.game_stats['stats']['gamelog'])
118-
119-
game_log_stat = self.game_stats['stats']['gamelog']
120-
self.assertTrue(len(game_log_stat.splits) == 3)
121-
stat = self.game_stats['pitching']['vsplayer5y']
122-
123-
for split in stat.splits:
124-
self.assertTrue(split.team)
125-
self.assertTrue(split.stat)

0 commit comments

Comments
 (0)