Spaces:
Sleeping
Sleeping
Jon Solow
commited on
Commit
·
3b6a23b
1
Parent(s):
1cc116e
Load time slots based on separate sheet
Browse files
src/maximum_roster_strategy/data_loader.py
CHANGED
@@ -6,6 +6,14 @@ MRS_SHEET_ID = os.environ.get("MRS_SHEET_ID")
|
|
6 |
|
7 |
|
8 |
def get_google_sheet_data() -> pd.DataFrame:
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
df = pd.read_csv(sheet_url)
|
11 |
return df
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
def get_google_sheet_data() -> pd.DataFrame:
|
9 |
+
return get_sheet_data(0)
|
10 |
+
|
11 |
+
|
12 |
+
def get_sheet_data(sheet_id: int = 0):
|
13 |
+
sheet_url = f"https://docs.google.com/spreadsheet/ccc?key={MRS_SHEET_ID}&output=csv&gid={sheet_id}"
|
14 |
df = pd.read_csv(sheet_url)
|
15 |
return df
|
16 |
+
|
17 |
+
|
18 |
+
def get_timeslot_labels() -> pd.DataFrame:
|
19 |
+
return get_sheet_data(1875906423)
|
src/pages/80_Maximum_Roster_Strategy.py
CHANGED
@@ -24,9 +24,9 @@ POSITION_ABBR_FULL_NAME_MAP = {
|
|
24 |
}
|
25 |
|
26 |
|
27 |
-
@st.cache_data(ttl=60 * 60
|
28 |
def load_data():
|
29 |
-
return data_loader.get_google_sheet_data()
|
30 |
|
31 |
|
32 |
def get_player_grid_div(player_series: pd.Series) -> str:
|
@@ -73,11 +73,10 @@ def get_player_container(df_players: pd.DataFrame, slot_number: int | str) -> st
|
|
73 |
return f"""<div class="playerslot{slot_number} playerslot">{player_code_str}</div>"""
|
74 |
|
75 |
|
76 |
-
def get_position_breakdown(df: pd.DataFrame, position_abbr: str, position_full_str: str):
|
77 |
with st.container():
|
78 |
st.header(position_full_str)
|
79 |
df_pos = df[df["Position"] == position_abbr]
|
80 |
-
time_slots = df.sort_values("WeekTimeSlotIndex")["TimeSlotName"].unique().tolist()
|
81 |
|
82 |
grid_code_str = ""
|
83 |
grid_code_str += get_time_slot_div(time_slots)
|
@@ -113,10 +112,13 @@ def get_page():
|
|
113 |
position = st.selectbox(label="Position", options=POSITION_OPTIONS, index=0)
|
114 |
with week_select:
|
115 |
week = st.selectbox(label="Week", options=list(range(MAXIMUM_WEEK, MINIMUM_WEEK - 1, -1)), index=0)
|
116 |
-
df_mrs = load_data()
|
117 |
df_mrs = df_mrs[df_mrs["Week"] == week]
|
|
|
|
|
|
|
118 |
|
119 |
-
get_position_breakdown(df_mrs, position, POSITION_ABBR_FULL_NAME_MAP[position])
|
120 |
|
121 |
|
122 |
if __name__ == "__main__":
|
|
|
24 |
}
|
25 |
|
26 |
|
27 |
+
@st.cache_data(ttl=60 * 60)
|
28 |
def load_data():
|
29 |
+
return data_loader.get_google_sheet_data(), data_loader.get_timeslot_labels()
|
30 |
|
31 |
|
32 |
def get_player_grid_div(player_series: pd.Series) -> str:
|
|
|
73 |
return f"""<div class="playerslot{slot_number} playerslot">{player_code_str}</div>"""
|
74 |
|
75 |
|
76 |
+
def get_position_breakdown(df: pd.DataFrame, position_abbr: str, position_full_str: str, time_slots: list[str]):
|
77 |
with st.container():
|
78 |
st.header(position_full_str)
|
79 |
df_pos = df[df["Position"] == position_abbr]
|
|
|
80 |
|
81 |
grid_code_str = ""
|
82 |
grid_code_str += get_time_slot_div(time_slots)
|
|
|
112 |
position = st.selectbox(label="Position", options=POSITION_OPTIONS, index=0)
|
113 |
with week_select:
|
114 |
week = st.selectbox(label="Week", options=list(range(MAXIMUM_WEEK, MINIMUM_WEEK - 1, -1)), index=0)
|
115 |
+
df_mrs, all_time_slots_df = load_data()
|
116 |
df_mrs = df_mrs[df_mrs["Week"] == week]
|
117 |
+
current_week_timeslots = (
|
118 |
+
all_time_slots_df[all_time_slots_df["Week"] == week].sort_values("WeekTimeSlotIndex").TimeSlotName.tolist()
|
119 |
+
)
|
120 |
|
121 |
+
get_position_breakdown(df_mrs, position, POSITION_ABBR_FULL_NAME_MAP[position], current_week_timeslots)
|
122 |
|
123 |
|
124 |
if __name__ == "__main__":
|