Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,174 +42,154 @@ def init_conn():
|
|
42 |
|
43 |
gcservice_account, client, db = init_conn()
|
44 |
|
45 |
-
NBA_Data = 'https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=1808117109'
|
46 |
-
|
47 |
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
48 |
|
49 |
@st.cache_resource(ttl = 599)
|
50 |
def init_baselines():
|
51 |
-
|
52 |
-
collection = db["gamelog"]
|
53 |
cursor = collection.find() # Finds all documents in the collection
|
54 |
|
55 |
raw_display = pd.DataFrame(list(cursor))
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
'passes', 'secondaryAssists', 'freeThrowAssists', 'assists', 'STL', 'BLK', 'TOV', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy', 'FPPM']]
|
60 |
-
gamelog_table['assists'].replace("", 0, inplace=True)
|
61 |
-
gamelog_table['reboundChancesTotal'].replace("", 0, inplace=True)
|
62 |
-
gamelog_table['passes'].replace("", 0, inplace=True)
|
63 |
-
gamelog_table['touches'].replace("", 0, inplace=True)
|
64 |
-
gamelog_table['MIN'].replace("", 0, inplace=True)
|
65 |
-
gamelog_table['Fantasy'].replace("", 0, inplace=True)
|
66 |
-
gamelog_table['FD_Fantasy'].replace("", 0, inplace=True)
|
67 |
-
gamelog_table['FPPM'].replace("", 0, inplace=True)
|
68 |
-
gamelog_table['REB'] = gamelog_table['REB'].astype(int)
|
69 |
-
gamelog_table['assists'] = gamelog_table['assists'].astype(int)
|
70 |
-
gamelog_table['reboundChancesTotal'] = gamelog_table['reboundChancesTotal'].astype(int)
|
71 |
-
gamelog_table['passes'] = gamelog_table['passes'].astype(int)
|
72 |
-
gamelog_table['touches'] = gamelog_table['touches'].astype(int)
|
73 |
-
gamelog_table['MIN'] = gamelog_table['MIN'].astype(int)
|
74 |
-
gamelog_table['Fantasy'] = gamelog_table['Fantasy'].astype(float)
|
75 |
-
gamelog_table['FD_Fantasy'] = gamelog_table['FD_Fantasy'].astype(float)
|
76 |
-
gamelog_table['FPPM'] = gamelog_table['FPPM'].astype(float)
|
77 |
-
gamelog_table['rebound%'] = gamelog_table['REB'] / gamelog_table['reboundChancesTotal']
|
78 |
-
gamelog_table['assists_per_pass'] = gamelog_table['assists'] / gamelog_table['passes']
|
79 |
-
gamelog_table['Touch_per_min'] = gamelog_table['touches'] / gamelog_table['MIN']
|
80 |
-
gamelog_table['Fantasy_per_touch'] = gamelog_table['Fantasy'] / gamelog_table['touches']
|
81 |
-
gamelog_table['FD_Fantasy_per_touch'] = gamelog_table['FD_Fantasy'] / gamelog_table['touches']
|
82 |
-
data_cols = gamelog_table.columns.drop(['PLAYER_NAME', 'POS', 'TEAM_NAME', 'OPP_NAME', 'SEASON_ID', 'GAME_DATE', 'MATCHUP'])
|
83 |
-
gamelog_table[data_cols] = gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
84 |
-
gamelog_table['team_score'] = gamelog_table.groupby(['TEAM_NAME', 'GAME_ID'], sort=False)['PTS'].transform('sum')
|
85 |
-
gamelog_table['opp_score'] = gamelog_table.groupby(['GAME_ID'], sort=False)['PTS'].transform('sum') - gamelog_table['team_score']
|
86 |
-
gamelog_table['spread'] = (gamelog_table['opp_score'] - gamelog_table['team_score']).abs()
|
87 |
-
gamelog_table['GAME_DATE'] = pd.to_datetime(gamelog_table['GAME_DATE']).dt.date
|
88 |
-
|
89 |
-
spread_dict = dict(zip(gamelog_table['GAME_ID'], gamelog_table['spread']))
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy', 'FPPM',
|
94 |
-
'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch', 'team_score', 'opp_score', 'spread'], axis=1)
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
raw_display.columns = raw_display.iloc[0]
|
99 |
-
raw_display = raw_display[1:]
|
100 |
-
raw_display = raw_display.reset_index(drop=True)
|
101 |
-
rot_table = raw_display[raw_display['Player'] != ""]
|
102 |
-
rot_table = rot_table[['Player', 'Team', 'PG', 'SG', 'SF', 'PF', 'C', 'Given Pos']]
|
103 |
-
data_cols = ['PG', 'SG', 'SF', 'PF', 'C']
|
104 |
-
rot_table[data_cols] = rot_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
105 |
-
rot_table = rot_table[rot_table['Player'] != 0]
|
106 |
|
107 |
collection = db["rotations"]
|
108 |
cursor = collection.find() # Finds all documents in the collection
|
109 |
|
110 |
raw_display = pd.DataFrame(list(cursor))
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
-
timestamp =
|
119 |
|
120 |
-
return
|
121 |
|
122 |
@st.cache_data(show_spinner=False)
|
123 |
-
def
|
124 |
-
season_long_table = data_sample[['Player', '
|
125 |
-
season_long_table['
|
126 |
-
season_long_table['
|
127 |
-
season_long_table['
|
128 |
-
|
129 |
-
season_long_table['
|
130 |
-
season_long_table['
|
131 |
-
season_long_table['
|
132 |
-
season_long_table['
|
133 |
-
|
134 |
-
season_long_table['
|
135 |
-
season_long_table['
|
136 |
-
season_long_table['
|
137 |
-
|
138 |
-
season_long_table['
|
139 |
-
season_long_table['
|
140 |
-
season_long_table['
|
141 |
-
|
142 |
-
season_long_table['
|
143 |
-
season_long_table['
|
144 |
-
season_long_table['
|
145 |
-
season_long_table['
|
146 |
-
season_long_table['
|
147 |
-
season_long_table['
|
148 |
-
season_long_table['
|
149 |
-
season_long_table['
|
150 |
-
season_long_table['
|
151 |
-
season_long_table['
|
152 |
-
season_long_table['
|
153 |
-
season_long_table['Blk'] = data_sample.groupby(['Player', 'Season'], sort=False)['Blk'].transform('mean').astype(float)
|
154 |
-
season_long_table['Tov'] = data_sample.groupby(['Player', 'Season'], sort=False)['Tov'].transform('mean').astype(float)
|
155 |
-
season_long_table['PF'] = data_sample.groupby(['Player', 'Season'], sort=False)['PF'].transform('mean').astype(float)
|
156 |
-
season_long_table['DD'] = data_sample.groupby(['Player', 'Season'], sort=False)['DD'].transform('mean').astype(float)
|
157 |
-
season_long_table['TD'] = data_sample.groupby(['Player', 'Season'], sort=False)['TD'].transform('mean').astype(float)
|
158 |
-
season_long_table['Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('mean').astype(float)
|
159 |
-
season_long_table['FD_Fantasy'] = data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('mean').astype(float)
|
160 |
-
season_long_table['FPPM'] = data_sample.groupby(['Player', 'Season'], sort=False)['FPPM'].transform('mean').astype(float)
|
161 |
-
season_long_table['Rebound%'] = (data_sample.groupby(['Player', 'Season'], sort=False)['REB'].transform('sum').astype(int) /
|
162 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['REB Chance'].transform('sum').astype(int))
|
163 |
-
season_long_table['Assists/Pass'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Assists'].transform('sum').astype(int) /
|
164 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Passes'].transform('sum').astype(int))
|
165 |
-
season_long_table['Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['Fantasy'].transform('sum').astype(int) /
|
166 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
167 |
-
season_long_table['FD Fantasy/Touch'] = (data_sample.groupby(['Player', 'Season'], sort=False)['FD_Fantasy'].transform('sum').astype(int) /
|
168 |
-
data_sample.groupby(['Player', 'Season'], sort=False)['Touches'].transform('sum').astype(int))
|
169 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
170 |
|
171 |
-
season_long_table = season_long_table.sort_values(by='
|
172 |
|
173 |
-
season_long_table = season_long_table.set_axis(['Player', '
|
174 |
-
'
|
175 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
176 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch'], axis=1)
|
177 |
|
178 |
return season_long_table
|
179 |
|
180 |
@st.cache_data(show_spinner=False)
|
181 |
-
def
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
-
|
198 |
-
def run_min_corr(data_sample):
|
199 |
-
cor_testing = data_sample
|
200 |
-
cor_testing = cor_testing[cor_testing['Season'] == '22023']
|
201 |
-
date_list = cor_testing['Date'].unique().tolist()
|
202 |
-
player_list = cor_testing['Player'].unique().tolist()
|
203 |
-
corr_frame = pd.DataFrame()
|
204 |
-
corr_frame['DATE'] = date_list
|
205 |
-
for player in player_list:
|
206 |
-
player_testing = cor_testing[cor_testing['Player'] == player]
|
207 |
-
fantasy_map = dict(zip(player_testing['Date'], player_testing['Min']))
|
208 |
-
corr_frame[player] = corr_frame['DATE'].map(fantasy_map)
|
209 |
-
players_fantasy = corr_frame.drop('DATE', axis=1)
|
210 |
-
corrM = players_fantasy.corr()
|
211 |
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
@st.cache_data(show_spinner=False)
|
215 |
def split_frame(input_df, rows):
|
@@ -219,31 +199,38 @@ def split_frame(input_df, rows):
|
|
219 |
def convert_df_to_csv(df):
|
220 |
return df.to_csv().encode('utf-8')
|
221 |
|
222 |
-
|
223 |
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
total_teams = indv_teams.Team.values.tolist()
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
total_players = indv_players.Player.values.tolist()
|
244 |
-
total_dates = gamelog_table.Date.values.tolist()
|
245 |
|
246 |
-
tab1, tab2
|
247 |
|
248 |
with tab1:
|
249 |
st.info(t_stamp)
|
@@ -251,28 +238,36 @@ with tab1:
|
|
251 |
with col1:
|
252 |
if st.button("Reset Data", key='reset1'):
|
253 |
st.cache_data.clear()
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
'
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
total_teams = indv_teams.Team.values.tolist()
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
total_players = indv_players.Player.values.tolist()
|
275 |
-
total_dates = gamelog_table.Date.values.tolist()
|
276 |
|
277 |
split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
|
278 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
@@ -292,58 +287,46 @@ with tab1:
|
|
292 |
if high_date is not None:
|
293 |
high_date = pd.to_datetime(high_date).date()
|
294 |
elif split_var3 == 'All':
|
295 |
-
low_date =
|
296 |
-
high_date =
|
297 |
|
298 |
split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='split_var4')
|
299 |
|
300 |
if split_var4 == 'Specific Players':
|
301 |
-
player_var1 = st.multiselect('Which players would you like to include in the tables?', options =
|
302 |
elif split_var4 == 'All':
|
303 |
-
player_var1 =
|
304 |
-
|
305 |
-
spread_var1 = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='spread_var1')
|
306 |
-
|
307 |
-
min_var1 = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='min_var1')
|
308 |
|
309 |
with col2:
|
310 |
-
working_data =
|
311 |
if split_var1 == 'Season Logs':
|
312 |
choose_cols = st.container()
|
313 |
with choose_cols:
|
314 |
-
choose_disp = st.multiselect('Which stats would you like to view?', options =
|
315 |
disp_stats = basic_season_cols + choose_disp
|
316 |
display = st.container()
|
317 |
working_data = working_data[working_data['Date'] >= low_date]
|
318 |
working_data = working_data[working_data['Date'] <= high_date]
|
319 |
-
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
320 |
-
working_data = working_data[working_data['Min'] <= min_var1[1]]
|
321 |
-
working_data = working_data[working_data['spread'] >= spread_var1[0]]
|
322 |
-
working_data = working_data[working_data['spread'] <= spread_var1[1]]
|
323 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
324 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
325 |
-
season_long_table =
|
326 |
season_long_table = season_long_table.set_index('Player')
|
327 |
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
328 |
display.dataframe(season_long_table_disp.style.format(precision=2), height=750, use_container_width = True)
|
329 |
st.download_button(
|
330 |
-
label="Export seasonlogs Model",
|
331 |
data=convert_df_to_csv(season_long_table),
|
332 |
-
file_name='
|
333 |
mime='text/csv',
|
334 |
)
|
335 |
|
336 |
elif split_var1 == 'Gamelogs':
|
337 |
choose_cols = st.container()
|
338 |
with choose_cols:
|
339 |
-
choose_disp_gamelog = st.multiselect('Which stats would you like to view?', options =
|
340 |
gamelog_disp_stats = basic_cols + choose_disp_gamelog
|
341 |
working_data = working_data[working_data['Date'] >= low_date]
|
342 |
working_data = working_data[working_data['Date'] <= high_date]
|
343 |
-
working_data = working_data[working_data['Min'] >= min_var1[0]]
|
344 |
-
working_data = working_data[working_data['Min'] <= min_var1[1]]
|
345 |
-
working_data = working_data[working_data['spread'] >= spread_var1[0]]
|
346 |
-
working_data = working_data[working_data['spread'] <= spread_var1[1]]
|
347 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
348 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
349 |
working_data = working_data.reset_index(drop=True)
|
@@ -368,369 +351,133 @@ with tab1:
|
|
368 |
# pages = pages.set_index('Player')
|
369 |
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
370 |
st.download_button(
|
371 |
-
label="Export gamelogs
|
372 |
data=convert_df_to_csv(gamelog_data),
|
373 |
-
file_name='
|
374 |
mime='text/csv',
|
375 |
)
|
376 |
-
|
377 |
with tab2:
|
378 |
st.info(t_stamp)
|
379 |
col1, col2 = st.columns([1, 9])
|
380 |
with col1:
|
381 |
if st.button("Reset Data", key='reset2'):
|
382 |
st.cache_data.clear()
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
'
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
total_teams = indv_teams.Team.values.tolist()
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
total_players = indv_players.Player.values.tolist()
|
404 |
-
total_dates = gamelog_table.Date.values.tolist()
|
405 |
-
|
406 |
-
corr_var = st.radio("Are you correlating fantasy or minutes?", ('Fantasy', 'Minutes'), key='corr_var')
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
if split_var1_t2 == 'Specific Teams':
|
411 |
-
corr_var1_t2 = st.multiselect('Which teams would you like to include in the correlation?', options = total_teams, key='corr_var1_t2')
|
412 |
-
elif split_var1_t2 == 'Specific Players':
|
413 |
-
corr_var1_t2 = st.multiselect('Which players would you like to include in the correlation?', options = total_players, key='corr_var1_t2')
|
414 |
-
|
415 |
-
split_var2_t2 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='split_var3_t2')
|
416 |
|
417 |
-
if
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
high_date_t2 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date_t2')
|
422 |
-
if high_date_t2 is not None:
|
423 |
-
high_date_t2 = pd.to_datetime(high_date_t2).date()
|
424 |
-
elif split_var2_t2 == 'All':
|
425 |
-
low_date_t2 = gamelog_table['Date'].min()
|
426 |
-
high_date_t2 = gamelog_table['Date'].max()
|
427 |
|
428 |
-
|
429 |
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
working_data = working_data[working_data['Min'] <= min_var1_t2[1]]
|
441 |
-
working_data = working_data[working_data['spread'] >= spread_var1_t2[0]]
|
442 |
-
working_data = working_data[working_data['spread'] <= spread_var1_t2[1]]
|
443 |
-
working_data = working_data[working_data['Team'].isin(corr_var1_t2)]
|
444 |
-
if corr_var == 'Fantasy':
|
445 |
-
corr_display = run_fantasy_corr(working_data)
|
446 |
-
elif corr_var == 'Minutes':
|
447 |
-
corr_display = run_min_corr(working_data)
|
448 |
-
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=1000, use_container_width = True)
|
449 |
-
|
450 |
-
elif split_var1_t2 == 'Specific Players':
|
451 |
-
display = st.container()
|
452 |
-
working_data = working_data.sort_values(by='Fantasy', ascending=False)
|
453 |
-
working_data = working_data[working_data['Date'] >= low_date_t2]
|
454 |
-
working_data = working_data[working_data['Date'] <= high_date_t2]
|
455 |
-
working_data = working_data[working_data['Min'] >= min_var1_t2[0]]
|
456 |
-
working_data = working_data[working_data['Min'] <= min_var1_t2[1]]
|
457 |
-
working_data = working_data[working_data['spread'] >= spread_var1_t2[0]]
|
458 |
-
working_data = working_data[working_data['spread'] <= spread_var1_t2[1]]
|
459 |
-
working_data = working_data[working_data['Player'].isin(corr_var1_t2)]
|
460 |
-
if corr_var == 'Fantasy':
|
461 |
-
corr_display = run_fantasy_corr(working_data)
|
462 |
-
elif corr_var == 'Minutes':
|
463 |
-
corr_display = run_min_corr(working_data)
|
464 |
-
display.dataframe(corr_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
465 |
-
st.download_button(
|
466 |
-
label="Export Correlations Model",
|
467 |
-
data=convert_df_to_csv(corr_display),
|
468 |
-
file_name='Correlations_NBA_View.csv',
|
469 |
-
mime='text/csv',
|
470 |
-
)
|
471 |
-
|
472 |
-
with tab3:
|
473 |
-
st.info(t_stamp)
|
474 |
-
col1, col2 = st.columns([1, 9])
|
475 |
-
with col1:
|
476 |
-
if st.button("Reset Data", key='reset3'):
|
477 |
-
st.cache_data.clear()
|
478 |
-
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
479 |
-
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
480 |
-
basic_season_cols = ['Pos', 'Team', 'Min']
|
481 |
-
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
482 |
-
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
483 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
484 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
485 |
-
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
486 |
-
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
487 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
488 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
489 |
-
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
490 |
-
'Fantasy', 'FD_Fantasy']
|
491 |
-
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
492 |
-
total_teams = indv_teams.Team.values.tolist()
|
493 |
-
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
494 |
-
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
495 |
-
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
496 |
-
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
497 |
-
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
498 |
-
total_players = indv_players.Player.values.tolist()
|
499 |
-
total_dates = gamelog_table.Date.values.tolist()
|
500 |
-
|
501 |
-
team_var3 = st.selectbox('Which opponent would you like to view?', options = total_teams, key='team_var3')
|
502 |
-
pos_var3 = st.selectbox('Which position would you like to view?', options = ['PG', 'SG', 'SF', 'PF', 'C'], key='pos_var3')
|
503 |
-
disp_var3 = st.radio('Which view would you like to see?', options = ['Fantasy', 'Stats'], key='disp_var3')
|
504 |
-
date_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='date_var3')
|
505 |
-
|
506 |
-
if date_var3 == 'Specific Dates':
|
507 |
-
low_date3 = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='low_date3')
|
508 |
-
if low_date3 is not None:
|
509 |
-
low_date3 = pd.to_datetime(low_date3).date()
|
510 |
-
high_date3 = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='high_date3')
|
511 |
-
if high_date3 is not None:
|
512 |
-
high_date3 = pd.to_datetime(high_date3).date()
|
513 |
-
elif date_var3 == 'All':
|
514 |
-
low_date3 = gamelog_table['Date'].min()
|
515 |
-
high_date3 = gamelog_table['Date'].max()
|
516 |
|
517 |
-
|
518 |
|
519 |
-
|
|
|
|
|
|
|
520 |
|
521 |
with col2:
|
522 |
-
|
|
|
523 |
choose_cols = st.container()
|
524 |
with choose_cols:
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
533 |
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
gamelog_data = working_data.reindex(
|
545 |
-
|
546 |
-
gamelog_display['Avg_Fantasy'] = gamelog_display['Player'].map(fantasy_dict)
|
547 |
-
gamelog_display['Avg_FD_Fantasy'] = gamelog_display['Player'].map(fd_fantasy_dict)
|
548 |
-
display = st.container()
|
549 |
-
|
550 |
-
# pages = pages.set_index('Player')
|
551 |
-
display.dataframe(gamelog_display.style.format(precision=2), height=500, use_container_width=True)
|
552 |
-
st.download_button(
|
553 |
-
label="Export Matchups Model",
|
554 |
-
data=convert_df_to_csv(gamelog_display),
|
555 |
-
file_name='Matchups_NBA_View.csv',
|
556 |
-
mime='text/csv',
|
557 |
-
)
|
558 |
-
|
559 |
-
with tab4:
|
560 |
-
st.info(t_stamp)
|
561 |
-
col1, col2 = st.columns([1, 9])
|
562 |
-
with col1:
|
563 |
-
if st.button("Reset Data", key='reset4'):
|
564 |
-
st.cache_data.clear()
|
565 |
-
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
566 |
-
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
567 |
-
basic_season_cols = ['Pos', 'Team', 'Min']
|
568 |
-
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
569 |
-
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
570 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
571 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
572 |
-
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
573 |
-
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
574 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
575 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
576 |
-
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
577 |
-
'Fantasy', 'FD_Fantasy']
|
578 |
-
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
579 |
-
total_teams = indv_teams.Team.values.tolist()
|
580 |
-
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
581 |
-
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
582 |
-
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
583 |
-
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
584 |
-
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
585 |
-
total_players = indv_players.Player.values.tolist()
|
586 |
-
total_dates = gamelog_table.Date.values.tolist()
|
587 |
-
|
588 |
-
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
589 |
-
|
590 |
-
if split_var5 == 'Specific Teams':
|
591 |
-
team_var4 = st.multiselect('Which teams would you like to view?', options = total_rot_teams, key='team_var4')
|
592 |
-
elif split_var5 == 'All':
|
593 |
-
team_var4 = total_rot_teams
|
594 |
-
|
595 |
-
|
596 |
-
with col2:
|
597 |
-
working_data = rot_table
|
598 |
-
rot_display = working_data[working_data['Team'].isin(team_var4)]
|
599 |
-
display = st.container()
|
600 |
-
|
601 |
-
# rot_display = rot_display.set_index('Player')
|
602 |
-
display.dataframe(rot_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), height=500, use_container_width=True)
|
603 |
-
st.download_button(
|
604 |
-
label="Export Rotations Model",
|
605 |
-
data=convert_df_to_csv(rot_display),
|
606 |
-
file_name='Rotations_NBA_View.csv',
|
607 |
-
mime='text/csv',
|
608 |
-
)
|
609 |
-
|
610 |
-
with tab5:
|
611 |
-
st.info(t_stamp)
|
612 |
-
col1, col2 = st.columns([1, 9])
|
613 |
-
with col1:
|
614 |
-
if st.button("Reset Data", key='reset5'):
|
615 |
-
st.cache_data.clear()
|
616 |
-
gamelog_table, rot_table, game_rot, timestamp = init_baselines()
|
617 |
-
basic_cols = ['Player', 'Pos', 'Team', 'Opp', 'Season', 'Date', 'Matchup', 'Min']
|
618 |
-
basic_season_cols = ['Pos', 'Team', 'Min']
|
619 |
-
data_cols = ['team_score', 'opp_score', 'spread', 'Touches', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M',
|
620 |
-
'FG3A', 'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
621 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
622 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Touch_per_min', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
623 |
-
season_data_cols = ['Touches', 'Touch/Min', 'Pts', 'FGM', 'FGA', 'FG%', 'FG3M', 'FG3A',
|
624 |
-
'FG3%', 'FTM', 'FTA', 'FT%', 'OREB Chance', 'OREB', 'DREB Chance', 'DREB', 'REB Chance', 'REB',
|
625 |
-
'Passes', 'Alt Assists', 'FT Assists', 'Assists', 'Stl', 'Blk', 'Tov', 'PF', 'DD', 'TD', 'Fantasy', 'FD_Fantasy',
|
626 |
-
'FPPM', 'Rebound%', 'Assists/Pass', 'Fantasy/Touch', 'FD Fantasy/Touch']
|
627 |
-
game_rot_cols = ['PLAYER_NAME', 'backlog_lookup', 'spread', 'MIN', 'PTS', 'FGM', 'FGA', 'FG3M', 'FG3A', 'FTM', 'FTA', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF',
|
628 |
-
'Fantasy', 'FD_Fantasy']
|
629 |
-
indv_teams = gamelog_table.drop_duplicates(subset='Team')
|
630 |
-
total_teams = indv_teams.Team.values.tolist()
|
631 |
-
indv_rot_teams = rot_table.drop_duplicates(subset='Team')
|
632 |
-
total_rot_teams = indv_rot_teams.Team.values.tolist()
|
633 |
-
indv_game_rot_teams = game_rot.drop_duplicates(subset='TEAM_ABBREVIATION')
|
634 |
-
total_game_rot_teams = indv_game_rot_teams.TEAM_ABBREVIATION.values.tolist()
|
635 |
-
indv_players = gamelog_table.drop_duplicates(subset='Player')
|
636 |
-
total_players = indv_players.Player.values.tolist()
|
637 |
-
total_dates = gamelog_table.Date.values.tolist()
|
638 |
-
|
639 |
-
game_rot_view = st.radio("What set would you like to view?", ('Team Rotations', 'Player Rotations'), key='game_rot_view')
|
640 |
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
game_rot_low_date = pd.to_datetime(low_date).date()
|
654 |
-
game_rot_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='game_rot_high_date')
|
655 |
-
if game_rot_high_date is not None:
|
656 |
-
game_rot_high_date = pd.to_datetime(high_date).date()
|
657 |
-
elif game_rot_dates == 'All':
|
658 |
-
game_rot_low_date = gamelog_table['Date'].min()
|
659 |
-
game_rot_high_date = gamelog_table['Date'].max()
|
660 |
-
elif game_rot_view == 'Player Rotations':
|
661 |
-
game_rot_team = st.multiselect("What players would you like to work with?", options = total_players, key='game_rot_team')
|
662 |
-
|
663 |
-
game_rot_spread = st.slider("Is there a certain spread range you want to view?", 0, 100, (0, 100), key='game_rot_spread')
|
664 |
-
|
665 |
-
game_rot_min = st.slider("Is there a certain minutes range you want to view?", 0, 60, (0, 60), key='game_rot_min')
|
666 |
-
|
667 |
-
game_rot_dates = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='game_rot_dates')
|
668 |
-
|
669 |
-
if game_rot_dates == 'Specific Dates':
|
670 |
-
game_rot_low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='game_rot_low_date')
|
671 |
-
if game_rot_low_date is not None:
|
672 |
-
game_rot_low_date = pd.to_datetime(low_date).date()
|
673 |
-
game_rot_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='game_rot_high_date')
|
674 |
-
if game_rot_high_date is not None:
|
675 |
-
game_rot_high_date = pd.to_datetime(high_date).date()
|
676 |
-
elif game_rot_dates == 'All':
|
677 |
-
game_rot_low_date = gamelog_table['Date'].min()
|
678 |
-
game_rot_high_date = gamelog_table['Date'].max()
|
679 |
-
|
680 |
|
681 |
-
with col2:
|
682 |
-
if game_rot_view == 'Player Rotations':
|
683 |
-
team_backlog = game_rot[game_rot['PLAYER_NAME'].isin(game_rot_team)]
|
684 |
-
team_backlog = team_backlog[team_backlog['GAME_DATE'] >= game_rot_low_date]
|
685 |
-
team_backlog = team_backlog[team_backlog['GAME_DATE'] <= game_rot_high_date]
|
686 |
-
team_backlog = team_backlog[team_backlog['MIN'] >= game_rot_min[0]]
|
687 |
-
team_backlog = team_backlog[team_backlog['MIN'] <= game_rot_min[1]]
|
688 |
-
team_backlog = team_backlog[team_backlog['spread'] >= game_rot_spread[0]]
|
689 |
-
team_backlog = team_backlog[team_backlog['spread'] <= game_rot_spread[1]]
|
690 |
-
working_data = game_rot
|
691 |
-
display = st.container()
|
692 |
-
stats_disp = st.container()
|
693 |
-
check_rotation = team_backlog.sort_values(by='GAME_DATE', ascending=False)
|
694 |
-
game_rot_stats = check_rotation.reindex(game_rot_cols,axis="columns")
|
695 |
-
game_rot_stats = game_rot_stats.drop_duplicates(subset='backlog_lookup')
|
696 |
-
|
697 |
-
fig = px.timeline(check_rotation, x_start="Start", x_end="Finish", y="Task", range_x=[0,check_rotation["Finish"].max()], text='minutes')
|
698 |
-
fig.update_yaxes(autorange="reversed")
|
699 |
-
|
700 |
-
fig.layout.xaxis.type = 'linear'
|
701 |
-
fig.data[0].x = check_rotation.delta.tolist()
|
702 |
-
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
703 |
-
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
704 |
-
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|
705 |
-
# pages = pages.set_index('Player')
|
706 |
-
display.plotly_chart(fig, use_container_width=True)
|
707 |
-
stats_disp.dataframe(game_rot_stats.style.format(precision=2), hide_index=True, use_container_width = True)
|
708 |
|
709 |
-
|
710 |
-
team_backlog = game_rot[game_rot['TEAM_ABBREVIATION'] == game_rot_team]
|
711 |
-
team_backlog = team_backlog[team_backlog['GAME_DATE'] >= game_rot_low_date]
|
712 |
-
team_backlog = team_backlog[team_backlog['GAME_DATE'] <= game_rot_high_date]
|
713 |
-
team_backlog = team_backlog[team_backlog['MIN'] >= game_rot_min[0]]
|
714 |
-
team_backlog = team_backlog[team_backlog['MIN'] <= game_rot_min[1]]
|
715 |
-
team_backlog = team_backlog[team_backlog['spread'] >= game_rot_spread[0]]
|
716 |
-
team_backlog = team_backlog[team_backlog['spread'] <= game_rot_spread[1]]
|
717 |
-
game_id_var = st.selectbox("What game would you like to view?", options = team_backlog['backlog_lookup'].unique(), key='game_id_var')
|
718 |
-
working_data = game_rot
|
719 |
-
display = st.container()
|
720 |
-
stats_disp = st.container()
|
721 |
-
check_rotation = working_data[working_data['backlog_lookup'] == game_id_var]
|
722 |
-
check_rotation = check_rotation.sort_values(by='Start', ascending=True)
|
723 |
-
game_rot_stats = check_rotation.reindex(game_rot_cols,axis="columns")
|
724 |
-
game_rot_stats = game_rot_stats.drop_duplicates(subset='PLAYER_NAME')
|
725 |
-
|
726 |
-
fig = px.timeline(check_rotation, x_start="Start", x_end="Finish", y="Task", range_x=[0,check_rotation["Finish"].max()], text='minutes')
|
727 |
-
fig.update_yaxes(autorange="reversed")
|
728 |
-
|
729 |
-
fig.layout.xaxis.type = 'linear'
|
730 |
-
fig.data[0].x = check_rotation.delta.tolist()
|
731 |
-
fig.add_vline(x=12, line_width=3, line_dash="dash", line_color="green")
|
732 |
-
fig.add_vline(x=24, line_width=3, line_dash="dash", line_color="green")
|
733 |
-
fig.add_vline(x=36, line_width=3, line_dash="dash", line_color="green")
|
734 |
# pages = pages.set_index('Player')
|
735 |
-
display.
|
736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
gcservice_account, client, db = init_conn()
|
44 |
|
|
|
|
|
45 |
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
46 |
|
47 |
@st.cache_resource(ttl = 599)
|
48 |
def init_baselines():
|
49 |
+
collection = db["MLB_Hitters_DB"]
|
|
|
50 |
cursor = collection.find() # Finds all documents in the collection
|
51 |
|
52 |
raw_display = pd.DataFrame(list(cursor))
|
53 |
+
hitter_gamelog_table = raw_display[raw_display['NameASCII'] != ""]
|
54 |
+
hitter_gamelog_table = hitter_gamelog_table[['NameASCII', 'Team', 'Date', 'G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
55 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
data_cols = hitter_gamelog_table.columns.drop(['NameASCII', 'Team', 'Date'])
|
58 |
+
hitter_gamelog_table[data_cols] = hitter_gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
|
|
|
|
59 |
|
60 |
+
hitter_gamelog_table = hitter_gamelog_table.set_axis(['Player', 'Team', 'Date', 'G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
61 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%'], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
collection = db["rotations"]
|
64 |
cursor = collection.find() # Finds all documents in the collection
|
65 |
|
66 |
raw_display = pd.DataFrame(list(cursor))
|
67 |
+
pitcher_gamelog_table = raw_display[raw_display['NameASCII'] != ""]
|
68 |
+
|
69 |
+
pitcher_gamelog_table = pitcher_gamelog_table[['NameASCII', 'Team', 'Date', 'G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
70 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
71 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA (sc)', 'vFT (sc)', 'vFC (sc)', 'vFS (sc)', 'vFO (sc)', 'vSI (sc)',
|
72 |
+
'vSL (sc)', 'vCU (sc)', 'vKC (sc)', 'vEP (sc)', 'vCH (sc)', 'vSC (sc)', 'vKN (sc)']]
|
73 |
+
|
74 |
+
pitcher_gamelog_table.replace("", np.nan, inplace=True)
|
75 |
+
data_cols = pitcher_gamelog_table.columns.drop(['NameASCII', 'Team', 'Date'])
|
76 |
+
pitcher_gamelog_table[data_cols] = pitcher_gamelog_table[data_cols].apply(pd.to_numeric, errors='coerce')
|
77 |
+
|
78 |
+
pitcher_gamelog_table = pitcher_gamelog_table.set_axis(['Player', 'Team', 'Date', 'G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
79 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
80 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
81 |
+
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN'], axis=1)
|
82 |
|
83 |
+
timestamp = pitcher_gamelog_table['Date'].max()
|
84 |
|
85 |
+
return hitter_gamelog_table, pitcher_gamelog_table, timestamp
|
86 |
|
87 |
@st.cache_data(show_spinner=False)
|
88 |
+
def hitter_seasonlong_build(data_sample):
|
89 |
+
season_long_table = data_sample[['Player', 'Team']]
|
90 |
+
season_long_table['G'] = data_sample.groupby(['Player', 'Team'], sort=False)['G'].transform('sum').astype(int)
|
91 |
+
season_long_table['AB'] = data_sample.groupby(['Player', 'Team'], sort=False)['AB'].transform('sum').astype(int)
|
92 |
+
season_long_table['PA'] = data_sample.groupby(['Player', 'Team'], sort=False)['PA'].transform('sum').astype(int)
|
93 |
+
season_long_table['H'] = data_sample.groupby(['Player', 'Team'], sort=False)['H'].transform('sum').astype(int)
|
94 |
+
season_long_table['1B'] = data_sample.groupby(['Player', 'Team'], sort=False)['1B'].transform('sum').astype(int)
|
95 |
+
season_long_table['2B'] = data_sample.groupby(['Player', 'Team'], sort=False)['2B'].transform('sum').astype(int)
|
96 |
+
season_long_table['3B'] = data_sample.groupby(['Player', 'Team'], sort=False)['3B'].transform('sum').astype(int)
|
97 |
+
season_long_table['HR'] = data_sample.groupby(['Player', 'Team'], sort=False)['HR'].transform('sum').astype(int)
|
98 |
+
season_long_table['R'] = data_sample.groupby(['Player', 'Team'], sort=False)['R'].transform('sum').astype(int)
|
99 |
+
season_long_table['RBI'] = data_sample.groupby(['Player', 'Team'], sort=False)['RBI'].transform('sum').astype(int)
|
100 |
+
season_long_table['BB'] = data_sample.groupby(['Player', 'Team'], sort=False)['BB'].transform('sum').astype(int)
|
101 |
+
season_long_table['IBB'] = data_sample.groupby(['Player', 'Team'], sort=False)['IBB'].transform('sum').astype(int)
|
102 |
+
season_long_table['SO'] = data_sample.groupby(['Player', 'Team'], sort=False)['SO'].transform('sum').astype(int)
|
103 |
+
season_long_table['HBP'] = data_sample.groupby(['Player', 'Team'], sort=False)['HBP'].transform('sum').astype(int)
|
104 |
+
season_long_table['SF'] = data_sample.groupby(['Player', 'Team'], sort=False)['SF'].transform('sum').astype(int)
|
105 |
+
season_long_table['SH'] = data_sample.groupby(['Player', 'Team'], sort=False)['SH'].transform('sum').astype(int)
|
106 |
+
season_long_table['GDP'] = data_sample.groupby(['Player', 'Team'], sort=False)['GDP'].transform('sum').astype(int)
|
107 |
+
season_long_table['SB'] = data_sample.groupby(['Player', 'Team'], sort=False)['SB'].transform('sum').astype(int)
|
108 |
+
season_long_table['CS'] = data_sample.groupby(['Player', 'Team'], sort=False)['CS'].transform('sum').astype(int)
|
109 |
+
season_long_table['Avg AVG'] = data_sample.groupby(['Player', 'Team'], sort=False)['AVG'].transform('mean').astype(int)
|
110 |
+
season_long_table['Avg SLG'] = data_sample.groupby(['Player', 'Team'], sort=False)['SLG'].transform('mean').astype(int)
|
111 |
+
season_long_table['Avg wRC+'] = data_sample.groupby(['Player', 'Team'], sort=False)['wRC+'].transform('mean').astype(int)
|
112 |
+
season_long_table['Avg LD%'] = data_sample.groupby(['Player', 'Team'], sort=False)['LD%'].transform('mean').astype(int)
|
113 |
+
season_long_table['Avg GB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['GB%'].transform('mean').astype(float)
|
114 |
+
season_long_table['Avg FB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['FB%'].transform('mean').astype(float)
|
115 |
+
season_long_table['Avg Hard%'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hard%'].transform('mean').astype(float)
|
116 |
+
season_long_table['Barrels'] = data_sample.groupby(['Player', 'Team'], sort=False)['Barrels'].transform('sum').astype(int)
|
117 |
+
season_long_table['Avg Barrel%'] = data_sample.groupby(['Player', 'Team'], sort=False)['Barrel%'].transform('mean').astype(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
119 |
|
120 |
+
season_long_table = season_long_table.sort_values(by='Avg wRC+', ascending=False)
|
121 |
|
122 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Date', 'G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
123 |
+
'GDP', 'SB', 'CS', 'Avg AVG', 'Avg SLG', 'Avg wRC+', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg Hard%', 'Barrels', 'Avg Barrel%'], axis=1)
|
|
|
|
|
124 |
|
125 |
return season_long_table
|
126 |
|
127 |
@st.cache_data(show_spinner=False)
|
128 |
+
def pitcher_seasonlong_build(data_sample):
|
129 |
+
season_long_table = data_sample[['Player', 'Team']]
|
130 |
+
season_long_table['G'] = data_sample.groupby(['Player', 'Team'], sort=False)['G'].transform('sum').astype(int)
|
131 |
+
season_long_table['GS'] = data_sample.groupby(['Player', 'Team'], sort=False)['GS'].transform('sum').astype(int)
|
132 |
+
season_long_table['CG'] = data_sample.groupby(['Player', 'Team'], sort=False)['CG'].transform('sum').astype(int)
|
133 |
+
season_long_table['W'] = data_sample.groupby(['Player', 'Team'], sort=False)['W'].transform('sum').astype(int)
|
134 |
+
season_long_table['L'] = data_sample.groupby(['Player', 'Team'], sort=False)['L'].transform('sum').astype(int)
|
135 |
+
season_long_table['Avg ERA'] = data_sample.groupby(['Player', 'Team'], sort=False)['ERA'].transform('mean').astype(float)
|
136 |
+
season_long_table['ShO'] = data_sample.groupby(['Player', 'Team'], sort=False)['ShO'].transform('sum').astype(int)
|
137 |
+
season_long_table['SV'] = data_sample.groupby(['Player', 'Team'], sort=False)['SV'].transform('sum').astype(int)
|
138 |
+
season_long_table['HLD'] = data_sample.groupby(['Player', 'Team'], sort=False)['HLD'].transform('sum').astype(int)
|
139 |
+
season_long_table['BS'] = data_sample.groupby(['Player', 'Team'], sort=False)['BS'].transform('sum').astype(int)
|
140 |
+
season_long_table['IP'] = data_sample.groupby(['Player', 'Team'], sort=False)['IP'].transform('sum').astype(int)
|
141 |
+
season_long_table['TBF'] = data_sample.groupby(['Player', 'Team'], sort=False)['TBF'].transform('sum').astype(int)
|
142 |
+
season_long_table['H'] = data_sample.groupby(['Player', 'Team'], sort=False)['H'].transform('sum').astype(int)
|
143 |
+
season_long_table['R'] = data_sample.groupby(['Player', 'Team'], sort=False)['R'].transform('sum').astype(int)
|
144 |
+
season_long_table['ER'] = data_sample.groupby(['Player', 'Team'], sort=False)['ER'].transform('sum').astype(int)
|
145 |
+
season_long_table['HR'] = data_sample.groupby(['Player', 'Team'], sort=False)['HR'].transform('sum').astype(int)
|
146 |
+
season_long_table['BB'] = data_sample.groupby(['Player', 'Team'], sort=False)['BB'].transform('sum').astype(int)
|
147 |
+
season_long_table['IBB'] = data_sample.groupby(['Player', 'Team'], sort=False)['IBB'].transform('sum').astype(int)
|
148 |
+
season_long_table['HBP'] = data_sample.groupby(['Player', 'Team'], sort=False)['HBP'].transform('sum').astype(int)
|
149 |
+
season_long_table['WP'] = data_sample.groupby(['Player', 'Team'], sort=False)['WP'].transform('sum').astype(int)
|
150 |
+
season_long_table['BK'] = data_sample.groupby(['Player', 'Team'], sort=False)['BK'].transform('sum').astype(int)
|
151 |
+
season_long_table['SO'] = data_sample.groupby(['Player', 'Team'], sort=False)['SO'].transform('sum').astype(int)
|
152 |
+
season_long_table['Avg K/9'] = data_sample.groupby(['Player', 'Team'], sort=False)['K/9'].transform('mean').astype(float)
|
153 |
+
season_long_table['Avg BB/9'] = data_sample.groupby(['Player', 'Team'], sort=False)['BB/9'].transform('mean').astype(float)
|
154 |
+
season_long_table['Avg WHIP'] = data_sample.groupby(['Player', 'Team'], sort=False)['WHIP'].transform('mean').astype(float)
|
155 |
+
season_long_table['Avg BABIP'] = data_sample.groupby(['Player', 'Team'], sort=False)['BABIP'].transform('mean').astype(float)
|
156 |
+
season_long_table['Avg LOB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['LOB%'].transform('mean').astype(int)
|
157 |
+
season_long_table['Avg FIP'] = data_sample.groupby(['Player', 'Team'], sort=False)['FIP'].transform('mean').astype(float)
|
158 |
+
season_long_table['Avg xFIP'] = data_sample.groupby(['Player', 'Team'], sort=False)['xFIP'].transform('mean').astype(float)
|
159 |
+
season_long_table['Avg K%'] = data_sample.groupby(['Player', 'Team'], sort=False)['K%'].transform('mean').astype(float)
|
160 |
+
season_long_table['Avg BB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['BB%'].transform('mean').astype(float)
|
161 |
+
season_long_table['Avg SIERA'] = data_sample.groupby(['Player', 'Team'], sort=False)['SIERA'].transform('mean').astype(float)
|
162 |
+
season_long_table['Avg LD%'] = data_sample.groupby(['Player', 'Team'], sort=False)['LD%'].transform('mean').astype(float)
|
163 |
+
season_long_table['Avg GB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['GB%'].transform('mean').astype(float)
|
164 |
+
season_long_table['Avg FB%'] = data_sample.groupby(['Player', 'Team'], sort=False)['FB%'].transform('mean').astype(float)
|
165 |
+
season_long_table['Avg HR/FB'] = data_sample.groupby(['Player', 'Team'], sort=False)['HR/FB'].transform('mean').astype(float)
|
166 |
+
season_long_table['Avg Hard%'] = data_sample.groupby(['Player', 'Team'], sort=False)['Hard%'].transform('mean').astype(float)
|
167 |
+
season_long_table['Barrels'] = data_sample.groupby(['Player', 'Team'], sort=False)['Barrels'].transform('sum').astype(int)
|
168 |
+
season_long_table['Avg Barrel%'] = data_sample.groupby(['Player', 'Team'], sort=False)['Barrel%'].transform('mean').astype(float)
|
169 |
+
season_long_table['Avg xERA'] = data_sample.groupby(['Player', 'Team'], sort=False)['xERA'].transform('mean').astype(float)
|
170 |
+
season_long_table['Avg vFA'] = data_sample.groupby(['Player', 'Team'], sort=False)['vFA'].transform('mean').astype(float)
|
171 |
+
season_long_table['Avg vFT'] = data_sample.groupby(['Player', 'Team'], sort=False)['vFT'].transform('mean').astype(float)
|
172 |
+
season_long_table['Avg vFC'] = data_sample.groupby(['Player', 'Team'], sort=False)['vFC'].transform('mean').astype(float)
|
173 |
+
season_long_table['Avg vFS'] = data_sample.groupby(['Player', 'Team'], sort=False)['vFS'].transform('mean').astype(float)
|
174 |
+
season_long_table['Avg vFO'] = data_sample.groupby(['Player', 'Team'], sort=False)['vFO'].transform('mean').astype(float)
|
175 |
+
season_long_table['Avg vSI'] = data_sample.groupby(['Player', 'Team'], sort=False)['vSI'].transform('mean').astype(float)
|
176 |
+
season_long_table['Avg vSL'] = data_sample.groupby(['Player', 'Team'], sort=False)['vSL'].transform('mean').astype(float)
|
177 |
+
season_long_table['Avg vCU'] = data_sample.groupby(['Player', 'Team'], sort=False)['vCU'].transform('mean').astype(float)
|
178 |
+
season_long_table['Avg vKC'] = data_sample.groupby(['Player', 'Team'], sort=False)['vKC'].transform('mean').astype(float)
|
179 |
+
season_long_table['Avg vEP'] = data_sample.groupby(['Player', 'Team'], sort=False)['vEP'].transform('mean').astype(float)
|
180 |
+
season_long_table['Avg vCH'] = data_sample.groupby(['Player', 'Team'], sort=False)['vCH'].transform('mean').astype(float)
|
181 |
+
season_long_table['Avg vSC'] = data_sample.groupby(['Player', 'Team'], sort=False)['vSC'].transform('mean').astype(float)
|
182 |
+
season_long_table['Avg vKN'] = data_sample.groupby(['Player', 'Team'], sort=False)['vKN'].transform('mean').astype(float)
|
183 |
+
season_long_table = season_long_table.drop_duplicates(subset='Player')
|
184 |
|
185 |
+
season_long_table = season_long_table.sort_values(by='SO', ascending=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
+
season_long_table = season_long_table.set_axis(['Player', 'Team', 'Date', 'G', 'GS', 'CG', 'W', 'L', 'Avg ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
188 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'Avg K/9', 'Avg BB/9', 'Avg WHIP', 'Avg BABIP', 'Avg LOB%', 'Avg FIP', 'Avg xFIP', 'Avg K%',
|
189 |
+
'Avg BB%', 'Avg SIERA', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg HR/FB', 'Avg Hard%', 'Barrels', 'Avg Barrel%', 'Avg xERA', 'Avg vFA',
|
190 |
+
'Avg vFT', 'Avg vFC', 'Avg vFS', 'Avg vFO', 'Avg vSI', 'Avg vSL', 'Avg vCU', 'Avg vKC', 'Avg vEP', 'Avg vCH', 'Avg vSC', 'Avg vKN'], axis=1)
|
191 |
+
|
192 |
+
return season_long_table
|
193 |
|
194 |
@st.cache_data(show_spinner=False)
|
195 |
def split_frame(input_df, rows):
|
|
|
199 |
def convert_df_to_csv(df):
|
200 |
return df.to_csv().encode('utf-8')
|
201 |
|
202 |
+
hitter_gamelog_table, pitcher_gamelog_table, timestamp = init_baselines()
|
203 |
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
204 |
+
|
205 |
+
basic_cols = ['Player', 'Team']
|
206 |
+
|
207 |
+
basic_season_cols = ['Team']
|
208 |
+
|
209 |
+
hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
210 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%']
|
211 |
+
|
212 |
+
season_hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
213 |
+
'GDP', 'SB', 'CS', 'Avg AVG', 'Avg SLG', 'Avg wRC+', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg Hard%', 'Barrels', 'Avg Barrel%']
|
214 |
+
|
215 |
+
pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
216 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
217 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
218 |
+
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN']
|
219 |
+
|
220 |
+
season_pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'Avg ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
221 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'Avg K/9', 'Avg BB/9', 'Avg WHIP', 'Avg BABIP', 'Avg LOB%', 'Avg FIP', 'Avg xFIP', 'Avg K%',
|
222 |
+
'Avg BB%', 'Avg SIERA', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg HR/FB', 'Avg Hard%', 'Barrels', 'Avg Barrel%', 'Avg xERA', 'Avg vFA',
|
223 |
+
'Avg vFT', 'Avg vFC', 'Avg vFS', 'Avg vFO', 'Avg vSI', 'Avg vSL', 'Avg vCU', 'Avg vKC', 'Avg vEP', 'Avg vCH', 'Avg vSC', 'Avg vKN']
|
224 |
+
|
225 |
+
indv_teams = hitter_gamelog_table.drop_duplicates(subset='Team')
|
226 |
total_teams = indv_teams.Team.values.tolist()
|
227 |
+
indv_hitters = hitter_gamelog_table.drop_duplicates(subset='Player')
|
228 |
+
total_hitters = indv_hitters.Player.values.tolist()
|
229 |
+
indv_pitchers = hitter_gamelog_table.drop_duplicates(subset='Player')
|
230 |
+
total_pitchers = indv_pitchers.Player.values.tolist()
|
231 |
+
total_dates = hitter_gamelog_table.Date.values.tolist()
|
|
|
|
|
232 |
|
233 |
+
tab1, tab2 = st.tabs(['Hitter Gamelogs', 'Pitcher Gamelogs'])
|
234 |
|
235 |
with tab1:
|
236 |
st.info(t_stamp)
|
|
|
238 |
with col1:
|
239 |
if st.button("Reset Data", key='reset1'):
|
240 |
st.cache_data.clear()
|
241 |
+
hitter_gamelog_table, pitcher_gamelog_table, timestamp = init_baselines()
|
242 |
+
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
243 |
+
|
244 |
+
basic_cols = ['Player', 'Team']
|
245 |
+
|
246 |
+
basic_season_cols = ['Team']
|
247 |
+
|
248 |
+
hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
249 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%']
|
250 |
+
|
251 |
+
season_hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
252 |
+
'GDP', 'SB', 'CS', 'Avg AVG', 'Avg SLG', 'Avg wRC+', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg Hard%', 'Barrels', 'Avg Barrel%']
|
253 |
+
|
254 |
+
pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
255 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
256 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
257 |
+
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN']
|
258 |
+
|
259 |
+
season_pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'Avg ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
260 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'Avg K/9', 'Avg BB/9', 'Avg WHIP', 'Avg BABIP', 'Avg LOB%', 'Avg FIP', 'Avg xFIP', 'Avg K%',
|
261 |
+
'Avg BB%', 'Avg SIERA', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg HR/FB', 'Avg Hard%', 'Barrels', 'Avg Barrel%', 'Avg xERA', 'Avg vFA',
|
262 |
+
'Avg vFT', 'Avg vFC', 'Avg vFS', 'Avg vFO', 'Avg vSI', 'Avg vSL', 'Avg vCU', 'Avg vKC', 'Avg vEP', 'Avg vCH', 'Avg vSC', 'Avg vKN']
|
263 |
+
|
264 |
+
indv_teams = hitter_gamelog_table.drop_duplicates(subset='Team')
|
265 |
total_teams = indv_teams.Team.values.tolist()
|
266 |
+
indv_hitters = hitter_gamelog_table.drop_duplicates(subset='Player')
|
267 |
+
total_hitters = indv_hitters.Player.values.tolist()
|
268 |
+
indv_pitchers = hitter_gamelog_table.drop_duplicates(subset='Player')
|
269 |
+
total_pitchers = indv_pitchers.Player.values.tolist()
|
270 |
+
total_dates = hitter_gamelog_table.Date.values.tolist()
|
|
|
|
|
271 |
|
272 |
split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='split_var1')
|
273 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
|
|
287 |
if high_date is not None:
|
288 |
high_date = pd.to_datetime(high_date).date()
|
289 |
elif split_var3 == 'All':
|
290 |
+
low_date = hitter_gamelog_table['Date'].min()
|
291 |
+
high_date = hitter_gamelog_table['Date'].max()
|
292 |
|
293 |
split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='split_var4')
|
294 |
|
295 |
if split_var4 == 'Specific Players':
|
296 |
+
player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_hitters, key='player_var1')
|
297 |
elif split_var4 == 'All':
|
298 |
+
player_var1 = total_hitters
|
|
|
|
|
|
|
|
|
299 |
|
300 |
with col2:
|
301 |
+
working_data = hitter_gamelog_table
|
302 |
if split_var1 == 'Season Logs':
|
303 |
choose_cols = st.container()
|
304 |
with choose_cols:
|
305 |
+
choose_disp = st.multiselect('Which stats would you like to view?', options = season_hitter_data_cols, default = season_hitter_data_cols, key='col_display')
|
306 |
disp_stats = basic_season_cols + choose_disp
|
307 |
display = st.container()
|
308 |
working_data = working_data[working_data['Date'] >= low_date]
|
309 |
working_data = working_data[working_data['Date'] <= high_date]
|
|
|
|
|
|
|
|
|
310 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
311 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
312 |
+
season_long_table = hitter_seasonlong_build(working_data)
|
313 |
season_long_table = season_long_table.set_index('Player')
|
314 |
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
315 |
display.dataframe(season_long_table_disp.style.format(precision=2), height=750, use_container_width = True)
|
316 |
st.download_button(
|
317 |
+
label="Export hitter seasonlogs Model",
|
318 |
data=convert_df_to_csv(season_long_table),
|
319 |
+
file_name='Seasonlogs_Hitter_View.csv',
|
320 |
mime='text/csv',
|
321 |
)
|
322 |
|
323 |
elif split_var1 == 'Gamelogs':
|
324 |
choose_cols = st.container()
|
325 |
with choose_cols:
|
326 |
+
choose_disp_gamelog = st.multiselect('Which stats would you like to view?', options = hitter_data_cols, default = hitter_data_cols, key='choose_disp_gamelog')
|
327 |
gamelog_disp_stats = basic_cols + choose_disp_gamelog
|
328 |
working_data = working_data[working_data['Date'] >= low_date]
|
329 |
working_data = working_data[working_data['Date'] <= high_date]
|
|
|
|
|
|
|
|
|
330 |
working_data = working_data[working_data['Team'].isin(team_var1)]
|
331 |
working_data = working_data[working_data['Player'].isin(player_var1)]
|
332 |
working_data = working_data.reset_index(drop=True)
|
|
|
351 |
# pages = pages.set_index('Player')
|
352 |
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
353 |
st.download_button(
|
354 |
+
label="Export hitter gamelogs model",
|
355 |
data=convert_df_to_csv(gamelog_data),
|
356 |
+
file_name='Gamelogs_Hitter_View.csv',
|
357 |
mime='text/csv',
|
358 |
)
|
359 |
+
|
360 |
with tab2:
|
361 |
st.info(t_stamp)
|
362 |
col1, col2 = st.columns([1, 9])
|
363 |
with col1:
|
364 |
if st.button("Reset Data", key='reset2'):
|
365 |
st.cache_data.clear()
|
366 |
+
hitter_gamelog_table, pitcher_gamelog_table, timestamp = init_baselines()
|
367 |
+
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
368 |
+
|
369 |
+
basic_cols = ['Player', 'Team']
|
370 |
+
|
371 |
+
basic_season_cols = ['Team']
|
372 |
+
|
373 |
+
hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
374 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%']
|
375 |
+
|
376 |
+
season_hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
377 |
+
'GDP', 'SB', 'CS', 'Avg AVG', 'Avg SLG', 'Avg wRC+', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg Hard%', 'Barrels', 'Avg Barrel%']
|
378 |
+
|
379 |
+
pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
380 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
381 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
382 |
+
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN']
|
383 |
+
|
384 |
+
season_pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'Avg ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
385 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'Avg K/9', 'Avg BB/9', 'Avg WHIP', 'Avg BABIP', 'Avg LOB%', 'Avg FIP', 'Avg xFIP', 'Avg K%',
|
386 |
+
'Avg BB%', 'Avg SIERA', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg HR/FB', 'Avg Hard%', 'Barrels', 'Avg Barrel%', 'Avg xERA', 'Avg vFA',
|
387 |
+
'Avg vFT', 'Avg vFC', 'Avg vFS', 'Avg vFO', 'Avg vSI', 'Avg vSL', 'Avg vCU', 'Avg vKC', 'Avg vEP', 'Avg vCH', 'Avg vSC', 'Avg vKN']
|
388 |
+
|
389 |
+
indv_teams = hitter_gamelog_table.drop_duplicates(subset='Team')
|
390 |
total_teams = indv_teams.Team.values.tolist()
|
391 |
+
indv_hitters = hitter_gamelog_table.drop_duplicates(subset='Player')
|
392 |
+
total_hitters = indv_hitters.Player.values.tolist()
|
393 |
+
indv_pitchers = hitter_gamelog_table.drop_duplicates(subset='Player')
|
394 |
+
total_pitchers = indv_pitchers.Player.values.tolist()
|
395 |
+
total_dates = hitter_gamelog_table.Date.values.tolist()
|
|
|
|
|
|
|
|
|
396 |
|
397 |
+
split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='sp_split_var1')
|
398 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='sp_split_var2')
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
|
400 |
+
if split_var2 == 'Specific Teams':
|
401 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='sp_team_var1')
|
402 |
+
elif split_var2 == 'All':
|
403 |
+
team_var1 = total_teams
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
|
405 |
+
split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='sp_split_var3')
|
406 |
|
407 |
+
if split_var3 == 'Specific Dates':
|
408 |
+
low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='sp_low_date')
|
409 |
+
if low_date is not None:
|
410 |
+
low_date = pd.to_datetime(low_date).date()
|
411 |
+
high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='sp_high_date')
|
412 |
+
if high_date is not None:
|
413 |
+
high_date = pd.to_datetime(high_date).date()
|
414 |
+
elif split_var3 == 'All':
|
415 |
+
low_date = hitter_gamelog_table['Date'].min()
|
416 |
+
high_date = hitter_gamelog_table['Date'].max()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
+
split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='sp_split_var4')
|
419 |
|
420 |
+
if split_var4 == 'Specific Players':
|
421 |
+
player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_hitters, key='sp_player_var1')
|
422 |
+
elif split_var4 == 'All':
|
423 |
+
player_var1 = total_hitters
|
424 |
|
425 |
with col2:
|
426 |
+
working_data = hitter_gamelog_table
|
427 |
+
if split_var1 == 'Season Logs':
|
428 |
choose_cols = st.container()
|
429 |
with choose_cols:
|
430 |
+
choose_disp = st.multiselect('Which stats would you like to view?', options = season_hitter_data_cols, default = season_hitter_data_cols, key='sp_col_display')
|
431 |
+
disp_stats = basic_season_cols + choose_disp
|
432 |
+
display = st.container()
|
433 |
+
working_data = working_data[working_data['Date'] >= low_date]
|
434 |
+
working_data = working_data[working_data['Date'] <= high_date]
|
435 |
+
working_data = working_data[working_data['Team'].isin(team_var1)]
|
436 |
+
working_data = working_data[working_data['Player'].isin(player_var1)]
|
437 |
+
season_long_table = hitter_seasonlong_build(working_data)
|
438 |
+
season_long_table = season_long_table.set_index('Player')
|
439 |
+
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
440 |
+
display.dataframe(season_long_table_disp.style.format(precision=2), height=750, use_container_width = True)
|
441 |
+
st.download_button(
|
442 |
+
label="Export pitcher seasonlogs Model",
|
443 |
+
data=convert_df_to_csv(season_long_table),
|
444 |
+
file_name='Seasonlogs_Pitcher_View.csv',
|
445 |
+
mime='text/csv',
|
446 |
+
)
|
447 |
|
448 |
+
elif split_var1 == 'Gamelogs':
|
449 |
+
choose_cols = st.container()
|
450 |
+
with choose_cols:
|
451 |
+
choose_disp_gamelog = st.multiselect('Which stats would you like to view?', options = hitter_data_cols, default = hitter_data_cols, key='sp_choose_disp_gamelog')
|
452 |
+
gamelog_disp_stats = basic_cols + choose_disp_gamelog
|
453 |
+
working_data = working_data[working_data['Date'] >= low_date]
|
454 |
+
working_data = working_data[working_data['Date'] <= high_date]
|
455 |
+
working_data = working_data[working_data['Team'].isin(team_var1)]
|
456 |
+
working_data = working_data[working_data['Player'].isin(player_var1)]
|
457 |
+
working_data = working_data.reset_index(drop=True)
|
458 |
+
gamelog_data = working_data.reindex(gamelog_disp_stats,axis="columns")
|
459 |
+
display = st.container()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
460 |
|
461 |
+
bottom_menu = st.columns((4, 1, 1))
|
462 |
+
with bottom_menu[2]:
|
463 |
+
batch_size = st.selectbox("Page Size", options=[25, 50, 100])
|
464 |
+
with bottom_menu[1]:
|
465 |
+
total_pages = (
|
466 |
+
int(len(gamelog_data) / batch_size) if int(len(gamelog_data) / batch_size) > 0 else 1
|
467 |
+
)
|
468 |
+
current_page = st.number_input(
|
469 |
+
"Page", min_value=1, max_value=total_pages, step=1
|
470 |
+
)
|
471 |
+
with bottom_menu[0]:
|
472 |
+
st.markdown(f"Page **{current_page}** of **{total_pages}** ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
|
475 |
+
pages = split_frame(gamelog_data, batch_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
# pages = pages.set_index('Player')
|
477 |
+
display.dataframe(data=pages[current_page - 1].style.format(precision=2), height=500, use_container_width=True)
|
478 |
+
st.download_button(
|
479 |
+
label="Export pitcher gamelogs model",
|
480 |
+
data=convert_df_to_csv(gamelog_data),
|
481 |
+
file_name='Gamelogs_Hitter_View.csv',
|
482 |
+
mime='text/csv',
|
483 |
+
)
|