Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,9 +9,6 @@ import numpy as np
|
|
9 |
import pandas as pd
|
10 |
import streamlit as st
|
11 |
import gspread
|
12 |
-
import gc
|
13 |
-
import plotly.express as px
|
14 |
-
import plotly.io as pio
|
15 |
import pymongo
|
16 |
import certifi
|
17 |
ca = certifi.where()
|
@@ -231,7 +228,7 @@ indv_pitchers = pitcher_gamelog_table.drop_duplicates(subset='Player')
|
|
231 |
total_pitchers = indv_pitchers.Player.values.tolist()
|
232 |
total_dates = hitter_gamelog_table.Date.values.tolist()
|
233 |
|
234 |
-
tab1, tab2 = st.tabs(['Hitter Gamelogs', 'Pitcher Gamelogs'])
|
235 |
|
236 |
with tab1:
|
237 |
st.info(t_stamp)
|
@@ -481,4 +478,76 @@ with tab2:
|
|
481 |
data=convert_df_to_csv(gamelog_data),
|
482 |
file_name='Gamelogs_Hitter_View.csv',
|
483 |
mime='text/csv',
|
484 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
import pandas as pd
|
10 |
import streamlit as st
|
11 |
import gspread
|
|
|
|
|
|
|
12 |
import pymongo
|
13 |
import certifi
|
14 |
ca = certifi.where()
|
|
|
228 |
total_pitchers = indv_pitchers.Player.values.tolist()
|
229 |
total_dates = hitter_gamelog_table.Date.values.tolist()
|
230 |
|
231 |
+
tab1, tab2, tab3 = st.tabs(['Hitter Gamelogs', 'Pitcher Gamelogs', 'Sample Graphs'])
|
232 |
|
233 |
with tab1:
|
234 |
st.info(t_stamp)
|
|
|
478 |
data=convert_df_to_csv(gamelog_data),
|
479 |
file_name='Gamelogs_Hitter_View.csv',
|
480 |
mime='text/csv',
|
481 |
+
)
|
482 |
+
|
483 |
+
with tab3:
|
484 |
+
st.info(t_stamp)
|
485 |
+
col1, col2 = st.columns([1, 9])
|
486 |
+
with col1:
|
487 |
+
if st.button("Reset Data", key='reset3'):
|
488 |
+
st.cache_data.clear()
|
489 |
+
hitter_gamelog_table, pitcher_gamelog_table, timestamp = init_baselines()
|
490 |
+
t_stamp = f"Updated through: " + str(timestamp) + f" CST"
|
491 |
+
|
492 |
+
basic_cols = ['Player', 'Team', 'Date']
|
493 |
+
|
494 |
+
basic_season_cols = ['Player', 'Team', 'Date']
|
495 |
+
|
496 |
+
hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
497 |
+
'GDP', 'SB', 'CS', 'AVG', 'SLG', 'wRC+', 'LD%', 'GB%', 'FB%', 'Hard%', 'Barrels', 'Barrel%']
|
498 |
+
|
499 |
+
season_hitter_data_cols = ['G', 'AB', 'PA', 'H', '1B', '2B', '3B', 'HR', 'R', 'RBI', 'BB', 'IBB', 'SO', 'HBP', 'SF', 'SH',
|
500 |
+
'GDP', 'SB', 'CS', 'Avg AVG', 'Avg SLG', 'Avg wRC+', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg Hard%', 'Barrels', 'Avg Barrel%']
|
501 |
+
|
502 |
+
pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
503 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'K/9', 'BB/9', 'WHIP', 'BABIP', 'LOB%', 'FIP', 'xFIP', 'K%', 'BB%', 'SIERA', 'LD%', 'GB%',
|
504 |
+
'FB%', 'HR/FB', 'Hard%', 'Barrels', 'Barrel%', 'xERA', 'vFA', 'vFT', 'vFC', 'vFS', 'vFO', 'vSI',
|
505 |
+
'vSL', 'vCU', 'vKC', 'vEP', 'vCH', 'vSC', 'vKN']
|
506 |
+
|
507 |
+
season_pitcher_data_cols = ['G', 'GS', 'CG', 'W', 'L', 'Avg ERA', 'ShO', 'SV', 'HLD', 'BS', 'IP', 'TBF', 'H', 'R', 'ER', 'HR',
|
508 |
+
'BB', 'IBB', 'HBP', 'WP', 'BK', 'SO', 'Avg K/9', 'Avg BB/9', 'Avg WHIP', 'Avg BABIP', 'Avg LOB%', 'Avg FIP', 'Avg xFIP', 'Avg K%',
|
509 |
+
'Avg BB%', 'Avg SIERA', 'Avg LD%', 'Avg GB%', 'Avg FB%', 'Avg HR/FB', 'Avg Hard%', 'Barrels', 'Avg Barrel%', 'Avg xERA', 'Avg vFA',
|
510 |
+
'Avg vFT', 'Avg vFC', 'Avg vFS', 'Avg vFO', 'Avg vSI', 'Avg vSL', 'Avg vCU', 'Avg vKC', 'Avg vEP', 'Avg vCH', 'Avg vSC', 'Avg vKN']
|
511 |
+
|
512 |
+
indv_teams = hitter_gamelog_table.drop_duplicates(subset='Team')
|
513 |
+
total_teams = indv_teams.Team.values.tolist()
|
514 |
+
indv_hitters = hitter_gamelog_table.drop_duplicates(subset='Player')
|
515 |
+
total_hitters = indv_hitters.Player.values.tolist()
|
516 |
+
indv_pitchers = pitcher_gamelog_table.drop_duplicates(subset='Player')
|
517 |
+
total_pitchers = indv_pitchers.Player.values.tolist()
|
518 |
+
total_dates = hitter_gamelog_table.Date.values.tolist()
|
519 |
+
|
520 |
+
plot_type = st.radio("Are you viewing hitter or pitcher stats?", ('Pitcher', 'Hitter'), key='plot_type')
|
521 |
+
if plot_type == "Pitcher":
|
522 |
+
player_drop = total_pitchers
|
523 |
+
stat_drop = pitcher_data_cols
|
524 |
+
elif plot_type == "Hitter":
|
525 |
+
player_drop = total_hitters
|
526 |
+
stat_drop = hitter_data_cols
|
527 |
+
player_var3 = st.selectbox("Which player are you viewing?", player_drop, key='player_var3')
|
528 |
+
plot_count = st.radio("how many stats would you like to plot?", ('One', 'Two', 'three'), key='plot_count')
|
529 |
+
if plot_count == "One":
|
530 |
+
plot_var1 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var1')
|
531 |
+
elif plot_count == "Two":
|
532 |
+
plot_var1 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var1')
|
533 |
+
plot_var2 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var2')
|
534 |
+
elif plot_count == "Three":
|
535 |
+
plot_var1 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var1')
|
536 |
+
plot_var2 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var2')
|
537 |
+
plot_var3 = st.selectbox("Which stat are you viewing?", stat_drop, key='plot_var3')
|
538 |
+
|
539 |
+
date_var_3 = st.radio("Would you like to view all dates or specific ones?", ('All', 'Specific Dates'), key='date_var_3')
|
540 |
+
|
541 |
+
if date_var_3 == 'Specific Dates':
|
542 |
+
plot_low_date = st.date_input('Min Date:', value=None, format="YYYY-MM-DD", key='plot_low_date')
|
543 |
+
if plot_low_date is not None:
|
544 |
+
plot_low_date = pd.to_datetime(plot_low_date).date()
|
545 |
+
plot_high_date = st.date_input('Max Date:', value=None, format="YYYY-MM-DD", key='plot_high_date')
|
546 |
+
if plot_high_date is not None:
|
547 |
+
plot_high_date = pd.to_datetime(plot_high_date).date()
|
548 |
+
elif date_var_3 == 'All':
|
549 |
+
plot_low_date = pitcher_gamelog_table['Date'].min()
|
550 |
+
plot_high_date = pitcher_gamelog_table['Date'].max()
|
551 |
+
|
552 |
+
with col2:
|
553 |
+
st.write("Things will go here")
|