Jon Solow commited on
Commit
a42b348
·
1 Parent(s): 6c6e34b

Implement score and final status from live yahoo source

Browse files
Files changed (2) hide show
  1. src/pages/11_Scoreboard.py +2 -2
  2. src/stats.py +44 -0
src/pages/11_Scoreboard.py CHANGED
@@ -8,7 +8,7 @@ from data_storage import get_all_users, get_all_rosters
8
  from domain.constants import SEASON
9
  from domain.playoffs import CURRENT_PLAYOFF_WEEK, PLAYOFF_WEEK_TO_NAME
10
  from load_options import get_map_week_player_id_option, PlayerOption
11
- from stats import get_stats_map, get_scores_map
12
  from queries.pfr.league_schedule import get_season_game_map
13
 
14
 
@@ -25,7 +25,7 @@ POSITION_LABELS = [
25
 
26
 
27
  def get_live_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
28
- return {}
29
 
30
 
31
  @st.cache_data(ttl=60 * 60 * 24)
 
8
  from domain.constants import SEASON
9
  from domain.playoffs import CURRENT_PLAYOFF_WEEK, PLAYOFF_WEEK_TO_NAME
10
  from load_options import get_map_week_player_id_option, PlayerOption
11
+ from stats import get_stats_map, get_scores_map, get_yahoo_schedule
12
  from queries.pfr.league_schedule import get_season_game_map
13
 
14
 
 
25
 
26
 
27
  def get_live_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
28
+ return get_yahoo_schedule()
29
 
30
 
31
  @st.cache_data(ttl=60 * 60 * 24)
src/stats.py CHANGED
@@ -308,6 +308,50 @@ def get_yahoo_stat_json_obj():
308
  return dom_json
309
 
310
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  def get_yahoo_stats() -> dict[int, dict[str, dict[str, float]]]:
312
  dom_json = get_yahoo_stat_json_obj()
313
  stat_map: dict[int, dict[str, dict[str, float]]] = {w: {} for w in NFLVERSE_STAT_WEEK_TO_PLAYOFF_WEEK.values()}
 
308
  return dom_json
309
 
310
 
311
+ def get_yahoo_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
312
+ schedule_map: dict[int, dict[str, dict[str, str | int | pd.Timestamp]]] = {}
313
+ dom_json = get_yahoo_stat_json_obj()
314
+ team_id_to_abbr = {}
315
+ teams_json = dom_json["context"]["dispatcher"]["stores"]["TeamsStore"]["teams"]
316
+ for team_key, team_dict in teams_json.items():
317
+ if not team_key.split(".")[0] == "nfl":
318
+ continue
319
+ team_id_to_abbr[team_dict["team_id"]] = team_dict["abbr"]
320
+
321
+ games_json = dom_json["context"]["dispatcher"]["stores"]["GamesStore"]["games"]
322
+ for game_id, game in games_json.items():
323
+ if not game_id.split(".")[0] == "nfl":
324
+ continue
325
+ away_team = team_id_to_abbr[game["away_team_id"]]
326
+ home_team = team_id_to_abbr[game["home_team_id"]]
327
+ week = YAHOO_WEEK_MAP[int(game["week_number"])]
328
+ away_score = int(game["total_away_points"] or 0)
329
+ home_score = int(game["total_home_points"] or 0)
330
+ if week not in schedule_map:
331
+ schedule_map[week] = {}
332
+
333
+ home_team_map: dict[str, str | int | pd.Timestamp] = {
334
+ "score": home_score,
335
+ "opponent_score": away_score,
336
+ }
337
+ away_team_map: dict[str, str | int | pd.Timestamp] = {
338
+ "score": away_score,
339
+ "opponent_score": home_score,
340
+ }
341
+
342
+ if game["status_type"] == "final":
343
+ home_team_win = home_score > away_score
344
+ home_status = "Win" if home_team_win else "Loss"
345
+ away_status = "Loss" if home_team_win else "Win"
346
+ home_team_map.update({"status": home_status})
347
+ away_team_map.update({"status": away_status})
348
+
349
+ schedule_map[week][home_team] = home_team_map
350
+ schedule_map[week][away_team] = away_team_map
351
+
352
+ return schedule_map
353
+
354
+
355
  def get_yahoo_stats() -> dict[int, dict[str, dict[str, float]]]:
356
  dom_json = get_yahoo_stat_json_obj()
357
  stat_map: dict[int, dict[str, dict[str, float]]] = {w: {} for w in NFLVERSE_STAT_WEEK_TO_PLAYOFF_WEEK.values()}