Skip to content

Commit

Permalink
Football Add Avg Points to Player
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendt94 committed Oct 23, 2023
1 parent 38860d4 commit 783d2db
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions espn_api/football/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ def __init__(self, data, year):
stats_breakdown = stats.get('stats') or stats.get('appliedStats', {})
breakdown = {PLAYER_STATS_MAP.get(int(k), k):v for (k,v) in stats_breakdown.items()}
points = round(stats.get('appliedTotal', 0), 2)
avg_points = round(stats.get('appliedAverage', 0), 2)
scoring_period = stats.get('scoringPeriodId')
stat_source = stats.get('statSourceId')
(points_type, breakdown_type) = ('points', 'breakdown') if stat_source == 0 else ('projected_points', 'projected_breakdown')
(points_type, breakdown_type, avg_type) = ('points', 'breakdown', 'avg_points') if stat_source == 0 else ('projected_points', 'projected_breakdown', 'projected_avg_points')
if self.stats.get(scoring_period):
self.stats[scoring_period][points_type] = points
self.stats[scoring_period][breakdown_type] = breakdown
self.stats[scoring_period][avg_type] = avg_points
else:
self.stats[scoring_period] = {points_type: points, breakdown_type: breakdown}
self.stats[scoring_period] = {points_type: points, breakdown_type: breakdown, avg_type: avg_points}
self.total_points = self.stats.get(0, {}).get('points', 0)
self.projected_total_points = self.stats.get(0, {}).get('projected_points', 0)
self.avg_points = self.stats.get(0, {}).get('avg_points', 0)
self.projected_avg_points = self.stats.get(0, {}).get('projected_avg_points', 0)

def __repr__(self):
return f'Player({self.name})'

0 comments on commit 783d2db

Please sign in to comment.