Spaces:
Build error
Build error
James McCool
commited on
Commit
·
fb140dc
1
Parent(s):
5d83f16
Refactor data handling in pitcher tab of Streamlit app
Browse files- Consolidated the assignment of the displayed data frame to a single line at the end of the conditional checks, improving code clarity and reducing redundancy.
- Updated the displayed data for 'Current Slate Overview' to drop unnecessary columns, enhancing the relevance of the information presented to users.
- Standardized the naming of the site options in the hitter tab for consistency.
- src/streamlit_app.py +18 -8
src/streamlit_app.py
CHANGED
|
@@ -123,7 +123,7 @@ with pitcher_tab:
|
|
| 123 |
disp_raw = disp_raw[disp_raw['Team'].isin(team_var_sp)]
|
| 124 |
|
| 125 |
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'True AVG (LHH)', 'True AVG (RHH)', 'True AVG (Overall)', 'Weighted True AVG']]
|
| 126 |
-
|
| 127 |
elif table_var_sp == 'HWSr Splits':
|
| 128 |
disp_raw = true_avg_split
|
| 129 |
|
|
@@ -131,9 +131,16 @@ with pitcher_tab:
|
|
| 131 |
disp_raw = disp_raw[disp_raw['Team'].isin(team_var_sp)]
|
| 132 |
|
| 133 |
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'HWSr (LHH)', 'HWSr (RHH)', 'HWSr (Overall)', 'Weighted HWSr']]
|
| 134 |
-
|
|
|
|
| 135 |
elif table_var_sp == 'Current Slate Overview':
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
elif table_var_sp == 'Active Baselines':
|
| 138 |
disp_raw = pitcher_info
|
| 139 |
|
|
@@ -147,27 +154,30 @@ with pitcher_tab:
|
|
| 147 |
|
| 148 |
disp_raw = disp_raw[['Names', 'DK_Salary', 'FD_Salary', 'Team', 'Opp', 'Opp_TT', 'Hand', 'K%', 'BB%', 'True AVG', 'xSLG', 'xBA', 'Hits', 'xHRs', 'xHR/PA']]
|
| 149 |
positive_set = ['K%']
|
| 150 |
-
|
| 151 |
elif table_var_sp == 'League Aggregate Baselines':
|
| 152 |
disp_raw = pitcher_agg
|
| 153 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 154 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
| 155 |
-
|
| 156 |
elif table_var_sp == 'League Short Term Baselines':
|
| 157 |
disp_raw = pitcher_short
|
| 158 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 159 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
| 160 |
-
|
| 161 |
elif table_var_sp == 'League Long Term Baselines':
|
| 162 |
disp_raw = pitcher_long
|
| 163 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 164 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
| 165 |
-
st.session_state['sp_disp_frame'] = disp_raw
|
| 166 |
|
|
|
|
| 167 |
sp_disp_container = st.container(border = True)
|
| 168 |
sp_disp_container = sp_disp_container.empty()
|
| 169 |
|
| 170 |
with sp_disp_container:
|
|
|
|
|
|
|
|
|
|
| 171 |
st.dataframe(st.session_state['sp_disp_frame'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn_r').format(precision=2), height = 750, use_container_width = True, hide_index = True)
|
| 172 |
|
| 173 |
with hitter_tab:
|
|
@@ -175,7 +185,7 @@ with hitter_tab:
|
|
| 175 |
st.info('Note: Splits options are available for all baseline tables')
|
| 176 |
col1, col2, col3, col4, col5 = st.columns(5)
|
| 177 |
with col1:
|
| 178 |
-
site_var_hitter = st.selectbox('Site', ['
|
| 179 |
with col2:
|
| 180 |
table_var_hitter = st.selectbox('Table', ['Current Slate Overview', 'Active Baselines', 'League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines'], key = 'table_var_hitter')
|
| 181 |
with col3:
|
|
|
|
| 123 |
disp_raw = disp_raw[disp_raw['Team'].isin(team_var_sp)]
|
| 124 |
|
| 125 |
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'True AVG (LHH)', 'True AVG (RHH)', 'True AVG (Overall)', 'Weighted True AVG']]
|
| 126 |
+
|
| 127 |
elif table_var_sp == 'HWSr Splits':
|
| 128 |
disp_raw = true_avg_split
|
| 129 |
|
|
|
|
| 131 |
disp_raw = disp_raw[disp_raw['Team'].isin(team_var_sp)]
|
| 132 |
|
| 133 |
disp_raw = disp_raw[['Player', 'Handedness', 'Team', 'Opp', 'Opp LHH', 'Opp RHH', 'HWSr (LHH)', 'HWSr (RHH)', 'HWSr (Overall)', 'Weighted HWSr']]
|
| 134 |
+
|
| 135 |
+
|
| 136 |
elif table_var_sp == 'Current Slate Overview':
|
| 137 |
+
disp_raw = starting_pitchers
|
| 138 |
+
|
| 139 |
+
disp_raw = disp_raw.drop(columns = ['Own Adj', 'Perf_Adj'])
|
| 140 |
+
|
| 141 |
+
if team_var_sp is not None:
|
| 142 |
+
disp_raw = disp_raw[disp_raw['Team'].isin(team_var_sp)]
|
| 143 |
+
|
| 144 |
elif table_var_sp == 'Active Baselines':
|
| 145 |
disp_raw = pitcher_info
|
| 146 |
|
|
|
|
| 154 |
|
| 155 |
disp_raw = disp_raw[['Names', 'DK_Salary', 'FD_Salary', 'Team', 'Opp', 'Opp_TT', 'Hand', 'K%', 'BB%', 'True AVG', 'xSLG', 'xBA', 'Hits', 'xHRs', 'xHR/PA']]
|
| 156 |
positive_set = ['K%']
|
| 157 |
+
|
| 158 |
elif table_var_sp == 'League Aggregate Baselines':
|
| 159 |
disp_raw = pitcher_agg
|
| 160 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 161 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
| 162 |
+
|
| 163 |
elif table_var_sp == 'League Short Term Baselines':
|
| 164 |
disp_raw = pitcher_short
|
| 165 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 166 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
| 167 |
+
|
| 168 |
elif table_var_sp == 'League Long Term Baselines':
|
| 169 |
disp_raw = pitcher_long
|
| 170 |
disp_raw = disp_raw[disp_raw['Set'] == splits_var_sp]
|
| 171 |
disp_raw = disp_raw[['Player', 'PA', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeoutper', 'Strikeouts', 'Walkper', 'Walks', 'xBA', 'xSLG', 'xwOBA', 'BABIP', 'AVG', 'FB%', 'True_AVG', 'xHits', 'xHRs', 'xHR/PA', 'HWSr']]
|
|
|
|
| 172 |
|
| 173 |
+
st.session_state['sp_disp_frame'] = disp_raw
|
| 174 |
sp_disp_container = st.container(border = True)
|
| 175 |
sp_disp_container = sp_disp_container.empty()
|
| 176 |
|
| 177 |
with sp_disp_container:
|
| 178 |
+
if table_var_sp in (['League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines']):
|
| 179 |
+
with st.spinner("Full league baselines can take some time to load"):
|
| 180 |
+
time.sleep(7)
|
| 181 |
st.dataframe(st.session_state['sp_disp_frame'].style.background_gradient(axis=0).background_gradient(cmap='RdYlGn_r').format(precision=2), height = 750, use_container_width = True, hide_index = True)
|
| 182 |
|
| 183 |
with hitter_tab:
|
|
|
|
| 185 |
st.info('Note: Splits options are available for all baseline tables')
|
| 186 |
col1, col2, col3, col4, col5 = st.columns(5)
|
| 187 |
with col1:
|
| 188 |
+
site_var_hitter = st.selectbox('Site', ['Draftkings', 'Fanduel'], key = 'site_var_hitter')
|
| 189 |
with col2:
|
| 190 |
table_var_hitter = st.selectbox('Table', ['Current Slate Overview', 'Active Baselines', 'League Aggregate Baselines', 'League Short Term Baselines', 'League Long Term Baselines'], key = 'table_var_hitter')
|
| 191 |
with col3:
|