Jon Solow
commited on
Commit
·
656be95
1
Parent(s):
f36022f
Fix for showing scoreboard when schedule map breaks
Browse files- src/stats.py +42 -35
src/stats.py
CHANGED
@@ -412,7 +412,10 @@ def get_yahoo_stats() -> dict[int, dict[str, dict[str, float]]]:
|
|
412 |
|
413 |
|
414 |
def get_live_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
|
415 |
-
|
|
|
|
|
|
|
416 |
|
417 |
|
418 |
@st.cache_data(ttl=60 * 60 * 24)
|
@@ -442,41 +445,45 @@ def add_points_against_team_win_stat(stat_map: dict[int, dict[str, dict[str, flo
|
|
442 |
for week, week_map in stat_map.items():
|
443 |
for player_id in week_map.keys():
|
444 |
if team_short_name := DEFENSE_PLAYER_ID_TO_ROSTER_TEAM_NAMES.get(player_id):
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
continue
|
453 |
-
opponent_score = float(opponent_score_str) # noqa
|
454 |
-
|
455 |
-
opponent_def_points_scored = (
|
456 |
-
opponent_def_stats.get(TWO_PT.key, 0.0) * 2.0
|
457 |
-
+ opponent_def_stats.get(DEF_TD.key, 0.0) * 6.0
|
458 |
-
+ opponent_def_stats.get(ST_TD.key, 0.0) * 6.0
|
459 |
-
)
|
460 |
-
points_allowed = opponent_score - opponent_def_points_scored
|
461 |
-
|
462 |
-
if points_allowed == 0:
|
463 |
-
stat_map[week][player_id].update({PTS_ALLOW_0.key: 1})
|
464 |
-
elif points_allowed < 7:
|
465 |
-
stat_map[week][player_id].update({PTS_ALLOW_1_6.key: 1})
|
466 |
-
elif points_allowed < 14:
|
467 |
-
stat_map[week][player_id].update({PTS_ALLOW_7_13.key: 1})
|
468 |
-
elif points_allowed < 21:
|
469 |
-
stat_map[week][player_id].update({PTS_ALLOW_14_20.key: 1})
|
470 |
-
elif points_allowed < 28:
|
471 |
-
stat_map[week][player_id].update({PTS_ALLOW_21_27.key: 1})
|
472 |
-
elif points_allowed < 35:
|
473 |
-
stat_map[week][player_id].update({PTS_ALLOW_28_34.key: 1})
|
474 |
-
else:
|
475 |
-
stat_map[week][player_id].update({PTS_ALLOW_35_.key: 1})
|
476 |
-
|
477 |
-
# check for win
|
478 |
-
if team_game["status"] == "Win":
|
479 |
-
stat_map[week][player_id].update({TEAM_WIN.key: 1})
|
480 |
|
481 |
|
482 |
@st.cache_data(ttl=STAT_CACHE_SECONDS)
|
|
|
412 |
|
413 |
|
414 |
def get_live_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
|
415 |
+
try:
|
416 |
+
return get_yahoo_schedule()
|
417 |
+
except:
|
418 |
+
return {}
|
419 |
|
420 |
|
421 |
@st.cache_data(ttl=60 * 60 * 24)
|
|
|
445 |
for week, week_map in stat_map.items():
|
446 |
for player_id in week_map.keys():
|
447 |
if team_short_name := DEFENSE_PLAYER_ID_TO_ROSTER_TEAM_NAMES.get(player_id):
|
448 |
+
try:
|
449 |
+
team_game = schedule[week][team_short_name]
|
450 |
+
opponent_team = str(team_game["opponent"])
|
451 |
+
opponent_player_id = ROSTER_TEAM_NAMES_TO_DEFENSE_PLAYER_ID[opponent_team]
|
452 |
+
opponent_def_stats = week_map[opponent_player_id]
|
453 |
+
|
454 |
+
if isinstance((opponent_score_str := team_game["opponent_score"]), pd.Timestamp):
|
455 |
+
# another case not possible but makes mypy happy
|
456 |
+
continue
|
457 |
+
opponent_score = float(opponent_score_str) # noqa
|
458 |
+
|
459 |
+
opponent_def_points_scored = (
|
460 |
+
opponent_def_stats.get(TWO_PT.key, 0.0) * 2.0
|
461 |
+
+ opponent_def_stats.get(DEF_TD.key, 0.0) * 6.0
|
462 |
+
+ opponent_def_stats.get(ST_TD.key, 0.0) * 6.0
|
463 |
+
)
|
464 |
+
points_allowed = opponent_score - opponent_def_points_scored
|
465 |
+
|
466 |
+
if points_allowed == 0:
|
467 |
+
stat_map[week][player_id].update({PTS_ALLOW_0.key: 1})
|
468 |
+
elif points_allowed < 7:
|
469 |
+
stat_map[week][player_id].update({PTS_ALLOW_1_6.key: 1})
|
470 |
+
elif points_allowed < 14:
|
471 |
+
stat_map[week][player_id].update({PTS_ALLOW_7_13.key: 1})
|
472 |
+
elif points_allowed < 21:
|
473 |
+
stat_map[week][player_id].update({PTS_ALLOW_14_20.key: 1})
|
474 |
+
elif points_allowed < 28:
|
475 |
+
stat_map[week][player_id].update({PTS_ALLOW_21_27.key: 1})
|
476 |
+
elif points_allowed < 35:
|
477 |
+
stat_map[week][player_id].update({PTS_ALLOW_28_34.key: 1})
|
478 |
+
else:
|
479 |
+
stat_map[week][player_id].update({PTS_ALLOW_35_.key: 1})
|
480 |
+
|
481 |
+
# check for win
|
482 |
+
if team_game["status"] == "Win":
|
483 |
+
stat_map[week][player_id].update({TEAM_WIN.key: 1})
|
484 |
+
|
485 |
+
except Exception:
|
486 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
487 |
|
488 |
|
489 |
@st.cache_data(ttl=STAT_CACHE_SECONDS)
|