Skip to content

Commit

Permalink
Merge pull request #423 from cjwin2000/master
Browse files Browse the repository at this point in the history
Only grab player stats for specified year
  • Loading branch information
cwendt94 authored Dec 15, 2022
2 parents 2cd8152 + 5585186 commit aa15b28
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions espn_api/basketball/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ def __init__(self, data, year, pro_team_schedule = None):
self.injured = player.get('injured', False)

for split in player.get('stats', []):
id = self._stat_id_pretty(split['id'], split['scoringPeriodId'])
applied_total = split.get('appliedTotal', 0)
applied_avg = round(split.get('appliedAverage', 0), 2)
game = self.schedule.get(id, {})
self.stats[id] = dict(applied_total=applied_total, applied_avg=applied_avg, team=game.get('team', None), date=game.get('date', None))
if split['stats']:
if 'averageStats' in split.keys():
self.stats[id]['avg'] = {STATS_MAP.get(i, i): split['averageStats'][i] for i in split['averageStats'].keys() if STATS_MAP.get(i) != ''}
self.stats[id]['total'] = {STATS_MAP.get(i, i): split['stats'][i] for i in split['stats'].keys() if STATS_MAP.get(i) != ''}
else:
self.stats[id]['avg'] = None
self.stats[id]['total'] = {STATS_MAP.get(i, i): split['stats'][i] for i in split['stats'].keys() if STATS_MAP.get(i) != ''}
if split['seasonId'] == year:
id = self._stat_id_pretty(split['id'], split['scoringPeriodId'])
applied_total = split.get('appliedTotal', 0)
applied_avg = round(split.get('appliedAverage', 0), 2)
game = self.schedule.get(id, {})
self.stats[id] = dict(applied_total=applied_total, applied_avg=applied_avg, team=game.get('team', None), date=game.get('date', None))
if split['stats']:
if 'averageStats' in split.keys():
self.stats[id]['avg'] = {STATS_MAP.get(i, i): split['averageStats'][i] for i in split['averageStats'].keys() if STATS_MAP.get(i) != ''}
self.stats[id]['total'] = {STATS_MAP.get(i, i): split['stats'][i] for i in split['stats'].keys() if STATS_MAP.get(i) != ''}
else:
self.stats[id]['avg'] = None
self.stats[id]['total'] = {STATS_MAP.get(i, i): split['stats'][i] for i in split['stats'].keys() if STATS_MAP.get(i) != ''}
self.total_points = self.stats.get(f'{year}_total', {}).get('applied_total', 0)
self.avg_points = self.stats.get(f'{year}_total', {}).get('applied_avg', 0)
self.projected_total_points= self.stats.get(f'{year}_projected', {}).get('applied_total', 0)
Expand All @@ -55,4 +56,4 @@ def __repr__(self):

def _stat_id_pretty(self, id: str, scoring_period):
id_type = STAT_ID_MAP.get(id[:2])
return f'{id[2:]}_{id_type}' if id_type else str(scoring_period)
return f'{id[2:]}_{id_type}' if id_type else str(scoring_period)

0 comments on commit aa15b28

Please sign in to comment.