James McCool
commited on
Commit
·
0d01fa6
1
Parent(s):
45a70a9
Enhance app.py layout and filtering options
Browse files- Refactored the user interface to include a two-column layout for sport and game type selection, improving usability.
- Reintroduced the filtering options within an expander for better organization, allowing users to filter by player selection while maintaining a clean interface.
- Streamlined the handling of session state for player filtering, ensuring consistent behavior during calculations.
app.py
CHANGED
|
@@ -21,7 +21,11 @@ with tab1:
|
|
| 21 |
if st.button('Clear data', key='reset1'):
|
| 22 |
st.session_state.clear()
|
| 23 |
st.session_state['calc_toggle'] = False
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Add file uploaders to your app
|
| 26 |
col1, col2 = st.columns(2)
|
| 27 |
|
|
@@ -98,26 +102,6 @@ with tab2:
|
|
| 98 |
# Create a copy of the dataframe for calculations
|
| 99 |
working_df = st.session_state['Contest'].copy()
|
| 100 |
|
| 101 |
-
with st.expander("Info and filters"):
|
| 102 |
-
if st.button('Clear data', key='reset3'):
|
| 103 |
-
st.session_state.clear()
|
| 104 |
-
with st.form(key='filter_form'):
|
| 105 |
-
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
| 106 |
-
entry_parse_var = st.selectbox("Do you want to view a specific player(s) or a group of players?", ['All', 'Specific'])
|
| 107 |
-
entry_names = st.multiselect("Select players", options=st.session_state['entry_list'], default=[])
|
| 108 |
-
submitted = st.form_submit_button("Submit")
|
| 109 |
-
if submitted:
|
| 110 |
-
if 'player_frame' in st.session_state:
|
| 111 |
-
del st.session_state['player_frame']
|
| 112 |
-
if 'stack_frame' in st.session_state:
|
| 113 |
-
del st.session_state['stack_frame']
|
| 114 |
-
# Apply entry name filter if specific entries are selected
|
| 115 |
-
if entry_parse_var == 'Specific' and entry_names:
|
| 116 |
-
working_df = working_df[working_df['BaseName'].isin(entry_names)]
|
| 117 |
-
st.session_state['calc_toggle'] = True
|
| 118 |
-
elif entry_parse_var == 'All':
|
| 119 |
-
st.session_state['calc_toggle'] = True
|
| 120 |
-
|
| 121 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state and st.session_state['calc_toggle']:
|
| 122 |
if type_var == 'Classic':
|
| 123 |
working_df['stack'] = working_df.apply(
|
|
@@ -187,6 +171,25 @@ with tab2:
|
|
| 187 |
working_df['percentile_finish'] = working_df['index'].rank(pct=True)
|
| 188 |
working_df['finish'] = working_df['index']
|
| 189 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# Initialize pagination in session state if not exists
|
| 192 |
if 'current_page' not in st.session_state:
|
|
|
|
| 21 |
if st.button('Clear data', key='reset1'):
|
| 22 |
st.session_state.clear()
|
| 23 |
st.session_state['calc_toggle'] = False
|
| 24 |
+
col1, col2 = st.columns(2)
|
| 25 |
+
with col1:
|
| 26 |
+
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'])
|
| 27 |
+
with col2:
|
| 28 |
+
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'])
|
| 29 |
# Add file uploaders to your app
|
| 30 |
col1, col2 = st.columns(2)
|
| 31 |
|
|
|
|
| 102 |
# Create a copy of the dataframe for calculations
|
| 103 |
working_df = st.session_state['Contest'].copy()
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
if 'Contest' in st.session_state and 'projections_df' in st.session_state and st.session_state['calc_toggle']:
|
| 106 |
if type_var == 'Classic':
|
| 107 |
working_df['stack'] = working_df.apply(
|
|
|
|
| 171 |
working_df['percentile_finish'] = working_df['index'].rank(pct=True)
|
| 172 |
working_df['finish'] = working_df['index']
|
| 173 |
working_df = working_df.drop(['sorted', 'index'], axis=1)
|
| 174 |
+
|
| 175 |
+
with st.expander("Info and filters"):
|
| 176 |
+
if st.button('Clear data', key='reset3'):
|
| 177 |
+
st.session_state.clear()
|
| 178 |
+
with st.form(key='filter_form'):
|
| 179 |
+
entry_parse_var = st.selectbox("Do you want to view a specific player(s) or a group of players?", ['All', 'Specific'])
|
| 180 |
+
entry_names = st.multiselect("Select players", options=st.session_state['entry_list'], default=[])
|
| 181 |
+
submitted = st.form_submit_button("Submit")
|
| 182 |
+
if submitted:
|
| 183 |
+
if 'player_frame' in st.session_state:
|
| 184 |
+
del st.session_state['player_frame']
|
| 185 |
+
if 'stack_frame' in st.session_state:
|
| 186 |
+
del st.session_state['stack_frame']
|
| 187 |
+
# Apply entry name filter if specific entries are selected
|
| 188 |
+
if entry_parse_var == 'Specific' and entry_names:
|
| 189 |
+
working_df = working_df[working_df['BaseName'].isin(entry_names)]
|
| 190 |
+
st.session_state['calc_toggle'] = True
|
| 191 |
+
elif entry_parse_var == 'All':
|
| 192 |
+
st.session_state['calc_toggle'] = True
|
| 193 |
|
| 194 |
# Initialize pagination in session state if not exists
|
| 195 |
if 'current_page' not in st.session_state:
|