Update app.py
Browse files
app.py
CHANGED
@@ -47,6 +47,7 @@ def init_conn():
|
|
47 |
gcservice_account = init_conn()
|
48 |
|
49 |
NBAGetGameData = 'https://docs.google.com/spreadsheets/d/1tRQrF_I5rS7Q0g9vE8NrENDZ2P3_DvtbBZzKEakwOI0/edit#gid=1373653837'
|
|
|
50 |
NBABettingModel = 'https://docs.google.com/spreadsheets/d/1WBnvOHQi_zVTGF63efejK5ho02AY00HiYrMHnMJXY1E/edit#gid=1157978351'
|
51 |
|
52 |
game_format = {'Injury and Rotation Adjusted Win %': '{:.2%}'}
|
@@ -58,146 +59,64 @@ percentages_format = {'Playoff Odds': '{:.2%}', 'Division Odds': '{:.2%}', 'Top
|
|
58 |
|
59 |
@st.cache_resource(ttl = 300)
|
60 |
def init_baselines():
|
61 |
-
sh = gcservice_account.open_by_url(
|
62 |
|
63 |
-
worksheet = sh.worksheet('
|
64 |
raw_display = pd.DataFrame(worksheet.get_values())
|
65 |
raw_display.columns = raw_display.iloc[0]
|
66 |
raw_display = raw_display[1:]
|
67 |
raw_display = raw_display.reset_index(drop=True)
|
68 |
raw_display.replace('', np.nan, inplace=True)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
|
|
77 |
|
78 |
-
|
79 |
-
raw_display = pd.DataFrame(worksheet.get_values())
|
80 |
-
raw_display.columns = raw_display.iloc[0]
|
81 |
-
raw_display = raw_display[1:]
|
82 |
-
raw_display = raw_display.reset_index(drop=True)
|
83 |
-
raw_display.replace('', 0, inplace=True)
|
84 |
-
cols_to_check = ['Playoff Odds', 'Division Odds', 'Top 4 Seed Odds', '1 Seed Odds', 'Win 1st Round', 'Win 2nd Round', 'Win Conference', 'Win Title',
|
85 |
-
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']
|
86 |
-
raw_display.loc[:, cols_to_check] = raw_display.loc[:, cols_to_check].replace({'%': ''}, regex=True).astype(float) / 100
|
87 |
-
raw_display = raw_display.apply(pd.to_numeric, errors='coerce').fillna(raw_display)
|
88 |
-
season_model = raw_display[raw_display['Team'] != ""]
|
89 |
-
title_sims = season_model[['Team', 'Conference', 'Division', 'Power Rank', 'Team PointMarginPerGame', 'SeasonSimLookup', 'Win Projection Now',
|
90 |
-
'Playoff Odds', 'Division Odds', 'Top 4 Seed Odds', '1 Seed Odds', 'Win 1st Round', 'Win 2nd Round', 'Win Conference', 'Win Title']]
|
91 |
-
seed_probs = season_model[['Team', 'Conference', 'Division', 'Avg Seed', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']]
|
92 |
-
|
93 |
-
sh = gcservice_account.open_by_url('https://docs.google.com/spreadsheets/d/1Yq0vGriWK-bS79e-bD6_u9pqrYE6Yrlbb_wEkmH-ot0/edit#gid=1540807349')
|
94 |
-
|
95 |
-
worksheet = sh.worksheet('Arturo Props')
|
96 |
-
raw_display = pd.DataFrame(worksheet.get_all_records())
|
97 |
-
raw_display.replace('', np.nan, inplace=True)
|
98 |
-
timestamp = raw_display['Date'].head(1)[0]
|
99 |
-
|
100 |
-
return game_model, season_model, seed_probs, title_sims, just_win_probs, timestamp
|
101 |
|
102 |
def convert_df_to_csv(df):
|
103 |
return df.to_csv().encode('utf-8')
|
104 |
|
105 |
-
game_model,
|
106 |
-
t_stamp = f"Last Update: " + str(timestamp) + f"
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
data=convert_df_to_csv(game_model),
|
138 |
-
file_name='AmericanNumbers_Game_Model_export.csv',
|
139 |
-
mime='text/csv',
|
140 |
-
)
|
141 |
-
elif view_var1 == 'Gimme details':
|
142 |
-
game_display = game_model[game_model['Acro'].isin(team_var1)]
|
143 |
-
game_display = game_display[game_display['Date'].isin(date_var1)]
|
144 |
-
game_display = game_display.set_index('Team Date')
|
145 |
-
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
146 |
-
st.download_button(
|
147 |
-
label="Export Game Model",
|
148 |
-
data=convert_df_to_csv(game_model),
|
149 |
-
file_name='AmericanNumbers_Game_Model_export.csv',
|
150 |
-
mime='text/csv',
|
151 |
-
)
|
152 |
-
|
153 |
-
with tab2:
|
154 |
-
st.info(t_stamp)
|
155 |
-
col1, col2 = st.columns([1, 9])
|
156 |
-
with col1:
|
157 |
-
if st.button("Reset Data", key='reset2'):
|
158 |
-
st.cache_data.clear()
|
159 |
-
game_model, season_model, seed_probs, title_sims, just_win_probs, timestamp = init_baselines()
|
160 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
161 |
-
view_var2 = st.radio("Would you like to view title odds and win projections or seeding probabilities?", ('Win Odds', 'Seed Probabilities'), key='view_var2')
|
162 |
-
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
163 |
-
if split_var2 == 'Specific Teams':
|
164 |
-
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = season_model['Team'].unique(), key='team_var2')
|
165 |
-
elif split_var2 == 'All':
|
166 |
-
team_var2 = season_model.Team.values.tolist()
|
167 |
-
conf_var2 = st.radio("Would you like to view all conferences or specific ones?", ('All', 'Specific Conferences'), key='conf_var2')
|
168 |
-
if conf_var2 == 'Specific Conferences':
|
169 |
-
conf_choice_var2 = st.multiselect('Which conferences would you like to include in the tables?', options = season_model['Conference'].unique(), key='conf_choice_var2')
|
170 |
-
elif conf_var2 == 'All':
|
171 |
-
conf_choice_var2 = season_model.Conference.values.tolist()
|
172 |
-
div_var2 = st.radio("Would you like to view all divisions or specific ones?", ('All', 'Specific Divisions'), key='div_var2')
|
173 |
-
if div_var2 == 'Specific Divisions':
|
174 |
-
div_choice_var2 = st.multiselect('Which divisions would you like to include in the tables?', options = season_model['Division'].unique(), key='div_choice_var2')
|
175 |
-
elif div_var2 == 'All':
|
176 |
-
div_choice_var2 = season_model.Division.values.tolist()
|
177 |
-
with col2:
|
178 |
-
if view_var2 == 'Win Odds':
|
179 |
-
title_sims = title_sims[title_sims['Team'].isin(team_var2)]
|
180 |
-
title_sims = title_sims[title_sims['Conference'].isin(conf_choice_var2)]
|
181 |
-
title_sims = title_sims[title_sims['Division'].isin(div_choice_var2)]
|
182 |
-
season_display = title_sims.set_index('Team')
|
183 |
-
season_display = season_display.sort_values(by=['Win Projection Now'], ascending=False)
|
184 |
-
st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
|
185 |
-
st.download_button(
|
186 |
-
label="Export Futures Model",
|
187 |
-
data=convert_df_to_csv(title_sims),
|
188 |
-
file_name='AmericanNumbers_Season_Futures.csv',
|
189 |
-
mime='text/csv',
|
190 |
-
)
|
191 |
-
elif view_var2 == 'Seed Probabilities':
|
192 |
-
seed_probs = seed_probs[seed_probs['Team'].isin(team_var2)]
|
193 |
-
seed_probs = seed_probs[seed_probs['Conference'].isin(conf_choice_var2)]
|
194 |
-
seed_probs = seed_probs[seed_probs['Division'].isin(div_choice_var2)]
|
195 |
-
season_display = seed_probs.set_index('Team')
|
196 |
-
season_display = season_display.sort_values(by=['Avg Seed'], ascending=True)
|
197 |
-
st.dataframe(season_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(percentages_format, precision=2), use_container_width = True)
|
198 |
-
st.download_button(
|
199 |
-
label="Export Futures Model",
|
200 |
-
data=convert_df_to_csv(seed_probs),
|
201 |
-
file_name='AmericanNumbers_Season_Futures.csv',
|
202 |
-
mime='text/csv',
|
203 |
-
)
|
|
|
47 |
gcservice_account = init_conn()
|
48 |
|
49 |
NBAGetGameData = 'https://docs.google.com/spreadsheets/d/1tRQrF_I5rS7Q0g9vE8NrENDZ2P3_DvtbBZzKEakwOI0/edit#gid=1373653837'
|
50 |
+
NCAAMensBasketball = 'https://docs.google.com/spreadsheets/d/1flWwlx1T7Xu68AjOkeq7u4Y7nWzukZzKTEI17RJ6MfE/edit#gid=1975368022'
|
51 |
NBABettingModel = 'https://docs.google.com/spreadsheets/d/1WBnvOHQi_zVTGF63efejK5ho02AY00HiYrMHnMJXY1E/edit#gid=1157978351'
|
52 |
|
53 |
game_format = {'Injury and Rotation Adjusted Win %': '{:.2%}'}
|
|
|
59 |
|
60 |
@st.cache_resource(ttl = 300)
|
61 |
def init_baselines():
|
62 |
+
sh = gcservice_account.open_by_url(NCAAMensBasketball)
|
63 |
|
64 |
+
worksheet = sh.worksheet('ActiveBets')
|
65 |
raw_display = pd.DataFrame(worksheet.get_values())
|
66 |
raw_display.columns = raw_display.iloc[0]
|
67 |
raw_display = raw_display[1:]
|
68 |
raw_display = raw_display.reset_index(drop=True)
|
69 |
raw_display.replace('', np.nan, inplace=True)
|
70 |
+
game_model = raw_display[['#', 'date', 'gameid', 'HomeTeam', 'HomeDiv', 'HomeConf', 'AwayTeam', 'AwayDiv', 'AwayConf',
|
71 |
+
'total', 'mlHome', 'mlAway', 'spreadHome', 'spreadAway', 'booksid', 'inconf', 'Neutral', 'Home Team PM',
|
72 |
+
'Road Team PM', 'HCA', 'Home Team Margin', 'Home Team Win', 'Home ML Break even %',
|
73 |
+
'Road ML Break Even %', 'Home Win Edge', 'Road Win Edge', 'Moneyline Bet Rec', 'Home Spread Edge',
|
74 |
+
'Road Team Edge', 'Home Spread HKelly', 'Away Spread HKelly', 'Spread Bet Rec', 'Edge for Spread']]
|
75 |
+
data_cols = ['#', 'gameid', 'total', 'mlHome', 'mlAway', 'spreadHome', 'spreadAway', 'Neutral', 'Home Team PM',
|
76 |
+
'Road Team PM', 'HCA', 'Home Team Margin', 'Home Team Win', 'Home ML Break even %',
|
77 |
+
'Road ML Break Even %', 'Home Win Edge', 'Road Win Edge', 'Home Spread Edge',
|
78 |
+
'Road Team Edge', 'Home Spread HKelly', 'Away Spread HKelly', 'Edge for Spread']
|
79 |
+
game_model[data_cols] = game_model[data_cols].apply(pd.to_numeric, errors='coerce')
|
80 |
+
game_model = game_model[game_model['Injury and Rotation Adjusted Win %'] != ""]
|
81 |
+
just_win_probs = game_model[['#', 'date', 'gameid', 'HomeTeam', 'AwayTeam', 'total', 'mlHome', 'mlAway', 'spreadHome', 'spreadAway', 'booksid',
|
82 |
+
'Home Win Edge', 'Road Win Edge', 'Moneyline Bet Rec', 'Home Spread Edge', 'Road Team Edge', 'Spread Bet Rec']]
|
83 |
|
84 |
+
timestamp = raw_display['Time'].head(1)[0]
|
85 |
|
86 |
+
return game_model, just_win_probs, timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def convert_df_to_csv(df):
|
89 |
return df.to_csv().encode('utf-8')
|
90 |
|
91 |
+
game_model, just_win_probs, timestamp = init_baselines()
|
92 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" EST"
|
93 |
+
|
94 |
+
|
95 |
+
st.info(t_stamp)
|
96 |
+
col1, col2 = st.columns([1, 9])
|
97 |
+
with col1:
|
98 |
+
if st.button("Reset Data", key='reset1'):
|
99 |
+
st.cache_data.clear()
|
100 |
+
game_model, just_win_probs, timestamp = init_baselines()
|
101 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" EST"
|
102 |
+
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')
|
103 |
+
|
104 |
+
with col2:
|
105 |
+
if view_var1 == 'Just win probs':
|
106 |
+
game_display = just_win_probs
|
107 |
+
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
108 |
+
st.download_button(
|
109 |
+
label="Export Game Model",
|
110 |
+
data=convert_df_to_csv(game_model),
|
111 |
+
file_name='AmericanNumbers_Game_Model_export.csv',
|
112 |
+
mime='text/csv',
|
113 |
+
)
|
114 |
+
elif view_var1 == 'Gimme details':
|
115 |
+
game_display = game_model
|
116 |
+
st.dataframe(game_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
117 |
+
st.download_button(
|
118 |
+
label="Export Game Model",
|
119 |
+
data=convert_df_to_csv(game_model),
|
120 |
+
file_name='AmericanNumbers_NCAA_BBall_export.csv',
|
121 |
+
mime='text/csv',
|
122 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|