Skip to content

Commit

Permalink
Merge pull request #186 from cwendt94/BasketballBoxScoreV2
Browse files Browse the repository at this point in the history
Basketball Box Score Allow both Matchup and Scoring Id
  • Loading branch information
cwendt94 authored Mar 2, 2021
2 parents 654b83f + 99c2ef1 commit 4a0ece2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions espn_api/basketball/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,21 @@ def free_agents(self, week: int=None, size: int=50, position: str=None, position

return [Player(player) for player in players]

def box_scores(self, matchup_period: int = None, scoring_period: int = None) -> List[BoxScore]:
def box_scores(self, matchup_period: int = None, scoring_period: int = None, matchup_total: bool = True) -> List[BoxScore]:
'''Returns list of box score for a given matchup or scoring period'''
if self.year < 2019:
raise Exception('Cant use box score before 2019')

matchup_id = self.currentMatchupPeriod
scoring_id = self.current_week
total_points = True
if matchup_period and matchup_period < matchup_id:
if matchup_period and scoring_period:
matchup_id = matchup_period
scoring_id = scoring_period
elif matchup_period and matchup_period < matchup_id:
matchup_id = matchup_period
scoring_id = self.matchup_ids[matchup_period][-1] if matchup_period in self.matchup_ids else 1
elif scoring_period and scoring_period <= scoring_id:
scoring_id = scoring_period
total_points = False
for matchup in self.matchup_ids.keys():
if str(scoring_id) in self.matchup_ids[matchup]:
matchup_id = matchup
Expand All @@ -166,7 +167,7 @@ def box_scores(self, matchup_period: int = None, scoring_period: int = None) ->

schedule = data['schedule']
pro_schedule = self._get_pro_schedule(scoring_id)
box_data = [BoxScore(matchup, pro_schedule, total_points) for matchup in schedule]
box_data = [BoxScore(matchup, pro_schedule, matchup_total) for matchup in schedule]

for team in self.teams:
for matchup in box_data:
Expand Down
2 changes: 1 addition & 1 deletion tests/basketball/integration/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_league_box_scores(self):
final_matchup = league.box_scores()[0]
middle_matchup = league.box_scores(matchup_period=7)[0]
# same matchup period but single scoring period
scoring_period_matchup = league.box_scores(scoring_period=48)[0]
scoring_period_matchup = league.box_scores(scoring_period=48, matchup_total=False)[0]

self.assertEqual(final_matchup.home_score, 4240.0)
self.assertEqual(final_matchup.away_lineup[0].points, 156.0)
Expand Down

0 comments on commit 4a0ece2

Please sign in to comment.