Jon Solow
commited on
Commit
·
7730451
1
Parent(s):
8aedeba
Implement live kicking stats
Browse files- src/stats.py +19 -5
src/stats.py
CHANGED
@@ -210,6 +210,14 @@ YAHOO_TO_STAT_MAP = {
|
|
210 |
"RECEIVING_TOUCHDOWNS": REC_TD.key,
|
211 |
"FUMBLES_LOST": FUM_LOST.key,
|
212 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
}
|
214 |
|
215 |
|
@@ -241,9 +249,12 @@ def add_yahoo_stat_type_to_stat_map(
|
|
241 |
if week not in stat_map:
|
242 |
stat_map[week] = {}
|
243 |
|
244 |
-
|
245 |
-
"leaders"
|
246 |
-
|
|
|
|
|
|
|
247 |
|
248 |
for player in week_leaders:
|
249 |
raw_player_id = player["player"]["playerId"].split(".")[-1]
|
@@ -253,7 +264,10 @@ def add_yahoo_stat_type_to_stat_map(
|
|
253 |
stats = player["stats"]
|
254 |
for stat in stats:
|
255 |
if stat_key := YAHOO_TO_STAT_MAP[yahoo_stat_type].get(stat["statId"]):
|
256 |
-
stat_map[week][player_id]
|
|
|
|
|
|
|
257 |
# else:
|
258 |
# # remove after mapping all intended
|
259 |
# stat_map[week][player_id][stat["statId"]] = stat["value"]
|
@@ -286,7 +300,7 @@ def get_yahoo_stats() -> dict[int, dict[str, dict[str, float]]]:
|
|
286 |
add_yahoo_stat_type_to_stat_map(
|
287 |
stats_json["weeklyStatsFootballReceiving"]["nfl"]["200"]["2023"], "RECEIVING", stat_map
|
288 |
)
|
289 |
-
|
290 |
return_stats = stats_json["weeklyStatsFootballReturns"]["nfl"]["200"]["2023"]
|
291 |
defense_stats = stats_json["weeklyStatsFootballDefense"]["nfl"]["200"]["2023"]
|
292 |
|
|
|
210 |
"RECEIVING_TOUCHDOWNS": REC_TD.key,
|
211 |
"FUMBLES_LOST": FUM_LOST.key,
|
212 |
},
|
213 |
+
"KICKING": {
|
214 |
+
"FIELD_GOALS_MADE_0_19": FG_0_49.key,
|
215 |
+
"FIELD_GOALS_MADE_20_29": FG_0_49.key,
|
216 |
+
"FIELD_GOALS_MADE_30_39": FG_0_49.key,
|
217 |
+
"FIELD_GOALS_MADE_40_49": FG_0_49.key,
|
218 |
+
"FIELD_GOALS_MADE_50_PLUS": FG_50_.key,
|
219 |
+
"EXTRA_POINTS_MADE": XP.key,
|
220 |
+
},
|
221 |
}
|
222 |
|
223 |
|
|
|
249 |
if week not in stat_map:
|
250 |
stat_map[week] = {}
|
251 |
|
252 |
+
if yahoo_stat_type == "KICKING":
|
253 |
+
week_leaders = week_dict["POSTSEASON"][""]["FIELD_GOALS_MADE"]["leagues"][0]["leagueWeeks"][0]["leaders"]
|
254 |
+
else:
|
255 |
+
week_leaders = week_dict["POSTSEASON"][""][f"{yahoo_stat_type}_YARDS"]["leagues"][0]["leagueWeeks"][0][
|
256 |
+
"leaders"
|
257 |
+
]
|
258 |
|
259 |
for player in week_leaders:
|
260 |
raw_player_id = player["player"]["playerId"].split(".")[-1]
|
|
|
264 |
stats = player["stats"]
|
265 |
for stat in stats:
|
266 |
if stat_key := YAHOO_TO_STAT_MAP[yahoo_stat_type].get(stat["statId"]):
|
267 |
+
if stat_key in stat_map[week][player_id]:
|
268 |
+
stat_map[week][player_id][stat_key] += float(stat["value"])
|
269 |
+
else:
|
270 |
+
stat_map[week][player_id][stat_key] = float(stat["value"])
|
271 |
# else:
|
272 |
# # remove after mapping all intended
|
273 |
# stat_map[week][player_id][stat["statId"]] = stat["value"]
|
|
|
300 |
add_yahoo_stat_type_to_stat_map(
|
301 |
stats_json["weeklyStatsFootballReceiving"]["nfl"]["200"]["2023"], "RECEIVING", stat_map
|
302 |
)
|
303 |
+
add_yahoo_stat_type_to_stat_map(stats_json["weeklyStatsFootballKicking"]["nfl"]["200"]["2023"], "KICKING", stat_map)
|
304 |
return_stats = stats_json["weeklyStatsFootballReturns"]["nfl"]["200"]["2023"]
|
305 |
defense_stats = stats_json["weeklyStatsFootballDefense"]["nfl"]["200"]["2023"]
|
306 |
|