Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,7 @@ 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 =
|
| 48 |
def init_baselines():
|
| 49 |
collection = db["MLB_Hitters_DB"]
|
| 50 |
cursor = collection.find() # Finds all documents in the collection
|
|
@@ -395,46 +395,46 @@ with tab2:
|
|
| 395 |
total_pitchers = indv_pitchers.Player.values.tolist()
|
| 396 |
total_dates = hitter_gamelog_table.Date.values.tolist()
|
| 397 |
|
| 398 |
-
|
| 399 |
-
|
| 400 |
|
| 401 |
-
if
|
| 402 |
-
|
| 403 |
-
elif
|
| 404 |
-
|
| 405 |
|
| 406 |
-
|
| 407 |
|
| 408 |
-
if
|
| 409 |
-
|
| 410 |
-
if
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
if
|
| 414 |
-
|
| 415 |
-
elif
|
| 416 |
-
|
| 417 |
-
|
| 418 |
|
| 419 |
-
|
| 420 |
|
| 421 |
-
if
|
| 422 |
-
|
| 423 |
-
elif
|
| 424 |
-
|
| 425 |
|
| 426 |
with col2:
|
| 427 |
working_data = pitcher_gamelog_table
|
| 428 |
-
if
|
| 429 |
choose_cols = st.container()
|
| 430 |
with choose_cols:
|
| 431 |
-
|
| 432 |
-
disp_stats = basic_season_cols +
|
| 433 |
display = st.container()
|
| 434 |
-
working_data = working_data[working_data['Date'] >=
|
| 435 |
-
working_data = working_data[working_data['Date'] <=
|
| 436 |
-
working_data = working_data[working_data['Team'].isin(
|
| 437 |
-
working_data = working_data[working_data['Player'].isin(
|
| 438 |
season_long_table = pitcher_seasonlong_build(working_data)
|
| 439 |
season_long_table = season_long_table.set_index('Player')
|
| 440 |
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
|
@@ -446,15 +446,15 @@ with tab2:
|
|
| 446 |
mime='text/csv',
|
| 447 |
)
|
| 448 |
|
| 449 |
-
elif
|
| 450 |
choose_cols = st.container()
|
| 451 |
with choose_cols:
|
| 452 |
-
|
| 453 |
-
gamelog_disp_stats = basic_cols +
|
| 454 |
-
working_data = working_data[working_data['Date'] >=
|
| 455 |
-
working_data = working_data[working_data['Date'] <=
|
| 456 |
-
working_data = working_data[working_data['Team'].isin(
|
| 457 |
-
working_data = working_data[working_data['Player'].isin(
|
| 458 |
working_data = working_data.reset_index(drop=True)
|
| 459 |
gamelog_data = working_data.reindex(gamelog_disp_stats,axis="columns")
|
| 460 |
display = st.container()
|
|
|
|
| 44 |
|
| 45 |
percentages_format = {'PG': '{:.2%}', 'SG': '{:.2%}', 'SF': '{:.2%}', 'PF': '{:.2%}', 'C': '{:.2%}'}
|
| 46 |
|
| 47 |
+
@st.cache_resource(ttl = 600)
|
| 48 |
def init_baselines():
|
| 49 |
collection = db["MLB_Hitters_DB"]
|
| 50 |
cursor = collection.find() # Finds all documents in the collection
|
|
|
|
| 395 |
total_pitchers = indv_pitchers.Player.values.tolist()
|
| 396 |
total_dates = hitter_gamelog_table.Date.values.tolist()
|
| 397 |
|
| 398 |
+
sp_split_var1 = st.radio("What table would you like to view?", ('Season Logs', 'Gamelogs'), key='sp_split_var1')
|
| 399 |
+
sp_split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='sp_split_var2')
|
| 400 |
|
| 401 |
+
if sp_split_var2 == 'Specific Teams':
|
| 402 |
+
sp_team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = total_teams, key='sp_team_var1')
|
| 403 |
+
elif sp_split_var2 == 'All':
|
| 404 |
+
sp_team_var1 = total_teams
|
| 405 |
|
| 406 |
+
sp_split_var3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='sp_split_var3')
|
| 407 |
|
| 408 |
+
if sp_split_var3 == 'Specific Dates':
|
| 409 |
+
sp_low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='sp_low_date')
|
| 410 |
+
if sp_low_date is not None:
|
| 411 |
+
sp_low_date = pd.to_datetime(sp_low_date).date()
|
| 412 |
+
sp_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='sp_high_date')
|
| 413 |
+
if sp_high_date is not None:
|
| 414 |
+
sp_high_date = pd.to_datetime(sp_high_date).date()
|
| 415 |
+
elif sp_split_var3 == 'All':
|
| 416 |
+
sp_low_date = pitcher_gamelog_table['Date'].min()
|
| 417 |
+
sp_high_date = pitcher_gamelog_table['Date'].max()
|
| 418 |
|
| 419 |
+
sp_split_var4 = st.radio("Would you like to view all players or specific ones?", ('All', 'Specific Players'), key='sp_split_var4')
|
| 420 |
|
| 421 |
+
if sp_split_var4 == 'Specific Players':
|
| 422 |
+
sp_player_var1 = st.multiselect('Which players would you like to include in the tables?', options = total_pitchers, key='sp_player_var1')
|
| 423 |
+
elif sp_split_var4 == 'All':
|
| 424 |
+
sp_player_var1 = total_pitchers
|
| 425 |
|
| 426 |
with col2:
|
| 427 |
working_data = pitcher_gamelog_table
|
| 428 |
+
if sp_split_var1 == 'Season Logs':
|
| 429 |
choose_cols = st.container()
|
| 430 |
with choose_cols:
|
| 431 |
+
sp_choose_disp = st.multiselect('Which stats would you like to view?', options = season_pitcher_data_cols, default = season_pitcher_data_cols, key='sp_col_display')
|
| 432 |
+
disp_stats = basic_season_cols + sp_choose_disp
|
| 433 |
display = st.container()
|
| 434 |
+
working_data = working_data[working_data['Date'] >= sp_low_date]
|
| 435 |
+
working_data = working_data[working_data['Date'] <= sp_high_date]
|
| 436 |
+
working_data = working_data[working_data['Team'].isin(sp_team_var1)]
|
| 437 |
+
working_data = working_data[working_data['Player'].isin(sp_player_var1)]
|
| 438 |
season_long_table = pitcher_seasonlong_build(working_data)
|
| 439 |
season_long_table = season_long_table.set_index('Player')
|
| 440 |
season_long_table_disp = season_long_table.reindex(disp_stats,axis="columns")
|
|
|
|
| 446 |
mime='text/csv',
|
| 447 |
)
|
| 448 |
|
| 449 |
+
elif sp_split_var1 == 'Gamelogs':
|
| 450 |
choose_cols = st.container()
|
| 451 |
with choose_cols:
|
| 452 |
+
sp_choose_disp_gamelog = st.multiselect('Which stats would you like to view?', options = pitcher_data_cols, default = pitcher_data_cols, key='sp_choose_disp_gamelog')
|
| 453 |
+
gamelog_disp_stats = basic_cols + sp_choose_disp_gamelog
|
| 454 |
+
working_data = working_data[working_data['Date'] >= sp_low_date]
|
| 455 |
+
working_data = working_data[working_data['Date'] <= sp_high_date]
|
| 456 |
+
working_data = working_data[working_data['Team'].isin(sp_team_var1)]
|
| 457 |
+
working_data = working_data[working_data['Player'].isin(sp_player_var1)]
|
| 458 |
working_data = working_data.reset_index(drop=True)
|
| 459 |
gamelog_data = working_data.reindex(gamelog_disp_stats,axis="columns")
|
| 460 |
display = st.container()
|