Update app.py
Browse files
app.py
CHANGED
|
@@ -51,78 +51,71 @@ NBABettingModel = 'https://docs.google.com/spreadsheets/d/1WBnvOHQi_zVTGF63efejK
|
|
| 51 |
|
| 52 |
@st.cache_resource(ttl = 300)
|
| 53 |
def init_baselines():
|
| 54 |
-
sh = gcservice_account.open_by_url(
|
| 55 |
|
| 56 |
-
worksheet = sh.worksheet('
|
| 57 |
raw_display = pd.DataFrame(worksheet.get_values())
|
| 58 |
raw_display.columns = raw_display.iloc[0]
|
| 59 |
raw_display = raw_display[1:]
|
| 60 |
raw_display = raw_display.reset_index(drop=True)
|
| 61 |
raw_display.replace('', np.nan, inplace=True)
|
| 62 |
-
raw_display = raw_display[['NBAID', 'PID', 'Player', 'TC', 'MP (Today)', 'Next Game', 'H/R', 'Injury Notes', 'Player Impact per 48', 'Player Impact',
|
| 63 |
-
'Team PM', 'Last Updated']]
|
| 64 |
raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
sh = gcservice_account.open_by_url(NBABettingModel)
|
| 68 |
|
| 69 |
-
worksheet = sh.worksheet('
|
| 70 |
raw_display = pd.DataFrame(worksheet.get_values())
|
| 71 |
raw_display.columns = raw_display.iloc[0]
|
| 72 |
raw_display = raw_display[1:]
|
| 73 |
raw_display = raw_display.reset_index(drop=True)
|
| 74 |
raw_display.replace('', 0, inplace=True)
|
| 75 |
-
raw_display = raw_display[['PID', 'Player', 'Team', 'Avg Minutes last 30 days for team', 'Minutes Projection', 'Rotation Impact (versus last 30 days)',
|
| 76 |
-
'Injury Notes', 'Minute Change', 'Baseline Team PM', 'Net Rotation PM +/- for Team', 'Projected PM for Game', 'Offset', 'Rank']]
|
| 77 |
-
raw_display['Minute Change'].replace('+', '', inplace=True)
|
| 78 |
raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
|
| 79 |
-
|
| 80 |
|
| 81 |
-
return
|
| 82 |
|
| 83 |
def convert_df_to_csv(df):
|
| 84 |
return df.to_csv().encode('utf-8')
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
tab1, tab2 = st.tabs(["
|
| 89 |
|
| 90 |
with tab1:
|
| 91 |
if st.button("Reset Data", key='reset1'):
|
| 92 |
st.cache_data.clear()
|
| 93 |
-
|
| 94 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 95 |
if split_var1 == 'Specific Teams':
|
| 96 |
-
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options =
|
| 97 |
elif split_var1 == 'All':
|
| 98 |
-
team_var1 =
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
st.dataframe(player_min_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 103 |
st.download_button(
|
| 104 |
-
label="Export
|
| 105 |
-
data=convert_df_to_csv(
|
| 106 |
-
file_name='
|
| 107 |
mime='text/csv',
|
| 108 |
)
|
| 109 |
|
| 110 |
with tab2:
|
| 111 |
if st.button("Reset Data", key='reset2'):
|
| 112 |
st.cache_data.clear()
|
| 113 |
-
|
| 114 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 115 |
if split_var2 == 'Specific Teams':
|
| 116 |
-
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options =
|
| 117 |
elif split_var2 == 'All':
|
| 118 |
-
team_var2 =
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
st.dataframe(
|
| 123 |
st.download_button(
|
| 124 |
-
label="Export
|
| 125 |
-
data=convert_df_to_csv(
|
| 126 |
-
file_name='
|
| 127 |
mime='text/csv',
|
| 128 |
)
|
|
|
|
| 51 |
|
| 52 |
@st.cache_resource(ttl = 300)
|
| 53 |
def init_baselines():
|
| 54 |
+
sh = gcservice_account.open_by_url(NBABettingModel)
|
| 55 |
|
| 56 |
+
worksheet = sh.worksheet('ExportTable')
|
| 57 |
raw_display = pd.DataFrame(worksheet.get_values())
|
| 58 |
raw_display.columns = raw_display.iloc[0]
|
| 59 |
raw_display = raw_display[1:]
|
| 60 |
raw_display = raw_display.reset_index(drop=True)
|
| 61 |
raw_display.replace('', np.nan, inplace=True)
|
|
|
|
|
|
|
| 62 |
raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
|
| 63 |
+
raw_display['Team Date'] = raw_display['Team'] + " " + raw_display['Date'].astype(str)
|
| 64 |
+
game_model = raw_display[raw_display['Date'] != ""]
|
|
|
|
| 65 |
|
| 66 |
+
worksheet = sh.worksheet('SeasonExport')
|
| 67 |
raw_display = pd.DataFrame(worksheet.get_values())
|
| 68 |
raw_display.columns = raw_display.iloc[0]
|
| 69 |
raw_display = raw_display[1:]
|
| 70 |
raw_display = raw_display.reset_index(drop=True)
|
| 71 |
raw_display.replace('', 0, inplace=True)
|
|
|
|
|
|
|
|
|
|
| 72 |
raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
|
| 73 |
+
season_model = raw_display[raw_display['Team'] != ""]
|
| 74 |
|
| 75 |
+
return game_model, season_model
|
| 76 |
|
| 77 |
def convert_df_to_csv(df):
|
| 78 |
return df.to_csv().encode('utf-8')
|
| 79 |
|
| 80 |
+
game_model, season_model = init_baselines()
|
| 81 |
|
| 82 |
+
tab1, tab2 = st.tabs(["Game Betting Model", "Season and Futures"])
|
| 83 |
|
| 84 |
with tab1:
|
| 85 |
if st.button("Reset Data", key='reset1'):
|
| 86 |
st.cache_data.clear()
|
| 87 |
+
game_model, season_model = init_baselines()
|
| 88 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 89 |
if split_var1 == 'Specific Teams':
|
| 90 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = game_model['Team'].unique(), key='team_var1')
|
| 91 |
elif split_var1 == 'All':
|
| 92 |
+
team_var1 = game_model.Team.values.tolist()
|
| 93 |
+
game_model = game_model[game_model['Team'].isin(team_var1)]
|
| 94 |
+
game_display = game_model.set_index('Team')
|
| 95 |
+
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
| 96 |
st.download_button(
|
| 97 |
+
label="Export Game Model",
|
| 98 |
+
data=convert_df_to_csv(game_model),
|
| 99 |
+
file_name='AmericanNumbers_Game_Model_export.csv',
|
| 100 |
mime='text/csv',
|
| 101 |
)
|
| 102 |
|
| 103 |
with tab2:
|
| 104 |
if st.button("Reset Data", key='reset2'):
|
| 105 |
st.cache_data.clear()
|
| 106 |
+
game_model, season_model = init_baselines()
|
| 107 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 108 |
if split_var2 == 'Specific Teams':
|
| 109 |
+
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = season_model['Team'].unique(), key='team_var2')
|
| 110 |
elif split_var2 == 'All':
|
| 111 |
+
team_var2 = season_model.Team.values.tolist()
|
| 112 |
+
season_model = season_model[season_model['Team'].isin(team_var2)]
|
| 113 |
+
season_display = season_model.set_index('Team')
|
| 114 |
+
season_display = season_display.sort_values(by=['Win Projection Now'], ascending=False)
|
| 115 |
+
st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 116 |
st.download_button(
|
| 117 |
+
label="Export Futures Model",
|
| 118 |
+
data=convert_df_to_csv(season_model),
|
| 119 |
+
file_name='AmericanNumbers_Season_Futures.csv',
|
| 120 |
mime='text/csv',
|
| 121 |
)
|