Jon Solow
commited on
Commit
·
4393241
1
Parent(s):
e310fd9
Implement game time in options
Browse files
src/pages/10_Set_Your_Lineup.py
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
from dataclasses import dataclass
|
|
|
2 |
import streamlit as st
|
3 |
|
4 |
from config import DEFAULT_ICON
|
5 |
from shared_page import common_page_config
|
6 |
|
|
|
|
|
|
|
7 |
from queries.nflverse.github_data import get_weekly_rosters
|
|
|
8 |
from login import check_password, get_user_team, save_user_team
|
9 |
-
from domain.playoffs import PLAYOFF_WEEK_TO_NAME, CURRENT_PLAYOFF_WEEK
|
10 |
|
11 |
|
12 |
@dataclass
|
@@ -16,6 +20,7 @@ class PlayerOption:
|
|
16 |
headshot_url: str
|
17 |
position: str
|
18 |
team: str
|
|
|
19 |
|
20 |
@classmethod
|
21 |
def from_series(cls, input_series):
|
@@ -25,6 +30,7 @@ class PlayerOption:
|
|
25 |
headshot_url=input_series.headshot_url,
|
26 |
position=input_series.position,
|
27 |
team=input_series.team,
|
|
|
28 |
)
|
29 |
|
30 |
@classmethod
|
@@ -35,6 +41,7 @@ class PlayerOption:
|
|
35 |
headshot_url="",
|
36 |
position="",
|
37 |
team="",
|
|
|
38 |
)
|
39 |
|
40 |
|
@@ -51,9 +58,20 @@ def load_options():
|
|
51 |
# filter active only
|
52 |
df_rosters = get_weekly_rosters()
|
53 |
df_rosters = df_rosters[df_rosters.status == "ACT"]
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# select latest
|
55 |
sort_by_cols = ["position", "week", "fantasy_points"]
|
56 |
df_rosters = df_rosters.sort_values(sort_by_cols, ascending=False).drop_duplicates(subset="gsis_id")
|
|
|
|
|
|
|
|
|
|
|
57 |
qb_options = player_options_from_df(df_rosters, "QB")
|
58 |
wr_options = player_options_from_df(df_rosters, "WR")
|
59 |
rb_options = player_options_from_df(df_rosters, "RB")
|
|
|
1 |
from dataclasses import dataclass
|
2 |
+
import pandas as pd
|
3 |
import streamlit as st
|
4 |
|
5 |
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, PLAYOFF_WEEK_TO_SCHEDULE_WEEK
|
10 |
+
from domain.teams import SCHEDULE_NAME_TO_PFR_NAME_MAP
|
11 |
from queries.nflverse.github_data import get_weekly_rosters
|
12 |
+
from queries.pfr.league_schedule import get_season_time_map
|
13 |
from login import check_password, get_user_team, save_user_team
|
|
|
14 |
|
15 |
|
16 |
@dataclass
|
|
|
20 |
headshot_url: str
|
21 |
position: str
|
22 |
team: str
|
23 |
+
gametime: pd.Timestamp | None
|
24 |
|
25 |
@classmethod
|
26 |
def from_series(cls, input_series):
|
|
|
30 |
headshot_url=input_series.headshot_url,
|
31 |
position=input_series.position,
|
32 |
team=input_series.team,
|
33 |
+
gametime=input_series.gametime,
|
34 |
)
|
35 |
|
36 |
@classmethod
|
|
|
41 |
headshot_url="",
|
42 |
position="",
|
43 |
team="",
|
44 |
+
gametime=None,
|
45 |
)
|
46 |
|
47 |
|
|
|
58 |
# filter active only
|
59 |
df_rosters = get_weekly_rosters()
|
60 |
df_rosters = df_rosters[df_rosters.status == "ACT"]
|
61 |
+
|
62 |
+
# get current week games
|
63 |
+
schedule_week = PLAYOFF_WEEK_TO_SCHEDULE_WEEK[CURRENT_PLAYOFF_WEEK]
|
64 |
+
current_week_game_times = get_season_time_map(SEASON)[schedule_week]
|
65 |
+
latest_game_time = max(current_week_game_times.values())
|
66 |
+
|
67 |
# select latest
|
68 |
sort_by_cols = ["position", "week", "fantasy_points"]
|
69 |
df_rosters = df_rosters.sort_values(sort_by_cols, ascending=False).drop_duplicates(subset="gsis_id")
|
70 |
+
# set gametime
|
71 |
+
df_rosters["gametime"] = df_rosters.apply(
|
72 |
+
lambda x: current_week_game_times.get(SCHEDULE_NAME_TO_PFR_NAME_MAP[x.team], latest_game_time), axis=1
|
73 |
+
)
|
74 |
+
|
75 |
qb_options = player_options_from_df(df_rosters, "QB")
|
76 |
wr_options = player_options_from_df(df_rosters, "WR")
|
77 |
rb_options = player_options_from_df(df_rosters, "RB")
|