James McCool
commited on
Commit
·
0c721eb
1
Parent(s):
aca3a9f
Refactor sport and game type handling in app.py for consistency
Browse files- Updated the code to use local variables for sport and game type selections, ensuring consistent access across different components.
- This change enhances code readability and prepares for future improvements in user interaction and data management.
app.py
CHANGED
|
@@ -185,10 +185,10 @@ if selected_tab == 'Data Load':
|
|
| 185 |
sport_options, date_options = st.columns(2)
|
| 186 |
parse_type = 'Manual'
|
| 187 |
with sport_options:
|
| 188 |
-
|
| 189 |
-
|
| 190 |
try:
|
| 191 |
-
contest_names, curr_info = grab_contest_names(db,
|
| 192 |
except:
|
| 193 |
st.error("No contests found for this sport and/or game type")
|
| 194 |
st.stop()
|
|
@@ -212,8 +212,8 @@ if selected_tab == 'Data Load':
|
|
| 212 |
del st.session_state['Contest_file']
|
| 213 |
if 'Contest_file' not in st.session_state:
|
| 214 |
if st.button('Load Contest Data', key='load_contest_data'):
|
| 215 |
-
st.session_state['player_info'], st.session_state['info_maps'] = grab_contest_player_info(db,
|
| 216 |
-
st.session_state['Contest_file'] = grab_contest_data(
|
| 217 |
else:
|
| 218 |
pass
|
| 219 |
with contest_upload:
|
|
@@ -225,7 +225,7 @@ if selected_tab == 'Data Load':
|
|
| 225 |
del st.session_state['Contest_file']
|
| 226 |
if 'Contest_file' not in st.session_state:
|
| 227 |
st.session_state['Contest_upload'] = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
| 228 |
-
st.session_state['player_info'], st.session_state['info_maps'] = grab_contest_player_info(db,
|
| 229 |
try:
|
| 230 |
st.session_state['Contest_file'] = pd.read_csv(st.session_state['Contest_upload'])
|
| 231 |
except:
|
|
@@ -261,7 +261,7 @@ if selected_tab == 'Data Load':
|
|
| 261 |
|
| 262 |
|
| 263 |
if 'Contest_file' in st.session_state:
|
| 264 |
-
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'],
|
| 265 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
| 266 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
| 267 |
if st.session_state['Contest'] is not None:
|
|
@@ -272,7 +272,7 @@ if selected_tab == 'Data Load':
|
|
| 272 |
st.warning("If you have confirmed that the data is correct, you can send the CSV to the database to enrich Paydirt's sources and help us create actionable tools and algorithms >>")
|
| 273 |
with upload_col:
|
| 274 |
if st.button('Send file to Database?', key='export_contest_file'):
|
| 275 |
-
return_message = export_contest_file(db,
|
| 276 |
with message_col:
|
| 277 |
try:
|
| 278 |
st.info(return_message)
|
|
@@ -292,8 +292,7 @@ if selected_tab == 'Data Load':
|
|
| 292 |
st.session_state['salary_dict'] = st.session_state['info_maps']['salary_dict']
|
| 293 |
st.session_state['team_dict'] = st.session_state['info_maps']['team_dict']
|
| 294 |
st.session_state['pos_dict'] = st.session_state['info_maps']['position_dict']
|
| 295 |
-
|
| 296 |
-
elif selected_tab == 'Contest Analysis':
|
| 297 |
excluded_cols = ['BaseName', 'EntryCount']
|
| 298 |
exclude_stacks = ['BaseName', 'EntryCount', 'SP', 'SP1', 'SP2', 'P1', 'P2']
|
| 299 |
if 'Contest' in st.session_state and 'display_contest_info' not in st.session_state:
|
|
@@ -467,6 +466,10 @@ elif selected_tab == 'Contest Analysis':
|
|
| 467 |
st.session_state['unique_players'] = pd.unique(st.session_state['display_contest_info'][st.session_state['player_columns']].values.ravel('K'))
|
| 468 |
st.session_state['unique_players'] = [p for p in st.session_state['unique_players'] if p != 'nan']
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
if 'display_contest_info' in st.session_state:
|
| 471 |
with st.expander("Info and filters"):
|
| 472 |
st.info("Note that any filtering here needs to be reset manually, i.e. if you parse down the specific users and want to reset the table, just backtrack your filtering by setting it back to 'All'")
|
|
|
|
| 185 |
sport_options, date_options = st.columns(2)
|
| 186 |
parse_type = 'Manual'
|
| 187 |
with sport_options:
|
| 188 |
+
sport_init = st.selectbox("Select Sport", ['MLB', 'MMA', 'GOLF', 'NBA', 'NHL', 'WNBA', 'NAS'], key='sport_select')
|
| 189 |
+
type_init = st.selectbox("Select Game Type", ['Classic', 'Showdown'], key='type_var')
|
| 190 |
try:
|
| 191 |
+
contest_names, curr_info = grab_contest_names(db, sport_init, type_init)
|
| 192 |
except:
|
| 193 |
st.error("No contests found for this sport and/or game type")
|
| 194 |
st.stop()
|
|
|
|
| 212 |
del st.session_state['Contest_file']
|
| 213 |
if 'Contest_file' not in st.session_state:
|
| 214 |
if st.button('Load Contest Data', key='load_contest_data'):
|
| 215 |
+
st.session_state['player_info'], st.session_state['info_maps'] = grab_contest_player_info(db, sport_init, type_init, date_select, contest_name_var, contest_id_map)
|
| 216 |
+
st.session_state['Contest_file'] = grab_contest_data(sport_init, contest_name_var, contest_id_map, date_select, date_select2)
|
| 217 |
else:
|
| 218 |
pass
|
| 219 |
with contest_upload:
|
|
|
|
| 225 |
del st.session_state['Contest_file']
|
| 226 |
if 'Contest_file' not in st.session_state:
|
| 227 |
st.session_state['Contest_upload'] = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
| 228 |
+
st.session_state['player_info'], st.session_state['info_maps'] = grab_contest_player_info(db, sport_init, type_init, date_select, contest_name_var, contest_id_map)
|
| 229 |
try:
|
| 230 |
st.session_state['Contest_file'] = pd.read_csv(st.session_state['Contest_upload'])
|
| 231 |
except:
|
|
|
|
| 261 |
|
| 262 |
|
| 263 |
if 'Contest_file' in st.session_state:
|
| 264 |
+
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], type_init, st.session_state['player_info'], sport_init, st.session_state['portfolio_df'])
|
| 265 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
| 266 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
| 267 |
if st.session_state['Contest'] is not None:
|
|
|
|
| 272 |
st.warning("If you have confirmed that the data is correct, you can send the CSV to the database to enrich Paydirt's sources and help us create actionable tools and algorithms >>")
|
| 273 |
with upload_col:
|
| 274 |
if st.button('Send file to Database?', key='export_contest_file'):
|
| 275 |
+
return_message = export_contest_file(db, sport_init, type_init, date_select, contest_id_map[contest_name_var], st.session_state['Contest_file'])
|
| 276 |
with message_col:
|
| 277 |
try:
|
| 278 |
st.info(return_message)
|
|
|
|
| 292 |
st.session_state['salary_dict'] = st.session_state['info_maps']['salary_dict']
|
| 293 |
st.session_state['team_dict'] = st.session_state['info_maps']['team_dict']
|
| 294 |
st.session_state['pos_dict'] = st.session_state['info_maps']['position_dict']
|
| 295 |
+
|
|
|
|
| 296 |
excluded_cols = ['BaseName', 'EntryCount']
|
| 297 |
exclude_stacks = ['BaseName', 'EntryCount', 'SP', 'SP1', 'SP2', 'P1', 'P2']
|
| 298 |
if 'Contest' in st.session_state and 'display_contest_info' not in st.session_state:
|
|
|
|
| 466 |
st.session_state['unique_players'] = pd.unique(st.session_state['display_contest_info'][st.session_state['player_columns']].values.ravel('K'))
|
| 467 |
st.session_state['unique_players'] = [p for p in st.session_state['unique_players'] if p != 'nan']
|
| 468 |
|
| 469 |
+
if selected_tab == 'Contest Analysis':
|
| 470 |
+
st.session_state['sport_select'] = sport_init
|
| 471 |
+
st.session_state['type_var'] = type_init
|
| 472 |
+
|
| 473 |
if 'display_contest_info' in st.session_state:
|
| 474 |
with st.expander("Info and filters"):
|
| 475 |
st.info("Note that any filtering here needs to be reset manually, i.e. if you parse down the specific users and want to reset the table, just backtrack your filtering by setting it back to 'All'")
|