Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,8 +39,10 @@ gcservice_account = init_conn()
|
|
39 |
|
40 |
master_hold = 'https://docs.google.com/spreadsheets/d/1D526UlXmrz-8qxVcUKrA-u7f6FftUiBufxDnzQv980k/edit#gid=791804525'
|
41 |
|
|
|
|
|
42 |
|
43 |
-
@st.cache_resource(ttl =
|
44 |
def init_baselines():
|
45 |
sh = gcservice_account.open_by_url(master_hold)
|
46 |
worksheet = sh.worksheet('Pitcher_Proj')
|
@@ -52,19 +54,41 @@ def init_baselines():
|
|
52 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
53 |
hitter_proj = raw_display.dropna()
|
54 |
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
def convert_df_to_csv(df):
|
58 |
return df.to_csv().encode('utf-8')
|
59 |
|
60 |
-
pitcher_proj, hitter_proj = init_baselines()
|
61 |
|
62 |
-
tab1, tab2, tab3, tab4 = st.tabs(["Pitcher Projections", "Hitter Projections", "Pitcher Simulations", "Hitter Simulations"])
|
63 |
|
64 |
with tab1:
|
65 |
if st.button("Reset Data", key='reset1'):
|
66 |
st.cache_data.clear()
|
67 |
-
pitcher_proj, hitter_proj = init_baselines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
raw_frame = pitcher_proj.copy()
|
69 |
export_frame_sp = raw_frame[['Name', 'Team', 'TBF', 'Ceiling_var', 'True_AVG', 'Hits', 'Singles%', 'Singles', 'Doubles%', 'Doubles', 'xHR%', 'Homeruns', 'Strikeout%', 'Strikeouts',
|
70 |
'Walk%', 'Walks', 'Runs%', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
@@ -80,14 +104,14 @@ with tab1:
|
|
80 |
key='pitcher_proj_export',
|
81 |
)
|
82 |
|
83 |
-
with
|
84 |
-
if st.button("Reset Data", key='
|
85 |
st.cache_data.clear()
|
86 |
-
pitcher_proj, hitter_proj = init_baselines()
|
87 |
raw_frame = hitter_proj.copy()
|
88 |
-
export_frame_h = raw_frame[['Name', '
|
89 |
'xHR%', 'Homeruns', 'Runs%', 'Runs', 'RBI%', 'RBI', 'Steal%', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
90 |
-
disp_frame = raw_frame[['Name', '
|
91 |
'Homeruns', 'Runs', 'RBI', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
92 |
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
93 |
|
@@ -99,10 +123,10 @@ with tab2:
|
|
99 |
key='hitter_proj_export',
|
100 |
)
|
101 |
|
102 |
-
with
|
103 |
-
if st.button("Reset Data", key='
|
104 |
st.cache_data.clear()
|
105 |
-
pitcher_proj, hitter_proj = init_baselines()
|
106 |
col1, col2 = st.columns([1, 5])
|
107 |
|
108 |
with col2:
|
@@ -184,10 +208,10 @@ with tab3:
|
|
184 |
df_hold_container = st.empty()
|
185 |
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
186 |
|
187 |
-
with
|
188 |
-
if st.button("Reset Data", key='
|
189 |
st.cache_data.clear()
|
190 |
-
pitcher_proj, hitter_proj = init_baselines()
|
191 |
col1, col2 = st.columns([1, 5])
|
192 |
|
193 |
with col2:
|
@@ -195,6 +219,7 @@ with tab4:
|
|
195 |
|
196 |
with col1:
|
197 |
prop_type_var_h = st.selectbox('Select type of prop to simulate', options = ['Hits', 'Doubles', 'Home Runs', 'RBI', 'Stolen Bases'], key='prop_type_var_h')
|
|
|
198 |
|
199 |
if st.button('Simulate Stat', key='sim_h'):
|
200 |
with col2:
|
|
|
39 |
|
40 |
master_hold = 'https://docs.google.com/spreadsheets/d/1D526UlXmrz-8qxVcUKrA-u7f6FftUiBufxDnzQv980k/edit#gid=791804525'
|
41 |
|
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 |
+
@st.cache_resource(ttl = 600)
|
46 |
def init_baselines():
|
47 |
sh = gcservice_account.open_by_url(master_hold)
|
48 |
worksheet = sh.worksheet('Pitcher_Proj')
|
|
|
54 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
55 |
hitter_proj = raw_display.dropna()
|
56 |
|
57 |
+
sh = gcservice_account.open_by_url(master_hold)
|
58 |
+
worksheet = sh.worksheet('Wins_Proj')
|
59 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
60 |
+
wins_proj = raw_display.dropna()
|
61 |
+
|
62 |
+
return pitcher_proj, hitter_proj, wins_proj
|
63 |
|
64 |
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(["Pitcher Projections", "Hitter Projections", "Pitcher Simulations", "Hitter Simulations"])
|
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",
|
82 |
+
data=convert_df_to_csv(export_frame_team),
|
83 |
+
file_name='MLB_team_win_export.csv',
|
84 |
+
mime='text/csv',
|
85 |
+
key='team_win_export',
|
86 |
+
)
|
87 |
+
|
88 |
+
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']]
|
|
|
104 |
key='pitcher_proj_export',
|
105 |
)
|
106 |
|
107 |
+
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 |
+
disp_frame = raw_frame[['Name', 'Team', 'PA', 'Walks', 'xHits', 'Singles', 'Doubles',
|
115 |
'Homeruns', 'Runs', 'RBI', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
116 |
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
117 |
|
|
|
123 |
key='hitter_proj_export',
|
124 |
)
|
125 |
|
126 |
+
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:
|
|
|
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:
|
|
|
219 |
|
220 |
with col1:
|
221 |
prop_type_var_h = st.selectbox('Select type of prop to simulate', options = ['Hits', 'Doubles', 'Home Runs', 'RBI', 'Stolen Bases'], key='prop_type_var_h')
|
222 |
+
|
223 |
|
224 |
if st.button('Simulate Stat', key='sim_h'):
|
225 |
with col2:
|