Skip to content

Commit

Permalink
Merge pull request #161 from cwendt94/FixBoxScoreBug
Browse files Browse the repository at this point in the history
Fix Box Score Points for regular playoffs
  • Loading branch information
cwendt94 authored Dec 18, 2020
2 parents 22f1950 + a40ec54 commit 2b5b10f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions espn_api/football/box_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ class BoxScore(object):
''' '''
def __init__(self, data, pro_schedule, positional_rankings, week, year):
self.home_team = data['home']['teamId']
self.home_score = round(data['home']['totalPoints'], 2)
self.home_projected = -1 # week is over/not set
if 'totalPointsLive' in data['home']:
self.home_score = round(data['home']['totalPointsLive'], 2)
self.home_projected = round(data['home'].get('totalProjectedPointsLive', -1), 2)
else:
self.home_score = round(data['home']['rosterForCurrentScoringPeriod']['appliedStatTotal'], 2)
home_roster = data['home']['rosterForCurrentScoringPeriod']['entries']
self.home_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week, year) for player in home_roster]

# For Leagues with bye weeks
self.away_team = 0
self.away_score = 0
self.away_lineup = []
self.away_projected = -1 # week is over/not set
if 'away' in data:
self.away_team = data['away']['teamId']
self.away_score = round(data['away']['totalPoints'], 2)
away_roster = data['away']['rosterForCurrentScoringPeriod']['entries']
self.away_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week, year) for player in away_roster]
self.away_team = data['away']['teamId']
if 'totalPointsLive' in data['away']:
self.away_score = round(data['away']['totalPointsLive'], 2)
self.away_projected = round(data['away'].get('totalProjectedPointsLive', -1), 2)
else:
self.away_score = round(data['away']['rosterForCurrentScoringPeriod']['appliedStatTotal'], 2)
away_roster = data['away']['rosterForCurrentScoringPeriod']['entries']
self.away_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week, year) for player in away_roster]

def __repr__(self):
away_team = self.away_team if self.away_team else "BYE"
Expand Down
2 changes: 1 addition & 1 deletion espn_api/football/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def box_scores(self, week: int = None) -> List[BoxScore]:
schedule = data['schedule']
pro_schedule = self._get_pro_schedule(scoring_period)
positional_rankings = self._get_positional_ratings(scoring_period)
box_data = [BoxScore(matchup, pro_schedule, positional_rankings, week, self.year) for matchup in schedule]
box_data = [BoxScore(matchup, pro_schedule, positional_rankings, scoring_period, self.year) for matchup in schedule]

for team in self.teams:
for matchup in box_data:
Expand Down

0 comments on commit 2b5b10f

Please sign in to comment.