Jon Solow
commited on
Commit
·
255e3c4
1
Parent(s):
bb8973a
Refactor position_cell to only allow current week edits
Browse files- src/pages/10_Set_Your_Lineup.py +28 -20
src/pages/10_Set_Your_Lineup.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
-
import numpy as np
|
3 |
import streamlit as st
|
4 |
|
5 |
from config import DEFAULT_ICON
|
@@ -7,7 +6,7 @@ from shared_page import common_page_config
|
|
7 |
|
8 |
from queries.nflverse.github_data import get_weekly_rosters
|
9 |
from login import check_password, get_user_team, save_user_team
|
10 |
-
from domain.playoffs import PLAYOFF_WEEK_TO_NAME
|
11 |
|
12 |
|
13 |
@dataclass
|
@@ -73,23 +72,33 @@ def display_player(player_opt: PlayerOption | None):
|
|
73 |
st.image(player_opt.headshot_url, caption=player_opt.full_name)
|
74 |
|
75 |
|
76 |
-
def position_cell(
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
else:
|
|
|
|
|
|
|
|
|
83 |
selected_option_idx = 0
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
selected_player_from_box = st.selectbox(
|
86 |
pos_label,
|
87 |
-
options=
|
88 |
format_func=format_player_option,
|
89 |
index=selected_option_idx,
|
90 |
)
|
91 |
-
if selected_player_from_box:
|
92 |
-
if selected_player_from_box.gsis_id and selected_player_from_box.gsis_id !=
|
93 |
update_and_save_selection(pos_label, selected_player_from_box.gsis_id, existing_selection_map),
|
94 |
display_player(selected_player_from_box)
|
95 |
|
@@ -109,7 +118,6 @@ def get_page():
|
|
109 |
st.stop()
|
110 |
|
111 |
existing_selections = get_user_team()
|
112 |
-
st.write(get_user_team())
|
113 |
|
114 |
qb_options, wr_options, rb_options, te_options, k_options = load_options()
|
115 |
|
@@ -118,21 +126,21 @@ def get_page():
|
|
118 |
selection_cols = st.columns(8)
|
119 |
|
120 |
with selection_cols[0]:
|
121 |
-
position_cell(
|
122 |
with selection_cols[1]:
|
123 |
-
position_cell(
|
124 |
with selection_cols[2]:
|
125 |
-
position_cell(
|
126 |
with selection_cols[3]:
|
127 |
-
position_cell(
|
128 |
with selection_cols[4]:
|
129 |
-
position_cell(
|
130 |
with selection_cols[5]:
|
131 |
-
position_cell(
|
132 |
with selection_cols[6]:
|
133 |
-
position_cell(
|
134 |
with selection_cols[7]:
|
135 |
-
position_cell(
|
136 |
|
137 |
|
138 |
if __name__ == "__main__":
|
|
|
1 |
from dataclasses import dataclass
|
|
|
2 |
import streamlit as st
|
3 |
|
4 |
from config import DEFAULT_ICON
|
|
|
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
|
|
|
72 |
st.image(player_opt.headshot_url, caption=player_opt.full_name)
|
73 |
|
74 |
|
75 |
+
def position_cell(week: str, pos_str: str, options_list: list[PlayerOption], existing_selection_map):
|
76 |
+
pos_label = f"{week}-{pos_str}"
|
77 |
+
selected_id = existing_selection_map.get(pos_label)
|
78 |
+
if isinstance(selected_id, str):
|
79 |
+
selected_option_idx, selected_player = next(
|
80 |
+
(i, v) for i, v in enumerate(options_list) if str(selected_id) == str(v.gsis_id)
|
81 |
+
)
|
82 |
else:
|
83 |
+
selected_player = PlayerOption.empty_player()
|
84 |
+
selected_option_idx = 0
|
85 |
+
if int(week) > CURRENT_PLAYOFF_WEEK:
|
86 |
+
options = []
|
87 |
selected_option_idx = 0
|
88 |
+
elif int(week) < CURRENT_PLAYOFF_WEEK:
|
89 |
+
options = [selected_player]
|
90 |
+
selected_option_idx = 0
|
91 |
+
else:
|
92 |
+
options = options_list
|
93 |
|
94 |
selected_player_from_box = st.selectbox(
|
95 |
pos_label,
|
96 |
+
options=options,
|
97 |
format_func=format_player_option,
|
98 |
index=selected_option_idx,
|
99 |
)
|
100 |
+
if selected_player_from_box and int(week) == CURRENT_PLAYOFF_WEEK:
|
101 |
+
if selected_player_from_box.gsis_id and selected_player_from_box.gsis_id != selected_id:
|
102 |
update_and_save_selection(pos_label, selected_player_from_box.gsis_id, existing_selection_map),
|
103 |
display_player(selected_player_from_box)
|
104 |
|
|
|
118 |
st.stop()
|
119 |
|
120 |
existing_selections = get_user_team()
|
|
|
121 |
|
122 |
qb_options, wr_options, rb_options, te_options, k_options = load_options()
|
123 |
|
|
|
126 |
selection_cols = st.columns(8)
|
127 |
|
128 |
with selection_cols[0]:
|
129 |
+
position_cell(week, "QB-1", qb_options, existing_selections)
|
130 |
with selection_cols[1]:
|
131 |
+
position_cell(week, "RB-1", rb_options, existing_selections)
|
132 |
with selection_cols[2]:
|
133 |
+
position_cell(week, "RB-2", rb_options, existing_selections)
|
134 |
with selection_cols[3]:
|
135 |
+
position_cell(week, "WR-1", wr_options, existing_selections)
|
136 |
with selection_cols[4]:
|
137 |
+
position_cell(week, "WR-2", wr_options, existing_selections)
|
138 |
with selection_cols[5]:
|
139 |
+
position_cell(week, "TE-1", te_options, existing_selections)
|
140 |
with selection_cols[6]:
|
141 |
+
position_cell(week, "K-1", k_options, existing_selections)
|
142 |
with selection_cols[7]:
|
143 |
+
position_cell(week, "DEF-1", [], existing_selections)
|
144 |
|
145 |
|
146 |
if __name__ == "__main__":
|