From 3cda1f42ceefb754b7148c393125dc864feb5409 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Fri, 17 Nov 2023 21:36:31 -0500 Subject: [PATCH] feat: Add active status to `Player` This uses the embedded stats objects to decipher whether a player was active in a historical week. * `active`: the player had a game and participated in it * `inactive`: the player had a game but did not participate in it (due to injury or suspension) * `bye`: the player did not have a game that week --- espn_api/football/player.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/espn_api/football/player.py b/espn_api/football/player.py index 2ac0a018..c099afa9 100644 --- a/espn_api/football/player.py +++ b/espn_api/football/player.py @@ -27,6 +27,7 @@ def __init__(self, data, year): self.percent_owned = round(player.get('ownership', {}).get('percentOwned', -1), 2) self.percent_started = round(player.get('ownership', {}).get('percentStarted', -1), 2) + self.active_status = 'bye' player_stats = player.get('stats', []) for stats in player_stats: if stats.get('seasonId') != year: @@ -49,5 +50,12 @@ def __init__(self, data, year): self.avg_points = self.stats.get(0, {}).get('avg_points', 0) self.projected_avg_points = self.stats.get(0, {}).get('projected_avg_points', 0) + if not stat_source: + if not self.stats[scoring_period][breakdown_type]: + self.active_status = 'inactive' + else: + self.active_status = 'active' + + def __repr__(self): return f'Player({self.name})'