Skip to content

Commit

Permalink
Merge pull request #203 from zero-sum-seattle/patch
Browse files Browse the repository at this point in the history
Version 0.5.16
  • Loading branch information
Mattsface authored Feb 3, 2024
2 parents 9f289b2 + 4d30a02 commit c65db52
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 59 deletions.
36 changes: 34 additions & 2 deletions mlbstatsapi/models/game/livedata/boxscore/boxscore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
from typing import Union, List
from typing import Union, List, Any, Optional
from dataclasses import dataclass, field

from .attributes import BoxScoreTeams, BoxScoreOffical, BoxScoreVL
from .attributes import BoxScoreTeams, BoxScoreOffical, BoxScoreVL, PlayersDictPerson



@dataclass
class TopPerformer:
"""
A class to represent this games topperformer
Attributes
----------
player : Player
Player
type : str
The officials for this game
gamescore : int
gamescore
hittinggamescore : int
hitting game score
"""
player: Union[PlayersDictPerson, dict]
type: str
gamescore: int
hittinggamescore: Optional[int] = None
pitchinggamescore: Optional[int] = None

def __post_init__(self):
self.player = PlayersDictPerson(**self.player)

@dataclass
class BoxScore:
Expand All @@ -19,12 +46,17 @@ class BoxScore:
pitchingnotes : List[str]
Pitching notes for this game
"""

teams: Union[BoxScoreTeams, dict]
officials: Union[List[BoxScoreOffical], List[dict]]
info: Union[List[BoxScoreVL], List[dict]]
pitchingnotes: List[str]
topperformers: Optional[List[Union[TopPerformer, dict]]] = field(default_factory=list)

def __post_init__(self):
self.teams = BoxScoreTeams(**self.teams)
self.officials = [BoxScoreOffical(**official) for official in self.officials]
self.info = [BoxScoreVL(**infos) for infos in self.info]
self.topperformers = [TopPerformer(**topperformer) for topperformer in self.topperformers]


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "python-mlb-statsapi"
version = "0.5.14"
version = "0.5.16"

authors = [
{ name="Matthew Spah", email="spahmatthew@gmail.com" },
Expand Down
56 changes: 0 additions & 56 deletions tests/external_tests/stats/test_player_game_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,15 @@ class TestHittingStats(unittest.TestCase):
def setUpClass(cls) -> None:
cls.mlb = Mlb()
cls.al_team = 133
cls.shoei_ohtani = 660271
cls.ty_france = 664034
cls.shoei_game_id = 531368
cls.ty_game_id = 715757
cls.cal_realeigh = 663728
cls.cal_game_id = 715757
cls.archie_bradley = 605151
cls.archie_game_id = 531368

@classmethod
def tearDownClass(cls) -> None:
pass


def test_get_players_stats_for_shoei_ohtana(self):
"""return player stat objects"""

game_stats = self.mlb.get_players_stats_for_game(person_id=self.shoei_ohtani,
game_id=self.shoei_game_id)

# game stats should not be None
self.assertIsNotNone(game_stats)

# game_stats should be a dict
self.assertIsInstance(game_stats, dict)

print(game_stats)
# game_stats should have hitting stats
self.assertTrue(game_stats['pitching'])

# game_stats should have vsplayer5y and playlog stats
self.assertTrue(game_stats['pitching']['vsplayer5y'])

stat = game_stats['pitching']['vsplayer5y']

for split in stat.splits:
self.assertTrue(split.team)
self.assertTrue(split.stat)

def test_get_players_stats_for_ty_france(self):
"""return player stat objects"""
Expand Down Expand Up @@ -94,32 +65,5 @@ def test_get_players_stats_for_cal_r(self):
self.assertTrue(game_stats['hitting']['playlog'])
self.assertTrue(game_stats['stats']['gamelog'])

stat = game_stats['stats']['gamelog']


def test_get_players_stats_for_archie(self):
"""return player stat objects"""

self.game_stats = self.mlb.get_players_stats_for_game(person_id=self.archie_bradley,
game_id=self.archie_game_id)

# game stats should not be None
self.assertIsNotNone(self.game_stats)

# game_stats should be a dict
self.assertIsInstance(self.game_stats, dict)

# game_stats should have hitting stats
self.assertTrue(self.game_stats['pitching'])

# game_stats should have vsplayer5y and playlog stats
self.assertTrue(self.game_stats['pitching']['vsplayer5y'])
self.assertTrue(self.game_stats['stats']['gamelog'])

game_log_stat = self.game_stats['stats']['gamelog']
self.assertTrue(len(game_log_stat.splits) == 3)
stat = self.game_stats['pitching']['vsplayer5y']

for split in stat.splits:
self.assertTrue(split.team)
self.assertTrue(split.stat)

0 comments on commit c65db52

Please sign in to comment.