Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,215 +37,101 @@ def init_conn():
|
|
| 37 |
|
| 38 |
gcservice_account = init_conn()
|
| 39 |
|
| 40 |
-
master_hold = 'https://docs.google.com/spreadsheets/d/
|
| 41 |
|
| 42 |
-
game_format = {'Win%': '{:.2%}'}
|
| 43 |
-
prop_format = {'L5 Success': '{:.2%}', 'L10_Success': '{:.2%}', 'L20_success': '{:.2%}', 'Matchup Boost': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
| 44 |
-
'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
|
| 45 |
-
prop_table_options = ['points', 'threes', 'rebounds', 'assists', 'blocks', 'steals', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
|
| 46 |
-
all_sim_vars = ['points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds', 'points+assists', 'rebounds+assists']
|
| 47 |
-
sim_all_hold = pd.DataFrame(columns=['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge'])
|
| 48 |
|
| 49 |
-
@st.cache_resource(ttl =
|
| 50 |
def init_baselines():
|
| 51 |
sh = gcservice_account.open_by_url(master_hold)
|
| 52 |
-
worksheet = sh.worksheet('
|
| 53 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 54 |
-
raw_display.
|
| 55 |
-
raw_display['Win%'] = raw_display['Win%'].replace({'%': ''}, regex=True).astype(float) / 100
|
| 56 |
-
game_model = raw_display.dropna()
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
raw_display.replace('', np.nan, inplace=True)
|
| 61 |
-
raw_display.rename(columns={"Name": "Player"}, inplace = True)
|
| 62 |
-
raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Minutes', '3P', 'Points', 'Rebounds', 'Assists', 'Steals', 'Blocks', 'Turnovers', 'Fantasy']]
|
| 63 |
-
player_stats = raw_display[raw_display['Minutes'] > 0]
|
| 64 |
-
|
| 65 |
-
player_stats['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 66 |
-
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 67 |
-
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 68 |
-
|
| 69 |
-
worksheet = sh.worksheet('Timestamp')
|
| 70 |
-
timestamp = worksheet.acell('A1').value
|
| 71 |
-
|
| 72 |
-
worksheet = sh.worksheet('Prop_Frame')
|
| 73 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 74 |
-
raw_display.
|
| 75 |
-
prop_frame = raw_display.dropna(subset='Player')
|
| 76 |
|
| 77 |
-
|
| 78 |
-
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 79 |
-
raw_display.replace('', np.nan, inplace=True)
|
| 80 |
-
pick_frame = raw_display.dropna(subset='Player')
|
| 81 |
-
|
| 82 |
-
prop_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 83 |
-
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 84 |
-
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 85 |
-
pick_frame['Player'].replace(['Jaren Jackson', 'Nic Claxton', 'Jabari Smith', 'Lu Dort', 'Moe Wagner', 'Kyle Kuzma', 'Trey Murphy', 'Cameron Thomas'],
|
| 86 |
-
['Jaren Jackson Jr.', 'Nicolas Claxton', 'Jabari Smith Jr.', 'Luguentz Dort', 'Moritz Wagner', 'Kyle Kuzma Jr.',
|
| 87 |
-
'Trey Murphy III', 'Cam Thomas'], inplace=True)
|
| 88 |
-
return game_model, player_stats, prop_frame, pick_frame, timestamp
|
| 89 |
|
| 90 |
def convert_df_to_csv(df):
|
| 91 |
return df.to_csv().encode('utf-8')
|
| 92 |
|
| 93 |
-
|
| 94 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 95 |
|
| 96 |
-
tab1, tab2, tab3, tab4
|
| 97 |
|
| 98 |
with tab1:
|
| 99 |
-
st.info(t_stamp)
|
| 100 |
if st.button("Reset Data", key='reset1'):
|
| 101 |
st.cache_data.clear()
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
| 110 |
-
if line_var1 == 'American':
|
| 111 |
-
team_frame = team_frame[['Team', 'Opp', 'Team Points', 'Opp Points', 'Proj Total', 'Proj Spread', 'Proj Winner', 'Odds Line']]
|
| 112 |
-
team_frame = team_frame.set_index('Team')
|
| 113 |
-
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 114 |
|
| 115 |
st.download_button(
|
| 116 |
-
label="Export
|
| 117 |
-
data=convert_df_to_csv(
|
| 118 |
-
file_name='
|
| 119 |
mime='text/csv',
|
| 120 |
-
key='
|
| 121 |
)
|
| 122 |
|
| 123 |
with tab2:
|
| 124 |
-
st.info(t_stamp)
|
| 125 |
if st.button("Reset Data", key='reset2'):
|
| 126 |
st.cache_data.clear()
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
player_stats_disp = player_stats.set_index('Player')
|
| 136 |
-
player_stats_disp = player_stats_disp.sort_values(by='Fantasy', ascending=False)
|
| 137 |
-
st.dataframe(player_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 138 |
st.download_button(
|
| 139 |
-
label="Export
|
| 140 |
-
data=convert_df_to_csv(
|
| 141 |
-
file_name='
|
| 142 |
mime='text/csv',
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
with tab3:
|
| 146 |
-
st.info(t_stamp)
|
| 147 |
if st.button("Reset Data", key='reset3'):
|
| 148 |
st.cache_data.clear()
|
| 149 |
-
|
| 150 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 151 |
-
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
| 152 |
-
if split_var5 == 'Specific Teams':
|
| 153 |
-
team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = player_stats['Team'].unique(), key='team_var5')
|
| 154 |
-
elif split_var5 == 'All':
|
| 155 |
-
team_var5 = player_stats.Team.values.tolist()
|
| 156 |
-
prop_type_var2 = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options)
|
| 157 |
-
prop_frame_disp = prop_frame[prop_frame['Team'].isin(team_var5)]
|
| 158 |
-
prop_frame_disp = prop_frame_disp[prop_frame_disp['prop_type'] == prop_type_var2]
|
| 159 |
-
prop_frame_disp = prop_frame_disp.set_index('Player')
|
| 160 |
-
prop_frame_disp = prop_frame_disp.sort_values(by='Trending Over', ascending=False)
|
| 161 |
-
st.dataframe(prop_frame_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(prop_format, precision=2), use_container_width = True)
|
| 162 |
-
st.download_button(
|
| 163 |
-
label="Export Prop Trends Model",
|
| 164 |
-
data=convert_df_to_csv(prop_frame),
|
| 165 |
-
file_name='NBA_prop_trends_export.csv',
|
| 166 |
-
mime='text/csv',
|
| 167 |
-
)
|
| 168 |
-
|
| 169 |
-
with tab4:
|
| 170 |
-
st.info(t_stamp)
|
| 171 |
-
if st.button("Reset Data", key='reset4'):
|
| 172 |
-
st.cache_data.clear()
|
| 173 |
-
game_model, player_stats, prop_frame, pick_frame, timestamp = init_baselines()
|
| 174 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 175 |
col1, col2 = st.columns([1, 5])
|
| 176 |
|
| 177 |
with col2:
|
| 178 |
df_hold_container = st.empty()
|
| 179 |
-
info_hold_container = st.empty()
|
| 180 |
-
plot_hold_container = st.empty()
|
| 181 |
|
| 182 |
with col1:
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
|
| 188 |
-
if prop_type_var == 'points':
|
| 189 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 15.5, step = .5)
|
| 190 |
-
elif prop_type_var == 'threes':
|
| 191 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 192 |
-
elif prop_type_var == 'rebounds':
|
| 193 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
|
| 194 |
-
elif prop_type_var == 'assists':
|
| 195 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 25.5, value = 5.5, step = .5)
|
| 196 |
-
elif prop_type_var == 'blocks':
|
| 197 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 198 |
-
elif prop_type_var == 'steals':
|
| 199 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
| 200 |
-
elif prop_type_var == 'PRA':
|
| 201 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 65.5, value = 20.5, step = .5)
|
| 202 |
-
elif prop_type_var == 'points+rebounds':
|
| 203 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 204 |
-
elif prop_type_var == 'points+assists':
|
| 205 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 206 |
-
elif prop_type_var == 'rebounds+assists':
|
| 207 |
-
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 45.5, value = 10.5, step = .5)
|
| 208 |
-
line_var = st.number_input('Type in the line on the prop (i.e. -120)', min_value = -1500, max_value = 1500, value = -150, step = 1)
|
| 209 |
-
line_var = line_var + 1
|
| 210 |
-
|
| 211 |
-
if st.button('Simulate Prop'):
|
| 212 |
with col2:
|
| 213 |
|
| 214 |
with df_hold_container.container():
|
| 215 |
|
| 216 |
-
df =
|
| 217 |
|
| 218 |
total_sims = 5000
|
| 219 |
|
| 220 |
df.replace("", 0, inplace=True)
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
df['Median'] = df['3P']
|
| 229 |
-
elif prop_type_var == 'rebounds':
|
| 230 |
-
df['Median'] = df['Rebounds']
|
| 231 |
-
elif prop_type_var == 'assists':
|
| 232 |
-
df['Median'] = df['Assists']
|
| 233 |
-
elif prop_type_var == 'blocks':
|
| 234 |
-
df['Median'] = df['Blocks']
|
| 235 |
-
elif prop_type_var == 'steals':
|
| 236 |
-
df['Median'] = df['Steals']
|
| 237 |
-
elif prop_type_var == 'PRA':
|
| 238 |
-
df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
|
| 239 |
-
elif prop_type_var == 'points+rebounds':
|
| 240 |
-
df['Median'] = df['Points'] + df['Rebounds']
|
| 241 |
-
elif prop_type_var == 'points+assists':
|
| 242 |
-
df['Median'] = df['Points'] + df['Assists']
|
| 243 |
-
elif prop_type_var == 'rebounds+assists':
|
| 244 |
-
df['Median'] = df['Assists'] + df['Rebounds']
|
| 245 |
|
| 246 |
flex_file = df
|
| 247 |
-
flex_file['Floor'] = (flex_file['Median'] * .25)
|
| 248 |
-
flex_file['Ceiling'] = flex_file['Median'] +
|
| 249 |
flex_file['STD'] = (flex_file['Median']/4)
|
| 250 |
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 251 |
|
|
@@ -268,354 +154,83 @@ with tab4:
|
|
| 268 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 269 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 270 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))
|
| 277 |
-
|
| 278 |
players_only['Player'] = hold_file[['Player']]
|
| 279 |
|
| 280 |
-
final_outcomes = players_only[['Player', '
|
| 281 |
-
final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
|
| 282 |
-
final_outcomes = final_outcomes.loc[final_outcomes['Player'] == player_check]
|
| 283 |
-
player_outcomes = player_outcomes.loc[player_outcomes['Player'] == player_check]
|
| 284 |
-
player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
|
| 285 |
-
player_outcomes = player_outcomes.reset_index()
|
| 286 |
-
player_outcomes.columns = ['Instance', 'Outcome']
|
| 287 |
-
|
| 288 |
-
x1 = player_outcomes.Outcome.to_numpy()
|
| 289 |
-
|
| 290 |
-
print(x1)
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
with df_hold_container:
|
| 301 |
-
df_hold_container = st.empty()
|
| 302 |
-
format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
|
| 303 |
-
st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)
|
| 304 |
-
|
| 305 |
-
with info_hold_container:
|
| 306 |
-
st.info('The Y-axis is the percent of times in simulations that the player reaches certain thresholds, while the X-axis is the threshold to be met. The Green dotted line is the prop you entered. You can hover over any spot and see the percent to reach that mark.')
|
| 307 |
-
|
| 308 |
-
with plot_hold_container:
|
| 309 |
-
st.dataframe(player_outcomes, use_container_width = True)
|
| 310 |
-
plot_hold_container = st.empty()
|
| 311 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 312 |
-
|
| 313 |
-
with tab5:
|
| 314 |
-
st.info(t_stamp)
|
| 315 |
-
st.info('The Over and Under percentages are a composite percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
| 316 |
-
if st.button("Reset Data/Load Data", key='reset5'):
|
| 317 |
st.cache_data.clear()
|
| 318 |
-
|
| 319 |
-
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 320 |
col1, col2 = st.columns([1, 5])
|
| 321 |
|
| 322 |
with col2:
|
| 323 |
df_hold_container = st.empty()
|
| 324 |
-
info_hold_container = st.empty()
|
| 325 |
-
plot_hold_container = st.empty()
|
| 326 |
-
export_container = st.empty()
|
| 327 |
|
| 328 |
with col1:
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
elif game_select_var == 'Pick6':
|
| 333 |
-
prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 334 |
-
prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
|
| 335 |
-
st.download_button(
|
| 336 |
-
label="Download Prop Source",
|
| 337 |
-
data=convert_df_to_csv(prop_df),
|
| 338 |
-
file_name='Nba_prop_source.csv',
|
| 339 |
-
mime='text/csv',
|
| 340 |
-
key='prop_source',
|
| 341 |
-
)
|
| 342 |
-
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'points', 'rebounds', 'assists', 'threes', 'PRA', 'points+rebounds',
|
| 343 |
-
'points+assists', 'rebounds+assists'])
|
| 344 |
-
if prop_type_var == 'All Props':
|
| 345 |
-
st.info('please note that the All Props run can take some time, you will see progress as tables show up in the sim area to the right')
|
| 346 |
-
|
| 347 |
-
if st.button('Simulate Prop Category'):
|
| 348 |
with col2:
|
|
|
|
| 349 |
with df_hold_container.container():
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
hold_file = flex_file
|
| 400 |
-
overall_file = flex_file
|
| 401 |
-
prop_file = flex_file
|
| 402 |
-
|
| 403 |
-
overall_players = overall_file[['Player']]
|
| 404 |
-
|
| 405 |
-
for x in range(0,total_sims):
|
| 406 |
-
prop_file[x] = prop_file['Prop']
|
| 407 |
-
|
| 408 |
-
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 409 |
-
|
| 410 |
-
for x in range(0,total_sims):
|
| 411 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 412 |
-
|
| 413 |
-
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 414 |
-
|
| 415 |
-
players_only = hold_file[['Player']]
|
| 416 |
-
|
| 417 |
-
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 418 |
-
|
| 419 |
-
prop_check = (overall_file - prop_file)
|
| 420 |
-
|
| 421 |
-
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 422 |
-
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 423 |
-
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 424 |
-
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 425 |
-
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 426 |
-
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 427 |
-
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 428 |
-
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 429 |
-
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 430 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 431 |
-
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 432 |
-
players_only['prop_threshold'] = .10
|
| 433 |
-
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 434 |
-
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 435 |
-
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 436 |
-
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 437 |
-
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 438 |
-
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 439 |
-
players_only['Edge'] = players_only['Bet_check']
|
| 440 |
-
players_only['Prop type'] = prop
|
| 441 |
-
|
| 442 |
-
players_only['Player'] = hold_file[['Player']]
|
| 443 |
-
|
| 444 |
-
leg_outcomes = players_only[['Player', 'Prop type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 445 |
-
|
| 446 |
-
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
| 447 |
-
|
| 448 |
-
final_outcomes = sim_all_hold
|
| 449 |
-
|
| 450 |
-
elif prop_type_var != 'All Props':
|
| 451 |
-
if game_select_var == 'Draftkings':
|
| 452 |
-
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 453 |
-
elif game_select_var == 'Pick6':
|
| 454 |
-
prop_df = pick_frame[['Full_name', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 455 |
-
prop_df.rename(columns={"Full_name": "Player"}, inplace = True)
|
| 456 |
-
if prop_type_var == "points":
|
| 457 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'points']
|
| 458 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 459 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 460 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 461 |
-
st.table(prop_df)
|
| 462 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 463 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 464 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 465 |
-
elif prop_type_var == "rebounds":
|
| 466 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds']
|
| 467 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 468 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 469 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 470 |
-
st.table(prop_df)
|
| 471 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 472 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 473 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 474 |
-
elif prop_type_var == "assists":
|
| 475 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'assists']
|
| 476 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 477 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 478 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 479 |
-
st.table(prop_df)
|
| 480 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 481 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 482 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 483 |
-
elif prop_type_var == "threes":
|
| 484 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'threes']
|
| 485 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 486 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 487 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 488 |
-
st.table(prop_df)
|
| 489 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 490 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 491 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 492 |
-
elif prop_type_var == "PRA":
|
| 493 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'PRA']
|
| 494 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 495 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 496 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 497 |
-
st.table(prop_df)
|
| 498 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 499 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 500 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 501 |
-
elif prop_type_var == "points+rebounds":
|
| 502 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'points+rebounds']
|
| 503 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 504 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 505 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 506 |
-
st.table(prop_df)
|
| 507 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 508 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 509 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 510 |
-
elif prop_type_var == "points+assists":
|
| 511 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'points+assists']
|
| 512 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 513 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 514 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 515 |
-
st.table(prop_df)
|
| 516 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 517 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 518 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 519 |
-
elif prop_type_var == "rebounds+assists":
|
| 520 |
-
prop_df = prop_df.loc[prop_df['prop_type'] == 'rebounds+assists']
|
| 521 |
-
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 522 |
-
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 523 |
-
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 524 |
-
st.table(prop_df)
|
| 525 |
-
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+101)), 101/(prop_df['over_line']+101))
|
| 526 |
-
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+101)), 101/(prop_df['under_line']+101))
|
| 527 |
-
df = pd.merge(player_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 528 |
-
|
| 529 |
-
prop_dict = dict(zip(df.Player, df.Prop))
|
| 530 |
-
over_dict = dict(zip(df.Player, df.Over))
|
| 531 |
-
under_dict = dict(zip(df.Player, df.Under))
|
| 532 |
-
|
| 533 |
-
total_sims = 5000
|
| 534 |
-
|
| 535 |
-
df.replace("", 0, inplace=True)
|
| 536 |
-
|
| 537 |
-
if prop_type_var == 'points':
|
| 538 |
-
df['Median'] = df['Points']
|
| 539 |
-
elif prop_type_var == 'rebounds':
|
| 540 |
-
df['Median'] = df['Rebounds']
|
| 541 |
-
elif prop_type_var == 'assists':
|
| 542 |
-
df['Median'] = df['Assists']
|
| 543 |
-
elif prop_type_var == 'threes':
|
| 544 |
-
df['Median'] = df['3P']
|
| 545 |
-
elif prop_type_var == 'PRA':
|
| 546 |
-
df['Median'] = df['Points'] + df['Rebounds'] + df['Assists']
|
| 547 |
-
elif prop_type_var == 'points+rebounds':
|
| 548 |
-
df['Median'] = df['Points'] + df['Rebounds']
|
| 549 |
-
elif prop_type_var == 'points+assists':
|
| 550 |
-
df['Median'] = df['Points'] + df['Assists']
|
| 551 |
-
elif prop_type_var == 'rebounds+assists':
|
| 552 |
-
df['Median'] = df['Assists'] + df['Rebounds']
|
| 553 |
-
|
| 554 |
-
flex_file = df
|
| 555 |
-
flex_file['Floor'] = (flex_file['Median'] * .25) + (flex_file['Minutes'] * .25)
|
| 556 |
-
flex_file['Ceiling'] = flex_file['Median'] + 10 + (flex_file['Minutes'] * .25)
|
| 557 |
-
flex_file['STD'] = (flex_file['Median']/4)
|
| 558 |
-
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 559 |
-
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 560 |
-
|
| 561 |
-
hold_file = flex_file
|
| 562 |
-
overall_file = flex_file
|
| 563 |
-
prop_file = flex_file
|
| 564 |
-
|
| 565 |
-
overall_players = overall_file[['Player']]
|
| 566 |
-
|
| 567 |
-
for x in range(0,total_sims):
|
| 568 |
-
prop_file[x] = prop_file['Prop']
|
| 569 |
-
|
| 570 |
-
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 571 |
-
|
| 572 |
-
for x in range(0,total_sims):
|
| 573 |
-
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 574 |
-
|
| 575 |
-
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 576 |
-
|
| 577 |
-
players_only = hold_file[['Player']]
|
| 578 |
-
|
| 579 |
-
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 580 |
-
|
| 581 |
-
prop_check = (overall_file - prop_file)
|
| 582 |
-
|
| 583 |
-
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 584 |
-
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 585 |
-
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 586 |
-
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 587 |
-
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 588 |
-
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 589 |
-
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 590 |
-
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 591 |
-
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 592 |
-
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 593 |
-
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 594 |
-
players_only['prop_threshold'] = .10
|
| 595 |
-
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 596 |
-
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 597 |
-
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 598 |
-
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 599 |
-
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 600 |
-
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 601 |
-
players_only['Edge'] = players_only['Bet_check']
|
| 602 |
-
|
| 603 |
-
players_only['Player'] = hold_file[['Player']]
|
| 604 |
-
|
| 605 |
-
final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 606 |
|
| 607 |
-
|
| 608 |
-
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
| 609 |
-
|
| 610 |
-
with df_hold_container:
|
| 611 |
-
df_hold_container = st.empty()
|
| 612 |
-
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 613 |
-
with export_container:
|
| 614 |
-
export_container = st.empty()
|
| 615 |
-
st.download_button(
|
| 616 |
-
label="Export Projections",
|
| 617 |
-
data=convert_df_to_csv(final_outcomes),
|
| 618 |
-
file_name='Nba_prop_proj.csv',
|
| 619 |
-
mime='text/csv',
|
| 620 |
-
key='prop_proj',
|
| 621 |
-
)
|
|
|
|
| 37 |
|
| 38 |
gcservice_account = init_conn()
|
| 39 |
|
| 40 |
+
master_hold = 'https://docs.google.com/spreadsheets/d/1D526UlXmrz-8qxVcUKrA-u7f6FftUiBufxDnzQv980k/edit#gid=791804525'
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
@st.cache_resource(ttl = 600)
|
| 44 |
def init_baselines():
|
| 45 |
sh = gcservice_account.open_by_url(master_hold)
|
| 46 |
+
worksheet = sh.worksheet('Pitcher_Proj')
|
| 47 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 48 |
+
pitcher_proj = raw_display.dropna()
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
sh = gcservice_account.open_by_url(master_hold)
|
| 51 |
+
worksheet = sh.worksheet('Hitter_Proj')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 53 |
+
hitter_proj = raw_display.dropna()
|
|
|
|
| 54 |
|
| 55 |
+
return pitcher_proj, hitter_proj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def convert_df_to_csv(df):
|
| 58 |
return df.to_csv().encode('utf-8')
|
| 59 |
|
| 60 |
+
pitcher_proj, hitter_proj = init_baselines()
|
|
|
|
| 61 |
|
| 62 |
+
tab1, tab2, tab3, tab4 = st.tabs(["Pitcher Projections", "Hitter Projections", "Pitcher Simulations", "Hitter Simulations"])
|
| 63 |
|
| 64 |
with tab1:
|
|
|
|
| 65 |
if st.button("Reset Data", key='reset1'):
|
| 66 |
st.cache_data.clear()
|
| 67 |
+
pitcher_proj, hitter_proj = init_baselines()
|
| 68 |
+
raw_frame = pitcher_proj
|
| 69 |
+
export_frame = raw_frame[['Name', 'Team', 'TBF', 'Ceiling_var', 'True_AVG', 'Hits', 'Singles%', 'Singles', 'Doubles%', 'Doubles', 'xHR%', 'Homeruns', 'Strikeout%', 'Strikeouts',
|
| 70 |
+
'Walk%', 'Walks', 'Runs%', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 71 |
+
disp_frame = raw_frame[['Name', 'Team', 'TBF', 'True_AVG', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'Strikeouts',
|
| 72 |
+
'Walks', 'Runs', 'ERA', 'Wins', 'Quality_starts', 'ADP', 'UD_fpts']]
|
| 73 |
+
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
st.download_button(
|
| 76 |
+
label="Export Pitcher Projections",
|
| 77 |
+
data=convert_df_to_csv(export_frame),
|
| 78 |
+
file_name='MLB_pitcher_proj_export.csv',
|
| 79 |
mime='text/csv',
|
| 80 |
+
key='pitcher_proj_export',
|
| 81 |
)
|
| 82 |
|
| 83 |
with tab2:
|
|
|
|
| 84 |
if st.button("Reset Data", key='reset2'):
|
| 85 |
st.cache_data.clear()
|
| 86 |
+
pitcher_proj, hitter_proj = init_baselines()
|
| 87 |
+
raw_frame = hitter_proj
|
| 88 |
+
export_frame = raw_frame[['Name', 'Team', 'PA', 'Ceiling_var', 'Walk%', 'Walks', 'xHits', 'Singles%', 'Singles', 'Doubles%', 'Doubles',
|
| 89 |
+
'xHR%', 'Homeruns', 'Runs%', 'Runs', 'RBI%', 'RBI', 'Steal%', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 90 |
+
disp_frame = raw_frame[['Name', 'Team', 'PA', 'Walks', 'xHits', 'Singles', 'Doubles',
|
| 91 |
+
'Homeruns', 'Runs', 'RBI', 'Stolen_bases', 'UD_fpts', 'ADP']]
|
| 92 |
+
st.dataframe(disp_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 93 |
+
|
|
|
|
|
|
|
|
|
|
| 94 |
st.download_button(
|
| 95 |
+
label="Export Hitter Projections",
|
| 96 |
+
data=convert_df_to_csv(export_frame),
|
| 97 |
+
file_name='MLB_hitter_proj_export.csv',
|
| 98 |
mime='text/csv',
|
| 99 |
+
key='hitter_proj_export',
|
| 100 |
)
|
| 101 |
|
| 102 |
with tab3:
|
|
|
|
| 103 |
if st.button("Reset Data", key='reset3'):
|
| 104 |
st.cache_data.clear()
|
| 105 |
+
pitcher_proj, hitter_proj = init_baselines()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
col1, col2 = st.columns([1, 5])
|
| 107 |
|
| 108 |
with col2:
|
| 109 |
df_hold_container = st.empty()
|
|
|
|
|
|
|
| 110 |
|
| 111 |
with col1:
|
| 112 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Strikeouts', 'Wins', 'Quality_starts'])
|
| 113 |
+
|
| 114 |
+
if st.button('Simulate Stat'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
with col2:
|
| 116 |
|
| 117 |
with df_hold_container.container():
|
| 118 |
|
| 119 |
+
df = pitcher_proj
|
| 120 |
|
| 121 |
total_sims = 5000
|
| 122 |
|
| 123 |
df.replace("", 0, inplace=True)
|
| 124 |
|
| 125 |
+
if prop_type_var == 'Strikeouts':
|
| 126 |
+
df['Median'] = df['Strikeouts']
|
| 127 |
+
elif prop_type_var == 'Wins':
|
| 128 |
+
df['Median'] = df['Wins']
|
| 129 |
+
elif prop_type_var == 'Quality_starts':
|
| 130 |
+
df['Median'] = df['Quality_starts']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
flex_file = df
|
| 133 |
+
flex_file['Floor'] = (flex_file['Median'] * .25)
|
| 134 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * (1.25 * flex_file['Ceiling_var']))
|
| 135 |
flex_file['STD'] = (flex_file['Median']/4)
|
| 136 |
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 137 |
|
|
|
|
| 154 |
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 155 |
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 156 |
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 157 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 158 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 159 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 160 |
+
|
|
|
|
|
|
|
|
|
|
| 161 |
players_only['Player'] = hold_file[['Player']]
|
| 162 |
|
| 163 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '10%', 'Median', '90%']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 166 |
+
final_Proj = final_Proj[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '10%', 'Median', '90%']]
|
| 167 |
+
|
| 168 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 169 |
+
|
| 170 |
+
with tab4:
|
| 171 |
+
if st.button("Reset Data", key='reset4'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
st.cache_data.clear()
|
| 173 |
+
pitcher_proj, hitter_proj = init_baselines()
|
|
|
|
| 174 |
col1, col2 = st.columns([1, 5])
|
| 175 |
|
| 176 |
with col2:
|
| 177 |
df_hold_container = st.empty()
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
with col1:
|
| 180 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Strikeouts', 'Wins', 'Quality_starts'])
|
| 181 |
+
|
| 182 |
+
if st.button('Simulate Stat'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
with col2:
|
| 184 |
+
|
| 185 |
with df_hold_container.container():
|
| 186 |
+
|
| 187 |
+
df = pitcher_proj
|
| 188 |
+
|
| 189 |
+
total_sims = 5000
|
| 190 |
+
|
| 191 |
+
df.replace("", 0, inplace=True)
|
| 192 |
+
|
| 193 |
+
if prop_type_var == 'Strikeouts':
|
| 194 |
+
df['Median'] = df['Strikeouts']
|
| 195 |
+
elif prop_type_var == 'Wins':
|
| 196 |
+
df['Median'] = df['Wins']
|
| 197 |
+
elif prop_type_var == 'Quality_starts':
|
| 198 |
+
df['Median'] = df['Quality_starts']
|
| 199 |
+
|
| 200 |
+
flex_file = df
|
| 201 |
+
flex_file['Floor'] = (flex_file['Median'] * .25)
|
| 202 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * (1.25 * flex_file['Ceiling_var']))
|
| 203 |
+
flex_file['STD'] = (flex_file['Median']/4)
|
| 204 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 205 |
+
|
| 206 |
+
hold_file = flex_file
|
| 207 |
+
overall_file = flex_file
|
| 208 |
+
salary_file = flex_file
|
| 209 |
+
|
| 210 |
+
overall_players = overall_file[['Player']]
|
| 211 |
+
|
| 212 |
+
for x in range(0,total_sims):
|
| 213 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 214 |
+
|
| 215 |
+
overall_file=overall_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 216 |
+
overall_file.astype('int').dtypes
|
| 217 |
+
|
| 218 |
+
players_only = hold_file[['Player']]
|
| 219 |
+
|
| 220 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 221 |
+
|
| 222 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 223 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 224 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 225 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 226 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 227 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 228 |
+
|
| 229 |
+
players_only['Player'] = hold_file[['Player']]
|
| 230 |
+
|
| 231 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '10%', 'Median', '90%']]
|
| 232 |
+
|
| 233 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 234 |
+
final_Proj = final_Proj[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '10%', 'Median', '90%']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|