Skip to content

Commit

Permalink
Merge pull request #484 from cwendt94/football-player-avg-points
Browse files Browse the repository at this point in the history
Football Add Avg Points to Player
  • Loading branch information
cwendt94 authored Oct 25, 2023
2 parents 36b8ab2 + 783d2db commit 67f1660
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 67f1660

Please sign in to comment.