From 3cda1f42ceefb754b7148c393125dc864feb5409 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Fri, 17 Nov 2023 21:36:31 -0500 Subject: [PATCH 1/3] 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})' From 55741f39befeab6911b98ec67b3a436f253610cf Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Fri, 17 Nov 2023 21:44:06 -0500 Subject: [PATCH 2/3] lint: remove blank lines --- espn_api/football/player.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/espn_api/football/player.py b/espn_api/football/player.py index c099afa9..22895eac 100644 --- a/espn_api/football/player.py +++ b/espn_api/football/player.py @@ -49,13 +49,11 @@ def __init__(self, data, year): 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) - 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})' From 3c00fdce928b321c65611ae60476879cc6092922 Mon Sep 17 00:00:00 2001 From: Desi Pilla Date: Fri, 17 Nov 2023 21:46:40 -0500 Subject: [PATCH 3/3] fix: fix indent error I'm just an idiot don't mind me --- espn_api/football/player.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/espn_api/football/player.py b/espn_api/football/player.py index 22895eac..3d94d70b 100644 --- a/espn_api/football/player.py +++ b/espn_api/football/player.py @@ -45,15 +45,15 @@ def __init__(self, data, year): self.stats[scoring_period][avg_type] = avg_points else: 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) if not stat_source: if not self.stats[scoring_period][breakdown_type]: self.active_status = 'inactive' else: self.active_status = 'active' + 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})'