Spaces:
Build error
Build error
James McCool
commited on
Commit
·
2ea483c
1
Parent(s):
51c1a0b
Refactor Streamlit app to streamline data handling and improve display logic
Browse files- Updated data retrieval to drop unnecessary '_id' columns from DataFrames for various tables.
- Enhanced display logic by storing DataFrames in session state for better performance and user experience.
- Improved organization of data presentation across different tabs for pitchers, hitters, and teams.
- src/streamlit_app.py +33 -27
src/streamlit_app.py
CHANGED
|
@@ -64,31 +64,31 @@ def init_baselines():
|
|
| 64 |
df = pd.DataFrame(cursor)
|
| 65 |
|
| 66 |
if table == 'Bullpen_Data':
|
| 67 |
-
bp_data = df
|
| 68 |
elif table == 'Hitter_Agg_Merge':
|
| 69 |
-
hitter_agg = df
|
| 70 |
elif table == 'Hitter_Long_Merge':
|
| 71 |
-
hitter_long = df
|
| 72 |
elif table == 'Hitter_Short_Merge':
|
| 73 |
-
hitter_short = df
|
| 74 |
elif table == 'Pitcher_Agg_Merge':
|
| 75 |
-
pitcher_agg = df
|
| 76 |
elif table == 'Pitcher_Long_Merge':
|
| 77 |
-
pitcher_long = df
|
| 78 |
elif table == 'Pitcher_Short_Merge':
|
| 79 |
-
pitcher_short = df
|
| 80 |
elif table == 'Slate_Hitters_Merge':
|
| 81 |
-
slate_hitters = df
|
| 82 |
elif table == 'Slate_Team_Merge':
|
| 83 |
-
slate_team = df
|
| 84 |
elif table == 'Starting_Pitchers':
|
| 85 |
-
starting_pitchers = df
|
| 86 |
elif table == 'True_AVG_Split':
|
| 87 |
-
true_avg_split = df
|
| 88 |
elif table == 'Pitcher_Info':
|
| 89 |
-
pitcher_info = df
|
| 90 |
elif table == 'Hitter_Info':
|
| 91 |
-
hitter_info = df
|
| 92 |
|
| 93 |
return bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info
|
| 94 |
|
|
@@ -108,19 +108,21 @@ with pitcher_tab:
|
|
| 108 |
splits_var_sp = st.selectbox('Splits', ['Overall', 'RHH', 'LHH'], key = 'splits_var_sp')
|
| 109 |
|
| 110 |
if table_var_sp == 'True AVG Splits':
|
| 111 |
-
st.
|
| 112 |
elif table_var_sp == 'HWSr Splits':
|
| 113 |
-
st.
|
| 114 |
elif table_var_sp == 'Current Slate Overview':
|
| 115 |
-
st.
|
| 116 |
elif table_var_sp == 'Active Baselines':
|
| 117 |
-
st.
|
| 118 |
elif table_var_sp == 'League Aggregate Baselines':
|
| 119 |
-
st.
|
| 120 |
elif table_var_sp == 'League Short Term Baselines':
|
| 121 |
-
st.
|
| 122 |
elif table_var_sp == 'League Long Term Baselines':
|
| 123 |
-
st.
|
|
|
|
|
|
|
| 124 |
|
| 125 |
with hitter_tab:
|
| 126 |
with st.expander('Info and Display Options'):
|
|
@@ -134,15 +136,17 @@ with hitter_tab:
|
|
| 134 |
splits_var_hitter = st.selectbox('Splits', ['Overall', 'RHP', 'LHP'], key = 'splits_var_hitter')
|
| 135 |
|
| 136 |
if table_var_hitter == 'Current Slate Overview':
|
| 137 |
-
st.
|
| 138 |
elif table_var_hitter == 'Active Baselines':
|
| 139 |
-
st.
|
| 140 |
elif table_var_hitter == 'League Aggregate Baselines':
|
| 141 |
-
st.
|
| 142 |
elif table_var_hitter == 'League Short Term Baselines':
|
| 143 |
-
st.
|
| 144 |
elif table_var_hitter == 'League Long Term Baselines':
|
| 145 |
-
st.
|
|
|
|
|
|
|
| 146 |
|
| 147 |
with team_tab:
|
| 148 |
with st.expander('Info and Display Options'):
|
|
@@ -153,6 +157,8 @@ with team_tab:
|
|
| 153 |
table_var_team = st.selectbox('Table', ['Team Baselines', 'Bullpen Baselines'], key = 'table_var_team')
|
| 154 |
|
| 155 |
if table_var_team == 'Team Baselines':
|
| 156 |
-
st.
|
| 157 |
elif table_var_team == 'Bullpen Baselines':
|
| 158 |
-
st.
|
|
|
|
|
|
|
|
|
| 64 |
df = pd.DataFrame(cursor)
|
| 65 |
|
| 66 |
if table == 'Bullpen_Data':
|
| 67 |
+
bp_data = df.drop(columns = ['_id'])
|
| 68 |
elif table == 'Hitter_Agg_Merge':
|
| 69 |
+
hitter_agg = df.drop(columns = ['_id'])
|
| 70 |
elif table == 'Hitter_Long_Merge':
|
| 71 |
+
hitter_long = df.drop(columns = ['_id'])
|
| 72 |
elif table == 'Hitter_Short_Merge':
|
| 73 |
+
hitter_short = df.drop(columns = ['_id'])
|
| 74 |
elif table == 'Pitcher_Agg_Merge':
|
| 75 |
+
pitcher_agg = df.drop(columns = ['_id'])
|
| 76 |
elif table == 'Pitcher_Long_Merge':
|
| 77 |
+
pitcher_long = df.drop(columns = ['_id'])
|
| 78 |
elif table == 'Pitcher_Short_Merge':
|
| 79 |
+
pitcher_short = df.drop(columns = ['_id'])
|
| 80 |
elif table == 'Slate_Hitters_Merge':
|
| 81 |
+
slate_hitters = df.drop(columns = ['_id'])
|
| 82 |
elif table == 'Slate_Team_Merge':
|
| 83 |
+
slate_team = df.drop(columns = ['_id'])
|
| 84 |
elif table == 'Starting_Pitchers':
|
| 85 |
+
starting_pitchers = df.drop(columns = ['_id'])
|
| 86 |
elif table == 'True_AVG_Split':
|
| 87 |
+
true_avg_split = df.drop(columns = ['_id'])
|
| 88 |
elif table == 'Pitcher_Info':
|
| 89 |
+
pitcher_info = df.drop(columns = ['_id'])
|
| 90 |
elif table == 'Hitter_Info':
|
| 91 |
+
hitter_info = df.drop(columns = ['_id'])
|
| 92 |
|
| 93 |
return bp_data, hitter_agg, hitter_long, hitter_short, pitcher_agg, pitcher_long, pitcher_short, slate_hitters, slate_team, starting_pitchers, true_avg_split, pitcher_info, hitter_info
|
| 94 |
|
|
|
|
| 108 |
splits_var_sp = st.selectbox('Splits', ['Overall', 'RHH', 'LHH'], key = 'splits_var_sp')
|
| 109 |
|
| 110 |
if table_var_sp == 'True AVG Splits':
|
| 111 |
+
st.session_state['sp_disp_frame'] = true_avg_split
|
| 112 |
elif table_var_sp == 'HWSr Splits':
|
| 113 |
+
st.session_state['sp_disp_frame'] = true_avg_split
|
| 114 |
elif table_var_sp == 'Current Slate Overview':
|
| 115 |
+
st.session_state['sp_disp_frame'] = starting_pitchers
|
| 116 |
elif table_var_sp == 'Active Baselines':
|
| 117 |
+
st.session_state['sp_disp_frame'] = pitcher_info
|
| 118 |
elif table_var_sp == 'League Aggregate Baselines':
|
| 119 |
+
st.session_state['sp_disp_frame'] = pitcher_agg
|
| 120 |
elif table_var_sp == 'League Short Term Baselines':
|
| 121 |
+
st.session_state['sp_disp_frame'] = pitcher_short
|
| 122 |
elif table_var_sp == 'League Long Term Baselines':
|
| 123 |
+
st.session_state['sp_disp_frame'] = pitcher_long
|
| 124 |
+
|
| 125 |
+
st.dataframe(st.session_state['sp_disp_frame'])
|
| 126 |
|
| 127 |
with hitter_tab:
|
| 128 |
with st.expander('Info and Display Options'):
|
|
|
|
| 136 |
splits_var_hitter = st.selectbox('Splits', ['Overall', 'RHP', 'LHP'], key = 'splits_var_hitter')
|
| 137 |
|
| 138 |
if table_var_hitter == 'Current Slate Overview':
|
| 139 |
+
st.session_state['hitter_disp_frame'] = starting_pitchers
|
| 140 |
elif table_var_hitter == 'Active Baselines':
|
| 141 |
+
st.session_state['hitter_disp_frame'] = hitter_info
|
| 142 |
elif table_var_hitter == 'League Aggregate Baselines':
|
| 143 |
+
st.session_state['hitter_disp_frame'] = hitter_agg
|
| 144 |
elif table_var_hitter == 'League Short Term Baselines':
|
| 145 |
+
st.session_state['hitter_disp_frame'] = hitter_short
|
| 146 |
elif table_var_hitter == 'League Long Term Baselines':
|
| 147 |
+
st.session_state['hitter_disp_frame'] = hitter_long
|
| 148 |
+
|
| 149 |
+
st.dataframe(st.session_state['hitter_disp_frame'])
|
| 150 |
|
| 151 |
with team_tab:
|
| 152 |
with st.expander('Info and Display Options'):
|
|
|
|
| 157 |
table_var_team = st.selectbox('Table', ['Team Baselines', 'Bullpen Baselines'], key = 'table_var_team')
|
| 158 |
|
| 159 |
if table_var_team == 'Team Baselines':
|
| 160 |
+
st.session_state['team_disp_frame'] = slate_team
|
| 161 |
elif table_var_team == 'Bullpen Baselines':
|
| 162 |
+
st.session_state['team_disp_frame'] = bp_data
|
| 163 |
+
|
| 164 |
+
st.dataframe(st.session_state['team_disp_frame'])
|