Jon Solow commited on
Commit
459585e
1 Parent(s): 4e3fad6

Map team names in schedule to start and implement scores shown

Browse files
src/domain/teams.py CHANGED
@@ -299,4 +299,4 @@ washington_football_team = NFLTeam(
299
  )
300
 
301
 
302
- SCHEDULE_NAME_TO_PFR_NAME_MAP = {t.rosters_short_name: t.team_full_name for t in ALL_TEAMS}
 
299
  )
300
 
301
 
302
+ PFR_NAME_TO_SCHEDULE_NAME_MAP = {t.team_full_name: t.rosters_short_name for t in ALL_TEAMS}
src/load_options.py CHANGED
@@ -9,7 +9,6 @@ from domain.playoffs import (
9
  PLAYOFFS_TEAMS,
10
  PLAYOFF_TEAM_DEF_PLAYER,
11
  )
12
- from domain.teams import SCHEDULE_NAME_TO_PFR_NAME_MAP
13
  from queries.nflverse.github_data import get_weekly_rosters
14
  from queries.pfr.league_schedule import get_season_game_map
15
 
@@ -117,7 +116,7 @@ def load_options():
117
  return initialize_empty_options_map()
118
  df_rosters["gametime"] = df_rosters.apply(
119
  lambda x: week_game_times.get(x.week, {})
120
- .get(SCHEDULE_NAME_TO_PFR_NAME_MAP[x.team], {})
121
  .get("gametime", latest_game_time_defaults.get(x.week, None)),
122
  axis=1,
123
  )
 
9
  PLAYOFFS_TEAMS,
10
  PLAYOFF_TEAM_DEF_PLAYER,
11
  )
 
12
  from queries.nflverse.github_data import get_weekly_rosters
13
  from queries.pfr.league_schedule import get_season_game_map
14
 
 
116
  return initialize_empty_options_map()
117
  df_rosters["gametime"] = df_rosters.apply(
118
  lambda x: week_game_times.get(x.week, {})
119
+ .get(x.team, {})
120
  .get("gametime", latest_game_time_defaults.get(x.week, None)),
121
  axis=1,
122
  )
src/pages/11_Scoreboard.py CHANGED
@@ -5,9 +5,11 @@ from config import DEFAULT_ICON
5
  from shared_page import common_page_config
6
 
7
  from data_storage import get_all_users, get_all_rosters
 
8
  from domain.playoffs import CURRENT_PLAYOFF_WEEK, PLAYOFF_WEEK_TO_NAME
9
  from load_options import get_map_week_player_id_option, PlayerOption
10
  from stats import get_stats_map, get_scores_map
 
11
 
12
 
13
  POSITION_LABELS = [
@@ -22,6 +24,27 @@ POSITION_LABELS = [
22
  ]
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def get_users_df():
26
  columns = ["user_id", "name"]
27
  all_users = pd.DataFrame(get_all_users(columns_included=columns), columns=columns)
@@ -65,8 +88,10 @@ def get_roster_html_str(week: int, user_map: dict[str, PlayerOption]) -> str:
65
  def get_player_html_str(player_opt: PlayerOption, player_stats: dict[str, float], score: float) -> str:
66
  # TODO
67
  multiplier = 1
 
 
68
  game_status = " "
69
- game_score = " "
70
  player_stats_str = get_player_stats_html_str(player_stats)
71
 
72
  player_classes = "player"
 
5
  from shared_page import common_page_config
6
 
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
 
15
  POSITION_LABELS = [
 
24
  ]
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)
32
+ def get_daily_updated_schedule() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
33
+ schedule, _ = get_season_game_map(SEASON)
34
+ return schedule
35
+
36
+
37
+ @st.cache_data(ttl=60 * 5)
38
+ def get_schedule_with_live() -> dict[int, dict[str, dict[str, str | int | pd.Timestamp]]]:
39
+ schedule = get_daily_updated_schedule()
40
+
41
+ for week, week_live in get_live_schedule().items():
42
+ for team, team_live in week_live.items():
43
+ schedule[week][team].update(team_live)
44
+
45
+ return schedule
46
+
47
+
48
  def get_users_df():
49
  columns = ["user_id", "name"]
50
  all_users = pd.DataFrame(get_all_users(columns_included=columns), columns=columns)
 
88
  def get_player_html_str(player_opt: PlayerOption, player_stats: dict[str, float], score: float) -> str:
89
  # TODO
90
  multiplier = 1
91
+
92
+ game_map = get_schedule_with_live().get(player_opt.week, {}).get(player_opt.team, {})
93
  game_status = " "
94
+ game_score = f"""{game_map.get("score")} - {game_map.get("opponent_score")}"""
95
  player_stats_str = get_player_stats_html_str(player_stats)
96
 
97
  player_classes = "player"
src/queries/pfr/league_schedule.py CHANGED
@@ -1,6 +1,7 @@
1
  import pandas as pd
2
 
3
  from domain.playoffs import SCHEDULE_WEEK_TO_PLAYOFF_WEEK
 
4
 
5
 
6
  def get_full_schedule(season_int: str | int) -> pd.DataFrame:
@@ -31,8 +32,8 @@ def get_season_game_map(
31
  last_game_week_map[mapped_week] = max(game_time, last_game_week_map[mapped_week])
32
 
33
  # only actual winner/loser if game has already happened
34
- winner_team = row["Winner/tie"]
35
- loser_team = row["Loser/tie"]
36
  winner_game = {
37
  "gametime": game_time,
38
  "opponent": loser_team,
 
1
  import pandas as pd
2
 
3
  from domain.playoffs import SCHEDULE_WEEK_TO_PLAYOFF_WEEK
4
+ from domain.teams import PFR_NAME_TO_SCHEDULE_NAME_MAP
5
 
6
 
7
  def get_full_schedule(season_int: str | int) -> pd.DataFrame:
 
32
  last_game_week_map[mapped_week] = max(game_time, last_game_week_map[mapped_week])
33
 
34
  # only actual winner/loser if game has already happened
35
+ winner_team = PFR_NAME_TO_SCHEDULE_NAME_MAP[row["Winner/tie"]]
36
+ loser_team = PFR_NAME_TO_SCHEDULE_NAME_MAP[row["Loser/tie"]]
37
  winner_game = {
38
  "gametime": game_time,
39
  "opponent": loser_team,