Spaces:
Build error
Build error
James McCool
commited on
Commit
·
2f31f7d
1
Parent(s):
7c7d5e6
Refactor data display logic in Streamlit app for pitchers and hitters
Browse files- Removed redundant container initializations for displaying dataframes in pitcher and hitter tabs.
- Streamlined dataframe assignment for 'True AVG Splits' and 'HWSr Splits' to improve clarity and maintainability.
- Ensured consistent use of containers for displaying dataframes across all tabs.
- src/streamlit_app.py +15 -11
src/streamlit_app.py
CHANGED
|
@@ -97,9 +97,6 @@ bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitch
|
|
| 97 |
pitcher_tab, hitter_tab, team_tab = st.tabs(['Pitchers', 'Hitters', 'Team'])
|
| 98 |
|
| 99 |
with pitcher_tab:
|
| 100 |
-
sp_disp_container = st.container(border = True)
|
| 101 |
-
sp_disp_container = sp_disp_container.empty()
|
| 102 |
-
|
| 103 |
with st.expander('Info and Display Options'):
|
| 104 |
st.info('Note: Splits options are available for all baseline tables, they do not apply to True AVG, HWSr, or the Overview tables')
|
| 105 |
col1, col2, col3 = st.columns(3)
|
|
@@ -111,9 +108,13 @@ with pitcher_tab:
|
|
| 111 |
splits_var_sp = st.selectbox('Splits', ['Overall', 'RHH', 'LHH'], key = 'splits_var_sp')
|
| 112 |
|
| 113 |
if table_var_sp == 'True AVG Splits':
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
elif table_var_sp == 'HWSr Splits':
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
elif table_var_sp == 'Current Slate Overview':
|
| 118 |
st.session_state['sp_disp_frame'] = starting_pitchers
|
| 119 |
elif table_var_sp == 'Active Baselines':
|
|
@@ -124,14 +125,14 @@ with pitcher_tab:
|
|
| 124 |
st.session_state['sp_disp_frame'] = pitcher_short
|
| 125 |
elif table_var_sp == 'League Long Term Baselines':
|
| 126 |
st.session_state['sp_disp_frame'] = pitcher_long
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
with sp_disp_container:
|
| 129 |
st.dataframe(st.session_state['sp_disp_frame'])
|
| 130 |
|
| 131 |
with hitter_tab:
|
| 132 |
-
hitter_disp_container = st.container(border = True)
|
| 133 |
-
hitter_disp_container = hitter_disp_container.empty()
|
| 134 |
-
|
| 135 |
with st.expander('Info and Display Options'):
|
| 136 |
st.info('Note: Splits options are available for all baseline tables')
|
| 137 |
col1, col2, col3 = st.columns(3)
|
|
@@ -153,13 +154,13 @@ with hitter_tab:
|
|
| 153 |
elif table_var_hitter == 'League Long Term Baselines':
|
| 154 |
st.session_state['hitter_disp_frame'] = hitter_long
|
| 155 |
|
|
|
|
|
|
|
|
|
|
| 156 |
with hitter_disp_container:
|
| 157 |
st.dataframe(st.session_state['hitter_disp_frame'])
|
| 158 |
|
| 159 |
with team_tab:
|
| 160 |
-
team_disp_container = st.container(border = True)
|
| 161 |
-
team_disp_container = team_disp_container.empty()
|
| 162 |
-
|
| 163 |
with st.expander('Info and Display Options'):
|
| 164 |
col1, col2, col3 = st.columns(3)
|
| 165 |
with col1:
|
|
@@ -172,5 +173,8 @@ with team_tab:
|
|
| 172 |
elif table_var_team == 'Bullpen Baselines':
|
| 173 |
st.session_state['team_disp_frame'] = bp_data
|
| 174 |
|
|
|
|
|
|
|
|
|
|
| 175 |
with team_disp_container:
|
| 176 |
st.dataframe(st.session_state['team_disp_frame'])
|
|
|
|
| 97 |
pitcher_tab, hitter_tab, team_tab = st.tabs(['Pitchers', 'Hitters', 'Team'])
|
| 98 |
|
| 99 |
with pitcher_tab:
|
|
|
|
|
|
|
|
|
|
| 100 |
with st.expander('Info and Display Options'):
|
| 101 |
st.info('Note: Splits options are available for all baseline tables, they do not apply to True AVG, HWSr, or the Overview tables')
|
| 102 |
col1, col2, col3 = st.columns(3)
|
|
|
|
| 108 |
splits_var_sp = st.selectbox('Splits', ['Overall', 'RHH', 'LHH'], key = 'splits_var_sp')
|
| 109 |
|
| 110 |
if table_var_sp == 'True AVG Splits':
|
| 111 |
+
disp_raw = true_avg_split
|
| 112 |
+
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'True AVG (LHH)', 'True AVG (RHH)', 'True AVG (Overall)', 'Weighted True AVG']]
|
| 113 |
+
st.session_state['sp_disp_frame'] = disp_raw
|
| 114 |
elif table_var_sp == 'HWSr Splits':
|
| 115 |
+
disp_raw = true_avg_split
|
| 116 |
+
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'HWSr (LHH)', 'HWSr (RHH)', 'HWSr (Overall)', 'Weighted HWSr']]
|
| 117 |
+
st.session_state['sp_disp_frame'] = disp_raw
|
| 118 |
elif table_var_sp == 'Current Slate Overview':
|
| 119 |
st.session_state['sp_disp_frame'] = starting_pitchers
|
| 120 |
elif table_var_sp == 'Active Baselines':
|
|
|
|
| 125 |
st.session_state['sp_disp_frame'] = pitcher_short
|
| 126 |
elif table_var_sp == 'League Long Term Baselines':
|
| 127 |
st.session_state['sp_disp_frame'] = pitcher_long
|
| 128 |
+
|
| 129 |
+
sp_disp_container = st.container(border = True)
|
| 130 |
+
sp_disp_container = sp_disp_container.empty()
|
| 131 |
|
| 132 |
with sp_disp_container:
|
| 133 |
st.dataframe(st.session_state['sp_disp_frame'])
|
| 134 |
|
| 135 |
with hitter_tab:
|
|
|
|
|
|
|
|
|
|
| 136 |
with st.expander('Info and Display Options'):
|
| 137 |
st.info('Note: Splits options are available for all baseline tables')
|
| 138 |
col1, col2, col3 = st.columns(3)
|
|
|
|
| 154 |
elif table_var_hitter == 'League Long Term Baselines':
|
| 155 |
st.session_state['hitter_disp_frame'] = hitter_long
|
| 156 |
|
| 157 |
+
hitter_disp_container = st.container(border = True)
|
| 158 |
+
hitter_disp_container = hitter_disp_container.empty()
|
| 159 |
+
|
| 160 |
with hitter_disp_container:
|
| 161 |
st.dataframe(st.session_state['hitter_disp_frame'])
|
| 162 |
|
| 163 |
with team_tab:
|
|
|
|
|
|
|
|
|
|
| 164 |
with st.expander('Info and Display Options'):
|
| 165 |
col1, col2, col3 = st.columns(3)
|
| 166 |
with col1:
|
|
|
|
| 173 |
elif table_var_team == 'Bullpen Baselines':
|
| 174 |
st.session_state['team_disp_frame'] = bp_data
|
| 175 |
|
| 176 |
+
team_disp_container = st.container(border = True)
|
| 177 |
+
team_disp_container = team_disp_container.empty()
|
| 178 |
+
|
| 179 |
with team_disp_container:
|
| 180 |
st.dataframe(st.session_state['team_disp_frame'])
|