Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,7 +42,9 @@ master_hold = 'https://docs.google.com/spreadsheets/d/1D526UlXmrz-8qxVcUKrA-u7f6
|
|
| 42 |
team_format = {'2B': '{:.2%}', 'HR': '{:.2%}', 'SB': '{:.2%}', 'P_SO': '{:.2%}', 'P_H': '{:.2%}', 'P_R': '{:.2%}',
|
| 43 |
'P_HR': '{:.2%}', 'P_BB': '{:.2%}'}
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
def init_baselines():
|
| 47 |
sh = gcservice_account.open_by_url(master_hold)
|
| 48 |
worksheet = sh.worksheet('Pitcher_Proj')
|
|
@@ -65,17 +67,19 @@ def convert_df_to_csv(df):
|
|
| 65 |
return df.to_csv().encode('utf-8')
|
| 66 |
|
| 67 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 68 |
|
| 69 |
-
tab1, tab2, tab3, tab4, tab5 = st.tabs(["
|
| 70 |
|
| 71 |
with tab1:
|
| 72 |
if st.button("Reset Data", key='reset1'):
|
| 73 |
st.cache_data.clear()
|
| 74 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 75 |
raw_frame = wins_proj.copy()
|
| 76 |
export_frame_team = raw_frame[['Team', '2B', 'HR', 'SB', 'P_SO', 'P_H', 'P_R', 'P_HR', 'P_BB', 'Upside', 'Projected']]
|
| 77 |
disp_frame = raw_frame[['Team', '2B', 'HR', 'SB', 'P_SO', 'P_H', 'P_R', 'P_HR', 'P_BB', 'Upside', 'Projected']]
|
| 78 |
-
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(team_format, precision=2), use_container_width = True
|
| 79 |
|
| 80 |
st.download_button(
|
| 81 |
label="Export Team Win Projections",
|
|
@@ -89,12 +93,20 @@ with tab2:
|
|
| 89 |
if st.button("Reset Data", key='reset2'):
|
| 90 |
st.cache_data.clear()
|
| 91 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 92 |
raw_frame = pitcher_proj.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
export_frame_sp = raw_frame[['Name', 'Team', 'TBF', 'Ceiling_var', 'True_AVG', 'Hits', 'Singles%', 'Singles', 'Doubles%', 'Doubles', 'xHR%', 'Homeruns', 'Strikeout%', 'Strikeouts',
|
| 94 |
'Walk%', 'Walks', 'Runs%', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 95 |
-
|
| 96 |
'Walks', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 97 |
-
st.dataframe(
|
| 98 |
|
| 99 |
st.download_button(
|
| 100 |
label="Export Pitcher Projections",
|
|
@@ -108,12 +120,20 @@ with tab3:
|
|
| 108 |
if st.button("Reset Data", key='reset3'):
|
| 109 |
st.cache_data.clear()
|
| 110 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 111 |
raw_frame = hitter_proj.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
export_frame_h = raw_frame[['Name', 'Team', 'PA', 'Ceiling_var', 'Walk%', 'Walks', 'xHits', 'Singles%', 'Singles', 'Doubles%', 'Doubles',
|
| 113 |
'xHR%', 'Homeruns', 'Runs%', 'Runs', 'RBI%', 'RBI', 'Steal%', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 114 |
-
|
| 115 |
'Homeruns', 'Runs', 'RBI', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 116 |
-
st.dataframe(
|
| 117 |
|
| 118 |
st.download_button(
|
| 119 |
label="Export Hitter Projections",
|
|
@@ -127,6 +147,7 @@ with tab4:
|
|
| 127 |
if st.button("Reset Data", key='reset4'):
|
| 128 |
st.cache_data.clear()
|
| 129 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 130 |
col1, col2 = st.columns([1, 5])
|
| 131 |
|
| 132 |
with col2:
|
|
@@ -206,12 +227,13 @@ with tab4:
|
|
| 206 |
|
| 207 |
with df_hold_container.container():
|
| 208 |
df_hold_container = st.empty()
|
| 209 |
-
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 210 |
|
| 211 |
with tab5:
|
| 212 |
if st.button("Reset Data", key='reset5'):
|
| 213 |
st.cache_data.clear()
|
| 214 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
|
|
|
| 215 |
col1, col2 = st.columns([1, 5])
|
| 216 |
|
| 217 |
with col2:
|
|
@@ -298,4 +320,4 @@ with tab5:
|
|
| 298 |
|
| 299 |
with df_hold_container.container():
|
| 300 |
df_hold_container = st.empty()
|
| 301 |
-
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
| 42 |
team_format = {'2B': '{:.2%}', 'HR': '{:.2%}', 'SB': '{:.2%}', 'P_SO': '{:.2%}', 'P_H': '{:.2%}', 'P_R': '{:.2%}',
|
| 43 |
'P_HR': '{:.2%}', 'P_BB': '{:.2%}'}
|
| 44 |
|
| 45 |
+
sim_format = {'Top_finish': '{:.2%}', 'Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}'}
|
| 46 |
+
|
| 47 |
+
@st.cache_resource(ttl = 600)
|
| 48 |
def init_baselines():
|
| 49 |
sh = gcservice_account.open_by_url(master_hold)
|
| 50 |
worksheet = sh.worksheet('Pitcher_Proj')
|
|
|
|
| 67 |
return df.to_csv().encode('utf-8')
|
| 68 |
|
| 69 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 70 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 71 |
|
| 72 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Pitcher Projections", "Hitter Projections", "Pitcher Simulations", "Hitter Simulations"])
|
| 73 |
|
| 74 |
with tab1:
|
| 75 |
if st.button("Reset Data", key='reset1'):
|
| 76 |
st.cache_data.clear()
|
| 77 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 78 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 79 |
raw_frame = wins_proj.copy()
|
| 80 |
export_frame_team = raw_frame[['Team', '2B', 'HR', 'SB', 'P_SO', 'P_H', 'P_R', 'P_HR', 'P_BB', 'Upside', 'Projected']]
|
| 81 |
disp_frame = raw_frame[['Team', '2B', 'HR', 'SB', 'P_SO', 'P_H', 'P_R', 'P_HR', 'P_BB', 'Upside', 'Projected']]
|
| 82 |
+
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(team_format, precision=2), use_container_width = True)
|
| 83 |
|
| 84 |
st.download_button(
|
| 85 |
label="Export Team Win Projections",
|
|
|
|
| 93 |
if st.button("Reset Data", key='reset2'):
|
| 94 |
st.cache_data.clear()
|
| 95 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 96 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 97 |
raw_frame = pitcher_proj.copy()
|
| 98 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 99 |
+
if split_var1 == 'Specific Teams':
|
| 100 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var1')
|
| 101 |
+
elif split_var1 == 'All':
|
| 102 |
+
team_var1 = total_teams
|
| 103 |
+
|
| 104 |
+
working_data = raw_frame[raw_frame['Team'].isin(team_var1)]
|
| 105 |
export_frame_sp = raw_frame[['Name', 'Team', 'TBF', 'Ceiling_var', 'True_AVG', 'Hits', 'Singles%', 'Singles', 'Doubles%', 'Doubles', 'xHR%', 'Homeruns', 'Strikeout%', 'Strikeouts',
|
| 106 |
'Walk%', 'Walks', 'Runs%', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 107 |
+
disp_frame_sp = working_data[['Name', 'Team', 'TBF', 'True_AVG', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeouts',
|
| 108 |
'Walks', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 109 |
+
st.dataframe(disp_frame_sp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 110 |
|
| 111 |
st.download_button(
|
| 112 |
label="Export Pitcher Projections",
|
|
|
|
| 120 |
if st.button("Reset Data", key='reset3'):
|
| 121 |
st.cache_data.clear()
|
| 122 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 123 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 124 |
raw_frame = hitter_proj.copy()
|
| 125 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 126 |
+
if split_var2 == 'Specific Teams':
|
| 127 |
+
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='team_var2')
|
| 128 |
+
elif split_var2 == 'All':
|
| 129 |
+
team_var2 = total_teams
|
| 130 |
+
|
| 131 |
+
working_data = raw_frame[raw_frame['Team'].isin(team_var2)]
|
| 132 |
export_frame_h = raw_frame[['Name', 'Team', 'PA', 'Ceiling_var', 'Walk%', 'Walks', 'xHits', 'Singles%', 'Singles', 'Doubles%', 'Doubles',
|
| 133 |
'xHR%', 'Homeruns', 'Runs%', 'Runs', 'RBI%', 'RBI', 'Steal%', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 134 |
+
disp_frame_h = working_data[['Name', 'Team', 'PA', 'Walks', 'xHits', 'Singles', 'Doubles',
|
| 135 |
'Homeruns', 'Runs', 'RBI', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 136 |
+
st.dataframe(disp_frame_h.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 137 |
|
| 138 |
st.download_button(
|
| 139 |
label="Export Hitter Projections",
|
|
|
|
| 147 |
if st.button("Reset Data", key='reset4'):
|
| 148 |
st.cache_data.clear()
|
| 149 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 150 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 151 |
col1, col2 = st.columns([1, 5])
|
| 152 |
|
| 153 |
with col2:
|
|
|
|
| 227 |
|
| 228 |
with df_hold_container.container():
|
| 229 |
df_hold_container = st.empty()
|
| 230 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(sim_format, precision=2), use_container_width = True)
|
| 231 |
|
| 232 |
with tab5:
|
| 233 |
if st.button("Reset Data", key='reset5'):
|
| 234 |
st.cache_data.clear()
|
| 235 |
pitcher_proj, hitter_proj, wins_proj = init_baselines()
|
| 236 |
+
total_teams = pitcher_proj['Team'].values.tolist()
|
| 237 |
col1, col2 = st.columns([1, 5])
|
| 238 |
|
| 239 |
with col2:
|
|
|
|
| 320 |
|
| 321 |
with df_hold_container.container():
|
| 322 |
df_hold_container = st.empty()
|
| 323 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(sim_format, precision=2), use_container_width = True)
|