Update app.py
Browse files
app.py
CHANGED
|
@@ -72,6 +72,8 @@ def init_baselines():
|
|
| 72 |
raw_display['Team Date'] = raw_display['Team'] + " " + raw_display['Date']
|
| 73 |
raw_display = raw_display.drop(columns=['Day of Season', 'Team', 'Opp', 'Date Num', 'DR Team', 'In Minutes File'])
|
| 74 |
game_model = raw_display[raw_display['Injury and Rotation Adjusted Win %'] != ""]
|
|
|
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
worksheet = sh.worksheet('SeasonExport')
|
|
@@ -89,12 +91,12 @@ def init_baselines():
|
|
| 89 |
'Playoff Odds', 'Division Odds', 'Top 4 Seed Odds', '1 Seed Odds', 'Win 1st Round', 'Win 2nd Round', 'Win Conference', 'Win Title']]
|
| 90 |
seed_probs = season_model[['Team', 'Conference', 'Division', 'Avg Seed', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']]
|
| 91 |
|
| 92 |
-
return game_model, season_model, seed_probs, title_sims
|
| 93 |
|
| 94 |
def convert_df_to_csv(df):
|
| 95 |
return df.to_csv().encode('utf-8')
|
| 96 |
|
| 97 |
-
game_model, season_model, seed_probs, title_sims = init_baselines()
|
| 98 |
|
| 99 |
tab1, tab2 = st.tabs(["Game Betting Model", "Season and Futures"])
|
| 100 |
|
|
@@ -103,7 +105,8 @@ with tab1:
|
|
| 103 |
with col1:
|
| 104 |
if st.button("Reset Data", key='reset1'):
|
| 105 |
st.cache_data.clear()
|
| 106 |
-
game_model, season_model, seed_probs, title_sims = init_baselines()
|
|
|
|
| 107 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 108 |
if split_var1 == 'Specific Teams':
|
| 109 |
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = game_model['Acro'].unique(), key='team_var1')
|
|
@@ -115,23 +118,35 @@ with tab1:
|
|
| 115 |
elif date_split_var1 == 'All':
|
| 116 |
date_var1 = game_model.Date.values.tolist()
|
| 117 |
with col2:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
with tab2:
|
| 130 |
col1, col2 = st.columns([1, 9])
|
| 131 |
with col1:
|
| 132 |
if st.button("Reset Data", key='reset2'):
|
| 133 |
st.cache_data.clear()
|
| 134 |
-
game_model, season_model, seed_probs, title_sims = init_baselines()
|
| 135 |
view_var2 = st.radio("Would you like to view title odds and win projections or seeding probabilities?", ('Win Odds', 'Seed Probabilities'), key='view_var2')
|
| 136 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 137 |
if split_var2 == 'Specific Teams':
|
|
|
|
| 72 |
raw_display['Team Date'] = raw_display['Team'] + " " + raw_display['Date']
|
| 73 |
raw_display = raw_display.drop(columns=['Day of Season', 'Team', 'Opp', 'Date Num', 'DR Team', 'In Minutes File'])
|
| 74 |
game_model = raw_display[raw_display['Injury and Rotation Adjusted Win %'] != ""]
|
| 75 |
+
just_win_probs = game_model[['Team Date', 'Time', 'Acro', 'Opponent', 'Injury and Rotation Adjusted Win %', 'Total Proj', 'Projected Points']]
|
| 76 |
+
just_win_probs['Projected Spread'] = (just_win_probs['Total Proj'] / 2) - just_win_probs['Projected Points']
|
| 77 |
|
| 78 |
|
| 79 |
worksheet = sh.worksheet('SeasonExport')
|
|
|
|
| 91 |
'Playoff Odds', 'Division Odds', 'Top 4 Seed Odds', '1 Seed Odds', 'Win 1st Round', 'Win 2nd Round', 'Win Conference', 'Win Title']]
|
| 92 |
seed_probs = season_model[['Team', 'Conference', 'Division', 'Avg Seed', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']]
|
| 93 |
|
| 94 |
+
return game_model, season_model, seed_probs, title_sims, just_win_probs
|
| 95 |
|
| 96 |
def convert_df_to_csv(df):
|
| 97 |
return df.to_csv().encode('utf-8')
|
| 98 |
|
| 99 |
+
game_model, season_model, seed_probs, title_sims, just_win_probs = init_baselines()
|
| 100 |
|
| 101 |
tab1, tab2 = st.tabs(["Game Betting Model", "Season and Futures"])
|
| 102 |
|
|
|
|
| 105 |
with col1:
|
| 106 |
if st.button("Reset Data", key='reset1'):
|
| 107 |
st.cache_data.clear()
|
| 108 |
+
game_model, season_model, seed_probs, title_sims, just_win_probs = init_baselines()
|
| 109 |
+
view_var1 = st.radio("Would you like to view math and stuff or just the win percentages and margins?", ('Just win probs', 'Gimme details'), key='view_var1')
|
| 110 |
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 111 |
if split_var1 == 'Specific Teams':
|
| 112 |
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = game_model['Acro'].unique(), key='team_var1')
|
|
|
|
| 118 |
elif date_split_var1 == 'All':
|
| 119 |
date_var1 = game_model.Date.values.tolist()
|
| 120 |
with col2:
|
| 121 |
+
if view_var1 == 'Just win probs':
|
| 122 |
+
game_display = just_win_probs[just_win_probs['Acro'].isin(team_var1)]
|
| 123 |
+
game_display = game_display[game_display['Date'].isin(date_var1)]
|
| 124 |
+
game_display = game_display.set_index('Team Date')
|
| 125 |
+
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 126 |
+
st.download_button(
|
| 127 |
+
label="Export Game Model",
|
| 128 |
+
data=convert_df_to_csv(game_model),
|
| 129 |
+
file_name='AmericanNumbers_Game_Model_export.csv',
|
| 130 |
+
mime='text/csv',
|
| 131 |
+
)
|
| 132 |
+
elif view_var1 == 'Gimme details':
|
| 133 |
+
game_display = game_model[game_model['Acro'].isin(team_var1)]
|
| 134 |
+
game_display = game_display[game_display['Date'].isin(date_var1)]
|
| 135 |
+
game_display = game_display.set_index('Team Date')
|
| 136 |
+
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 137 |
+
st.download_button(
|
| 138 |
+
label="Export Game Model",
|
| 139 |
+
data=convert_df_to_csv(game_model),
|
| 140 |
+
file_name='AmericanNumbers_Game_Model_export.csv',
|
| 141 |
+
mime='text/csv',
|
| 142 |
+
)
|
| 143 |
|
| 144 |
with tab2:
|
| 145 |
col1, col2 = st.columns([1, 9])
|
| 146 |
with col1:
|
| 147 |
if st.button("Reset Data", key='reset2'):
|
| 148 |
st.cache_data.clear()
|
| 149 |
+
game_model, season_model, seed_probs, title_sims, just_win_probs = init_baselines()
|
| 150 |
view_var2 = st.radio("Would you like to view title odds and win projections or seeding probabilities?", ('Win Odds', 'Seed Probabilities'), key='view_var2')
|
| 151 |
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 152 |
if split_var2 == 'Specific Teams':
|