James McCool
commited on
Commit
·
b5afac7
1
Parent(s):
5cebc76
Refactor contest file upload logic in app.py for improved session state management
Browse files- Removed unnecessary session state clearing to prevent data loss during contest file uploads.
- Enhanced the logic to check for existing contest files before allowing new uploads, ensuring a smoother user experience.
- Maintained existing functionality for loading contest data while improving clarity and efficiency in the upload process.
app.py
CHANGED
@@ -72,21 +72,20 @@ with tab1:
|
|
72 |
st.info("Go ahead and upload a Contest file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
|
73 |
if parse_type == 'DB Search':
|
74 |
contest_name_var = st.selectbox("Select Contest to load", name_parse)
|
75 |
-
st.session_state.clear()
|
76 |
if 'Contest_file' not in st.session_state:
|
77 |
if st.button('Load Contest Data', key='load_contest_data'):
|
78 |
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select)
|
79 |
else:
|
80 |
pass
|
81 |
elif parse_type == 'Manual':
|
82 |
-
st.session_state
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
if 'Contest_file' in st.session_state:
|
91 |
if 'Contest_file_helper' in st.session_state:
|
92 |
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['salary_df'], st.session_state['team_df'], st.session_state['pos_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], st.session_state['Contest_file_helper'], sport_select)
|
|
|
72 |
st.info("Go ahead and upload a Contest file here. Only include player columns and an optional 'Stack' column if you are playing MLB.")
|
73 |
if parse_type == 'DB Search':
|
74 |
contest_name_var = st.selectbox("Select Contest to load", name_parse)
|
|
|
75 |
if 'Contest_file' not in st.session_state:
|
76 |
if st.button('Load Contest Data', key='load_contest_data'):
|
77 |
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select)
|
78 |
else:
|
79 |
pass
|
80 |
elif parse_type == 'Manual':
|
81 |
+
if 'Contest_file' not in st.session_state:
|
82 |
+
st.session_state['Contest_upload'] = st.file_uploader("Upload Contest File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
|
83 |
+
if st.session_state['Contest_upload'] is not None:
|
84 |
+
st.session_state['Contest_file'] = pd.read_csv(st.session_state['Contest_upload'])
|
85 |
+
st.session_state['Contest_file_helper'] = grab_contest_data(sport_select, name_parse.iloc[0], contest_id_map, date_select)
|
86 |
+
else:
|
87 |
+
pass
|
88 |
+
|
89 |
if 'Contest_file' in st.session_state:
|
90 |
if 'Contest_file_helper' in st.session_state:
|
91 |
st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['salary_df'], st.session_state['team_df'], st.session_state['pos_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], st.session_state['Contest_file_helper'], sport_select)
|