Skip to content

Commit

Permalink
Merge pull request #372 from cwendt94/box_score_projected
Browse files Browse the repository at this point in the history
FB Caculate Box Score Projected
  • Loading branch information
cwendt94 authored Sep 29, 2022
2 parents 1dda8f4 + d4b7c97 commit 956b8c0
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions espn_api/football/box_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@ def __init__(self, data, pro_schedule, positional_rankings, week, year):
self.matchup_type = data.get('playoffTierType', 'NONE')
self.is_playoff = self.matchup_type != 'NONE'

self.home_team = data['home']['teamId']
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]
(self.home_team, self.home_score, self.home_projected, self.home_lineup) = self._get_team_data('home', data, pro_schedule, positional_rankings, week, year)
self.home_projected = self._get_projected_score(self.home_projected, self.home_lineup)

# 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']
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]
(self.away_team, self.away_score, self.away_projected, self.away_lineup) = self._get_team_data('away', data, pro_schedule, positional_rankings, week, year)
self.away_projected = self._get_projected_score(self.away_projected, self.away_lineup)

def __repr__(self):
away_team = self.away_team or "BYE"
home_team = self.home_team or "BYE"
return f'Box Score({away_team} at {home_team})'

def _get_projected_score(self, projected_score, lineup):
if projected_score != -1:
return projected_score
projected_score = 0
for player in lineup:
if player.slot_position != 'BE' and player.slot_position != 'IR':
projected_score += player.projected_points
return projected_score

def _get_team_data(self, team, data, pro_schedule, positional_rankings, week, year):
if team not in data:
return (0, 0, -1, [])

team_id = data[team]['teamId']
team_projected = -1
if 'totalPointsLive' in data[team]:
team_score = round(data[team]['totalPointsLive'], 2)
team_projected = round(data[team].get('totalProjectedPointsLive', -1), 2)
else:
team_score = round(data[team]['rosterForCurrentScoringPeriod']['appliedStatTotal'], 2)
team_roster = data[team]['rosterForCurrentScoringPeriod']['entries']
team_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week, year) for player in team_roster]

return (team_id, team_score, team_projected, team_lineup)

0 comments on commit 956b8c0

Please sign in to comment.