Spaces:
Running
Running
James McCool
commited on
Commit
·
c2689e4
1
Parent(s):
a33b237
Refactor app.py to standardize variable names for site and view selections across all tabs, ensuring consistent data handling and improving user experience with clearer input options.
Browse files
app.py
CHANGED
@@ -121,17 +121,18 @@ def convert_df(array):
|
|
121 |
roo_data, sd_roo_data, scoring_percentages = init_baselines()
|
122 |
hold_display = roo_data
|
123 |
|
124 |
-
with st.container():
|
125 |
-
col1, col2 = st.columns([3, 3])
|
126 |
-
with col1:
|
127 |
-
view_var = st.selectbox("Select view", ["Simple", "Advanced"])
|
128 |
-
with col2:
|
129 |
-
site_var = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'))
|
130 |
-
|
131 |
tab1, tab2, tab3 = st.tabs(["Scoring Percentages", "Player ROO", "Optimals"])
|
132 |
|
133 |
with tab1:
|
134 |
st.header("Scoring Percentages")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
with st.expander("Info and Filters"):
|
136 |
col1, col2, col3 = st.columns([3, 3, 3])
|
137 |
with col1:
|
@@ -148,14 +149,22 @@ with tab1:
|
|
148 |
with col3:
|
149 |
own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'))
|
150 |
st.title("Scoring Percentages")
|
151 |
-
if
|
152 |
scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
|
153 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
154 |
-
elif
|
155 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
156 |
|
157 |
with tab2:
|
158 |
st.header("Player ROO")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
with st.expander("Info and Filters"):
|
160 |
col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
|
161 |
with col1:
|
@@ -176,7 +185,7 @@ with tab2:
|
|
176 |
|
177 |
if slate_type_var2 == 'Regular':
|
178 |
player_roo_raw = roo_data.copy()
|
179 |
-
if
|
180 |
player_roo_raw['Site'] = 'Draftkings'
|
181 |
|
182 |
if pos_var2 == 'All':
|
@@ -185,7 +194,7 @@ with tab2:
|
|
185 |
player_roo_raw = player_roo_raw[player_roo_raw['Position'] == 'SP']
|
186 |
elif pos_var2 == 'Hitters':
|
187 |
player_roo_raw = player_roo_raw[player_roo_raw['Position'] != 'SP']
|
188 |
-
elif
|
189 |
player_roo_raw['Site'] = 'Fanduel'
|
190 |
|
191 |
if pos_var2 == 'All':
|
@@ -204,19 +213,27 @@ with tab2:
|
|
204 |
|
205 |
elif slate_type_var2 == 'Showdown':
|
206 |
player_roo_raw = sd_roo_data.copy()
|
207 |
-
if
|
208 |
player_roo_raw['Site'] = 'Draftkings'
|
209 |
-
elif
|
210 |
player_roo_raw['Site'] = 'Fanduel'
|
211 |
st.session_state['player_roo'] = player_roo_raw.drop(columns=['site', 'slate', 'version', 'timestamp'])
|
212 |
-
if
|
213 |
st.session_state['player_roo'] = st.session_state['player_roo'][['Player', 'Position', 'Salary', 'Median', 'Ceiling', 'Own']]
|
214 |
st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
215 |
-
elif
|
216 |
st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
217 |
|
218 |
with tab3:
|
219 |
st.header("Optimals")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
with st.expander("Info and Filters"):
|
221 |
if st.button("Load/Reset Data", key='reset3'):
|
222 |
st.cache_data.clear()
|
@@ -231,14 +248,14 @@ with tab3:
|
|
231 |
slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'))
|
232 |
|
233 |
if slate_type_var3 == 'Regular':
|
234 |
-
if
|
235 |
dk_lineups = init_DK_lineups(slate_var3)
|
236 |
-
elif
|
237 |
fd_lineups = init_FD_lineups(slate_var3)
|
238 |
elif slate_type_var3 == 'Showdown':
|
239 |
-
if
|
240 |
dk_lineups = init_DK_lineups(slate_var3)
|
241 |
-
elif
|
242 |
fd_lineups = init_FD_lineups(slate_var3)
|
243 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1)
|
244 |
|
@@ -247,7 +264,7 @@ with tab3:
|
|
247 |
elif slate_type_var3 == 'Showdown':
|
248 |
raw_baselines = sd_roo_data
|
249 |
|
250 |
-
if
|
251 |
if slate_type_var3 == 'Regular':
|
252 |
ROO_slice = raw_baselines[raw_baselines['Site'] == 'Draftkings']
|
253 |
player_salaries = dict(zip(ROO_slice['Player'], ROO_slice['Salary']))
|
@@ -264,7 +281,7 @@ with tab3:
|
|
264 |
elif player_var1 == 'Full Slate':
|
265 |
player_var2 = raw_baselines.Player.values.tolist()
|
266 |
|
267 |
-
elif
|
268 |
raw_baselines = hold_display
|
269 |
if slate_type_var3 == 'Regular':
|
270 |
ROO_slice = raw_baselines[raw_baselines['Site'] == 'Fanduel']
|
@@ -283,10 +300,10 @@ with tab3:
|
|
283 |
|
284 |
if st.button("Prepare data export", key='data_export'):
|
285 |
data_export = st.session_state.working_seed.copy()
|
286 |
-
# if
|
287 |
# for col_idx in range(6):
|
288 |
# data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
289 |
-
# elif
|
290 |
# for col_idx in range(6):
|
291 |
# data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
292 |
st.download_button(
|
@@ -296,7 +313,7 @@ with tab3:
|
|
296 |
mime='text/csv',
|
297 |
)
|
298 |
|
299 |
-
if
|
300 |
if 'working_seed' in st.session_state:
|
301 |
st.session_state.working_seed = st.session_state.working_seed
|
302 |
if player_var1 == 'Specific Players':
|
@@ -313,7 +330,7 @@ with tab3:
|
|
313 |
st.session_state.working_seed = dk_lineups.copy()
|
314 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
315 |
|
316 |
-
elif
|
317 |
if 'working_seed' in st.session_state:
|
318 |
st.session_state.working_seed = st.session_state.working_seed
|
319 |
if player_var1 == 'Specific Players':
|
@@ -331,10 +348,10 @@ with tab3:
|
|
331 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
332 |
|
333 |
export_file = st.session_state.data_export_display.copy()
|
334 |
-
# if
|
335 |
# for col_idx in range(6):
|
336 |
# export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
337 |
-
# elif
|
338 |
# for col_idx in range(6):
|
339 |
# export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
340 |
|
@@ -342,9 +359,9 @@ with tab3:
|
|
342 |
if st.button("Reset Optimals", key='reset3'):
|
343 |
for key in st.session_state.keys():
|
344 |
del st.session_state[key]
|
345 |
-
if
|
346 |
st.session_state.working_seed = dk_lineups.copy()
|
347 |
-
elif
|
348 |
st.session_state.working_seed = fd_lineups.copy()
|
349 |
if 'data_export_display' in st.session_state:
|
350 |
st.dataframe(st.session_state.data_export_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=500, use_container_width = True)
|
@@ -358,7 +375,7 @@ with tab3:
|
|
358 |
with st.container():
|
359 |
if 'working_seed' in st.session_state:
|
360 |
# Create a new dataframe with summary statistics
|
361 |
-
if
|
362 |
summary_df = pd.DataFrame({
|
363 |
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
364 |
'Salary': [
|
@@ -380,7 +397,7 @@ with tab3:
|
|
380 |
np.std(st.session_state.working_seed[:,8])
|
381 |
]
|
382 |
})
|
383 |
-
elif
|
384 |
summary_df = pd.DataFrame({
|
385 |
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
386 |
'Salary': [
|
@@ -418,9 +435,9 @@ with tab3:
|
|
418 |
tab1, tab2 = st.tabs(["Display Frequency", "Seed Frame Frequency"])
|
419 |
with tab1:
|
420 |
if 'data_export_display' in st.session_state:
|
421 |
-
if
|
422 |
player_columns = st.session_state.data_export_display.iloc[:, :6]
|
423 |
-
elif
|
424 |
player_columns = st.session_state.data_export_display.iloc[:, :6]
|
425 |
|
426 |
# Flatten the DataFrame and count unique values
|
@@ -454,9 +471,9 @@ with tab3:
|
|
454 |
)
|
455 |
with tab2:
|
456 |
if 'working_seed' in st.session_state:
|
457 |
-
if
|
458 |
player_columns = st.session_state.working_seed[:, :6]
|
459 |
-
elif
|
460 |
player_columns = st.session_state.working_seed[:, :6]
|
461 |
|
462 |
# Flatten the DataFrame and count unique values
|
|
|
121 |
roo_data, sd_roo_data, scoring_percentages = init_baselines()
|
122 |
hold_display = roo_data
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
tab1, tab2, tab3 = st.tabs(["Scoring Percentages", "Player ROO", "Optimals"])
|
125 |
|
126 |
with tab1:
|
127 |
st.header("Scoring Percentages")
|
128 |
+
|
129 |
+
with st.container():
|
130 |
+
col1, col2 = st.columns([3, 3])
|
131 |
+
with col1:
|
132 |
+
view_var1 = st.selectbox("Select view", ["Simple", "Advanced"])
|
133 |
+
with col2:
|
134 |
+
site_var1 = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'))
|
135 |
+
|
136 |
with st.expander("Info and Filters"):
|
137 |
col1, col2, col3 = st.columns([3, 3, 3])
|
138 |
with col1:
|
|
|
149 |
with col3:
|
150 |
own_var1 = st.radio("How would you like to display team ownership?", ('Sum', 'Average'))
|
151 |
st.title("Scoring Percentages")
|
152 |
+
if view_var1 == "Simple":
|
153 |
scoring_percentages = scoring_percentages[['Names', 'Avg Score', '8+ runs', 'Win Percentage']]
|
154 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
155 |
+
elif view_var1 == "Advanced":
|
156 |
st.dataframe(scoring_percentages.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
157 |
|
158 |
with tab2:
|
159 |
st.header("Player ROO")
|
160 |
+
|
161 |
+
with st.container():
|
162 |
+
col1, col2 = st.columns([3, 3])
|
163 |
+
with col1:
|
164 |
+
view_var2 = st.selectbox("Select view", ["Simple", "Advanced"])
|
165 |
+
with col2:
|
166 |
+
site_var2 = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'))
|
167 |
+
|
168 |
with st.expander("Info and Filters"):
|
169 |
col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
|
170 |
with col1:
|
|
|
185 |
|
186 |
if slate_type_var2 == 'Regular':
|
187 |
player_roo_raw = roo_data.copy()
|
188 |
+
if site_var2 == 'Draftkings':
|
189 |
player_roo_raw['Site'] = 'Draftkings'
|
190 |
|
191 |
if pos_var2 == 'All':
|
|
|
194 |
player_roo_raw = player_roo_raw[player_roo_raw['Position'] == 'SP']
|
195 |
elif pos_var2 == 'Hitters':
|
196 |
player_roo_raw = player_roo_raw[player_roo_raw['Position'] != 'SP']
|
197 |
+
elif site_var2 == 'Fanduel':
|
198 |
player_roo_raw['Site'] = 'Fanduel'
|
199 |
|
200 |
if pos_var2 == 'All':
|
|
|
213 |
|
214 |
elif slate_type_var2 == 'Showdown':
|
215 |
player_roo_raw = sd_roo_data.copy()
|
216 |
+
if site_var2 == 'Draftkings':
|
217 |
player_roo_raw['Site'] = 'Draftkings'
|
218 |
+
elif site_var2 == 'Fanduel':
|
219 |
player_roo_raw['Site'] = 'Fanduel'
|
220 |
st.session_state['player_roo'] = player_roo_raw.drop(columns=['site', 'slate', 'version', 'timestamp'])
|
221 |
+
if view_var2 == "Simple":
|
222 |
st.session_state['player_roo'] = st.session_state['player_roo'][['Player', 'Position', 'Salary', 'Median', 'Ceiling', 'Own']]
|
223 |
st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
224 |
+
elif view_var2 == "Advanced":
|
225 |
st.dataframe(st.session_state['player_roo'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), height=750, use_container_width = True, hide_index=True)
|
226 |
|
227 |
with tab3:
|
228 |
st.header("Optimals")
|
229 |
+
|
230 |
+
with st.container():
|
231 |
+
col1, col2 = st.columns([3, 3])
|
232 |
+
with col1:
|
233 |
+
site_var3 = st.selectbox("What site do you want to view?", ('Draftkings', 'Fanduel'))
|
234 |
+
with col2:
|
235 |
+
view_var3 = st.selectbox("Select view", ["Simple", "Advanced"])
|
236 |
+
|
237 |
with st.expander("Info and Filters"):
|
238 |
if st.button("Load/Reset Data", key='reset3'):
|
239 |
st.cache_data.clear()
|
|
|
248 |
slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'))
|
249 |
|
250 |
if slate_type_var3 == 'Regular':
|
251 |
+
if site_var3 == 'Draftkings':
|
252 |
dk_lineups = init_DK_lineups(slate_var3)
|
253 |
+
elif site_var3 == 'Fanduel':
|
254 |
fd_lineups = init_FD_lineups(slate_var3)
|
255 |
elif slate_type_var3 == 'Showdown':
|
256 |
+
if site_var3 == 'Draftkings':
|
257 |
dk_lineups = init_DK_lineups(slate_var3)
|
258 |
+
elif site_var3 == 'Fanduel':
|
259 |
fd_lineups = init_FD_lineups(slate_var3)
|
260 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1)
|
261 |
|
|
|
264 |
elif slate_type_var3 == 'Showdown':
|
265 |
raw_baselines = sd_roo_data
|
266 |
|
267 |
+
if site_var3 == 'Draftkings':
|
268 |
if slate_type_var3 == 'Regular':
|
269 |
ROO_slice = raw_baselines[raw_baselines['Site'] == 'Draftkings']
|
270 |
player_salaries = dict(zip(ROO_slice['Player'], ROO_slice['Salary']))
|
|
|
281 |
elif player_var1 == 'Full Slate':
|
282 |
player_var2 = raw_baselines.Player.values.tolist()
|
283 |
|
284 |
+
elif site_var3 == 'Fanduel':
|
285 |
raw_baselines = hold_display
|
286 |
if slate_type_var3 == 'Regular':
|
287 |
ROO_slice = raw_baselines[raw_baselines['Site'] == 'Fanduel']
|
|
|
300 |
|
301 |
if st.button("Prepare data export", key='data_export'):
|
302 |
data_export = st.session_state.working_seed.copy()
|
303 |
+
# if site_var3 == 'Draftkings':
|
304 |
# for col_idx in range(6):
|
305 |
# data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
306 |
+
# elif site_var3 == 'Fanduel':
|
307 |
# for col_idx in range(6):
|
308 |
# data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
309 |
st.download_button(
|
|
|
313 |
mime='text/csv',
|
314 |
)
|
315 |
|
316 |
+
if site_var3 == 'Draftkings':
|
317 |
if 'working_seed' in st.session_state:
|
318 |
st.session_state.working_seed = st.session_state.working_seed
|
319 |
if player_var1 == 'Specific Players':
|
|
|
330 |
st.session_state.working_seed = dk_lineups.copy()
|
331 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
332 |
|
333 |
+
elif site_var3 == 'Fanduel':
|
334 |
if 'working_seed' in st.session_state:
|
335 |
st.session_state.working_seed = st.session_state.working_seed
|
336 |
if player_var1 == 'Specific Players':
|
|
|
348 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
349 |
|
350 |
export_file = st.session_state.data_export_display.copy()
|
351 |
+
# if site_var3 == 'Draftkings':
|
352 |
# for col_idx in range(6):
|
353 |
# export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
354 |
+
# elif site_var3 == 'Fanduel':
|
355 |
# for col_idx in range(6):
|
356 |
# export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
357 |
|
|
|
359 |
if st.button("Reset Optimals", key='reset3'):
|
360 |
for key in st.session_state.keys():
|
361 |
del st.session_state[key]
|
362 |
+
if site_var3 == 'Draftkings':
|
363 |
st.session_state.working_seed = dk_lineups.copy()
|
364 |
+
elif site_var3 == 'Fanduel':
|
365 |
st.session_state.working_seed = fd_lineups.copy()
|
366 |
if 'data_export_display' in st.session_state:
|
367 |
st.dataframe(st.session_state.data_export_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=500, use_container_width = True)
|
|
|
375 |
with st.container():
|
376 |
if 'working_seed' in st.session_state:
|
377 |
# Create a new dataframe with summary statistics
|
378 |
+
if site_var3 == 'Draftkings':
|
379 |
summary_df = pd.DataFrame({
|
380 |
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
381 |
'Salary': [
|
|
|
397 |
np.std(st.session_state.working_seed[:,8])
|
398 |
]
|
399 |
})
|
400 |
+
elif site_var3 == 'Fanduel':
|
401 |
summary_df = pd.DataFrame({
|
402 |
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
403 |
'Salary': [
|
|
|
435 |
tab1, tab2 = st.tabs(["Display Frequency", "Seed Frame Frequency"])
|
436 |
with tab1:
|
437 |
if 'data_export_display' in st.session_state:
|
438 |
+
if site_var3 == 'Draftkings':
|
439 |
player_columns = st.session_state.data_export_display.iloc[:, :6]
|
440 |
+
elif site_var3 == 'Fanduel':
|
441 |
player_columns = st.session_state.data_export_display.iloc[:, :6]
|
442 |
|
443 |
# Flatten the DataFrame and count unique values
|
|
|
471 |
)
|
472 |
with tab2:
|
473 |
if 'working_seed' in st.session_state:
|
474 |
+
if site_var3 == 'Draftkings':
|
475 |
player_columns = st.session_state.working_seed[:, :6]
|
476 |
+
elif site_var3 == 'Fanduel':
|
477 |
player_columns = st.session_state.working_seed[:, :6]
|
478 |
|
479 |
# Flatten the DataFrame and count unique values
|