Jon Solow
commited on
Commit
·
4f0d0c7
1
Parent(s):
62740e0
Fix latest game of week mapping logic
Browse files
src/pages/10_Set_Your_Lineup.py
CHANGED
@@ -6,7 +6,7 @@ from config import DEFAULT_ICON
|
|
6 |
from shared_page import common_page_config
|
7 |
|
8 |
from domain.constants import SEASON
|
9 |
-
from domain.playoffs import PLAYOFF_WEEK_TO_NAME, CURRENT_PLAYOFF_WEEK,
|
10 |
from domain.teams import SCHEDULE_NAME_TO_PFR_NAME_MAP, PLAYOFFS_TEAMS
|
11 |
from queries.nflverse.github_data import get_weekly_rosters
|
12 |
from queries.pfr.league_schedule import get_season_time_map
|
@@ -59,29 +59,28 @@ def player_options_from_df(df_options) -> dict[str, dict[int, list[PlayerOption]
|
|
59 |
options_map = initialize_empty_options_map()
|
60 |
for pos, pos_week_map in options_map.items():
|
61 |
for week in pos_week_map.keys():
|
62 |
-
df_pos_week = df_options[
|
63 |
-
((df_options.week.map(SCHEDULE_WEEK_TO_PLAYOFF_WEEK) == week) & (df_options.position == pos))
|
64 |
-
]
|
65 |
if len(df_pos_week) > 0:
|
66 |
player_options_list = df_pos_week.apply(PlayerOption.from_series, axis=1).tolist()
|
67 |
options_map[pos][int(week)].extend(player_options_list)
|
68 |
return options_map
|
69 |
|
70 |
|
71 |
-
@st.cache_data(ttl=60 * 60 * 24)
|
72 |
def load_options():
|
73 |
df_rosters = get_weekly_rosters()
|
74 |
|
75 |
# get game schedules
|
76 |
week_game_times = get_season_time_map(SEASON)
|
77 |
-
latest_game_time_defaults = {k: max(v) for k, v in week_game_times.items() if v}
|
78 |
|
79 |
# sort
|
80 |
sort_by_cols = ["position", "week", "fantasy_points"]
|
81 |
df_rosters.sort_values(sort_by_cols, ascending=False, inplace=True)
|
82 |
|
83 |
# filter data from non-playoffs
|
84 |
-
df_rosters = df_rosters[df_rosters.week.isin(
|
|
|
85 |
# set gametime
|
86 |
if len(df_rosters) == 0:
|
87 |
return initialize_empty_options_map()
|
@@ -92,9 +91,7 @@ def load_options():
|
|
92 |
axis=1,
|
93 |
)
|
94 |
|
95 |
-
df_rosters["in_playoffs"] = df_rosters.apply(
|
96 |
-
lambda x: x.team in PLAYOFFS_TEAMS[SCHEDULE_WEEK_TO_PLAYOFF_WEEK[x.week]], axis=1
|
97 |
-
)
|
98 |
|
99 |
df_rosters = df_rosters[df_rosters.in_playoffs]
|
100 |
player_options = player_options_from_df(df_rosters)
|
|
|
6 |
from shared_page import common_page_config
|
7 |
|
8 |
from domain.constants import SEASON
|
9 |
+
from domain.playoffs import PLAYOFF_WEEK_TO_NAME, CURRENT_PLAYOFF_WEEK, ROSTER_WEEK_TO_PLAYOFF_WEEK
|
10 |
from domain.teams import SCHEDULE_NAME_TO_PFR_NAME_MAP, PLAYOFFS_TEAMS
|
11 |
from queries.nflverse.github_data import get_weekly_rosters
|
12 |
from queries.pfr.league_schedule import get_season_time_map
|
|
|
59 |
options_map = initialize_empty_options_map()
|
60 |
for pos, pos_week_map in options_map.items():
|
61 |
for week in pos_week_map.keys():
|
62 |
+
df_pos_week = df_options[((df_options.week == week) & (df_options.position == pos))]
|
|
|
|
|
63 |
if len(df_pos_week) > 0:
|
64 |
player_options_list = df_pos_week.apply(PlayerOption.from_series, axis=1).tolist()
|
65 |
options_map[pos][int(week)].extend(player_options_list)
|
66 |
return options_map
|
67 |
|
68 |
|
69 |
+
# @st.cache_data(ttl=60 * 60 * 24)
|
70 |
def load_options():
|
71 |
df_rosters = get_weekly_rosters()
|
72 |
|
73 |
# get game schedules
|
74 |
week_game_times = get_season_time_map(SEASON)
|
75 |
+
latest_game_time_defaults = {k: max(v.values()) for k, v in week_game_times.items() if v}
|
76 |
|
77 |
# sort
|
78 |
sort_by_cols = ["position", "week", "fantasy_points"]
|
79 |
df_rosters.sort_values(sort_by_cols, ascending=False, inplace=True)
|
80 |
|
81 |
# filter data from non-playoffs
|
82 |
+
df_rosters = df_rosters[df_rosters.week.isin(ROSTER_WEEK_TO_PLAYOFF_WEEK.keys())]
|
83 |
+
df_rosters["week"] = df_rosters["week"].map(ROSTER_WEEK_TO_PLAYOFF_WEEK)
|
84 |
# set gametime
|
85 |
if len(df_rosters) == 0:
|
86 |
return initialize_empty_options_map()
|
|
|
91 |
axis=1,
|
92 |
)
|
93 |
|
94 |
+
df_rosters["in_playoffs"] = df_rosters.apply(lambda x: x.team in PLAYOFFS_TEAMS[x.week], axis=1)
|
|
|
|
|
95 |
|
96 |
df_rosters = df_rosters[df_rosters.in_playoffs]
|
97 |
player_options = player_options_from_df(df_rosters)
|