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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import gspread
|
| 5 |
+
import plotly.figure_factory as ff
|
| 6 |
+
|
| 7 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 8 |
+
"https://www.googleapis.com/auth/drive"]
|
| 9 |
+
|
| 10 |
+
credentials = {
|
| 11 |
+
"type": "service_account",
|
| 12 |
+
"project_id": "sheets-api-connect-378620",
|
| 13 |
+
"private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
|
| 14 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0B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\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
| 15 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 16 |
+
"client_id": "106625872877651920064",
|
| 17 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 18 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 19 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 20 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
gc = gspread.service_account_from_dict(credentials)
|
| 24 |
+
|
| 25 |
+
st.set_page_config(layout="wide")
|
| 26 |
+
|
| 27 |
+
game_format = {'Win Percentage': '{:.2%}','Cover Spread Percentage': '{:.2%}', 'First Inning Lead Percentage': '{:.2%}',
|
| 28 |
+
'Fifth Inning Lead Percentage': '{:.2%}'}
|
| 29 |
+
american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead Percentage': '{:.2%}'}
|
| 30 |
+
|
| 31 |
+
master_hold = 'https://docs.google.com/spreadsheets/d/1f42Ergav8K1VsOLOK9MUn7DM_MLMvv4GR2Fy7EfnZTc/edit#gid=340831852'
|
| 32 |
+
|
| 33 |
+
@st.cache_resource(ttl = 300)
|
| 34 |
+
def init_baselines():
|
| 35 |
+
sh = gc.open_by_url(master_hold)
|
| 36 |
+
worksheet = sh.worksheet('Pitcher_Stats')
|
| 37 |
+
props_frame_hold = pd.DataFrame(worksheet.get_all_records())
|
| 38 |
+
props_frame_hold.rename(columns={"Names": "Player"}, inplace = True)
|
| 39 |
+
props_frame_hold = props_frame_hold[['Player', 'Team', 'BB', 'Hits', 'HRs', 'ERs', 'Ks', 'Outs', 'Fantasy', 'FD_Fantasy', 'PrizePicks']]
|
| 40 |
+
pitcher_stats = props_frame_hold.drop_duplicates(subset='Player')
|
| 41 |
+
|
| 42 |
+
worksheet = sh.worksheet('Timestamp')
|
| 43 |
+
raw_stamp = worksheet.acell('a1').value
|
| 44 |
+
|
| 45 |
+
t_stamp = f"Last update was at {raw_stamp}"
|
| 46 |
+
|
| 47 |
+
worksheet = sh.worksheet('Hitter_Stats')
|
| 48 |
+
props_frame_hold = pd.DataFrame(worksheet.get_all_records())
|
| 49 |
+
props_frame_hold.rename(columns={"Names": "Player"}, inplace = True)
|
| 50 |
+
props_frame_hold = props_frame_hold[['Player', 'Team', 'Walks', 'Steals', 'Hits', 'Singles', 'Doubles', 'HRs', 'RBIs', 'Runs', 'Fantasy', 'FD_Fantasy', 'PrizePicks']]
|
| 51 |
+
props_frame_hold['Total Bases'] = props_frame_hold['Singles'] + (props_frame_hold['Doubles'] * 2) + (props_frame_hold['HRs'] * 4)
|
| 52 |
+
props_frame_hold['Hits + Runs + RBIs'] = props_frame_hold['Hits'] + props_frame_hold['Runs'] + props_frame_hold['RBIs']
|
| 53 |
+
hitter_stats = props_frame_hold.drop_duplicates(subset='Player')
|
| 54 |
+
|
| 55 |
+
worksheet = sh.worksheet('Game_Betting_Model')
|
| 56 |
+
team_frame = pd.DataFrame(worksheet.get_all_records())
|
| 57 |
+
team_frame = team_frame.drop_duplicates(subset='Names')
|
| 58 |
+
team_frame['Win Percentage'] = team_frame['Win Percentage'].str.replace('%', '').astype('float')/100
|
| 59 |
+
team_frame['Cover Spread Percentage'] = team_frame['Cover Spread Percentage'].str.replace('%', '').astype('float')/100
|
| 60 |
+
team_frame['ML_Value'] = team_frame['ML_Value'].str.replace('%', '').astype('float')/100
|
| 61 |
+
team_frame['Spread_Value'] = team_frame['Spread_Value'].str.replace('%', '').astype('float')/100
|
| 62 |
+
|
| 63 |
+
worksheet = sh.worksheet('prop_frame')
|
| 64 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 65 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 66 |
+
prop_frame = raw_display.dropna(subset='Team')
|
| 67 |
+
|
| 68 |
+
worksheet = sh.worksheet('Prop_results')
|
| 69 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 70 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 71 |
+
betsheet_frame = raw_display.dropna(subset='proj')
|
| 72 |
+
|
| 73 |
+
worksheet = sh.worksheet('Pick6_ingest')
|
| 74 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 75 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 76 |
+
pick_frame = raw_display.dropna(subset='Player')
|
| 77 |
+
|
| 78 |
+
return pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp
|
| 79 |
+
|
| 80 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 81 |
+
|
| 82 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Game Betting Model", "Pitcher Prop Projections", "Hitter Prop Projections", "Player Prop Simulations", "Stat Specific Simulations", "Bet Sheet"])
|
| 83 |
+
|
| 84 |
+
def convert_df_to_csv(df):
|
| 85 |
+
return df.to_csv().encode('utf-8')
|
| 86 |
+
|
| 87 |
+
with tab1:
|
| 88 |
+
st.info(t_stamp)
|
| 89 |
+
if st.button("Reset Data", key='reset1'):
|
| 90 |
+
st.cache_data.clear()
|
| 91 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 92 |
+
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
| 93 |
+
if line_var1 == 'Percentage':
|
| 94 |
+
team_frame = team_frame[['Names', 'Game', 'Moneyline', 'Win Percentage', 'ML_Value', 'Spread', 'Cover Spread Percentage', 'Spread_Value', 'Avg Score', 'Game Total', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage']]
|
| 95 |
+
team_frame = team_frame.set_index('Names')
|
| 96 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
| 97 |
+
if line_var1 == 'American':
|
| 98 |
+
team_frame = team_frame[['Names', 'Game', 'Moneyline', 'American ML', 'ML_Value', 'Spread', 'American Cover', 'Spread_Value', 'Avg Score', 'Game Total', 'Avg Fifth Inning', 'Fifth Inning Lead Percentage']]
|
| 99 |
+
team_frame.rename(columns={"American ML": "Win Percentage", "American Cover": "Cover Spread Percentage"}, inplace = True)
|
| 100 |
+
team_frame = team_frame.set_index('Names')
|
| 101 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(american_format, precision=2), use_container_width = True)
|
| 102 |
+
|
| 103 |
+
st.download_button(
|
| 104 |
+
label="Export Team Model",
|
| 105 |
+
data=convert_df_to_csv(team_frame),
|
| 106 |
+
file_name='MLB_team_betting_export.csv',
|
| 107 |
+
mime='text/csv',
|
| 108 |
+
key='team_export',
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
with tab2:
|
| 112 |
+
st.info(t_stamp)
|
| 113 |
+
if st.button("Reset Data", key='reset2'):
|
| 114 |
+
st.cache_data.clear()
|
| 115 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 116 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 117 |
+
if split_var1 == 'Specific Teams':
|
| 118 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = pitcher_stats['Team'].unique(), key='team_var1')
|
| 119 |
+
elif split_var1 == 'All':
|
| 120 |
+
team_var1 = pitcher_stats.Team.values.tolist()
|
| 121 |
+
pitcher_stats = pitcher_stats[pitcher_stats['Team'].isin(team_var1)]
|
| 122 |
+
pitcher_frame = pitcher_stats.set_index('Player')
|
| 123 |
+
pitcher_frame = pitcher_frame.sort_values(by='Ks', ascending=False)
|
| 124 |
+
st.dataframe(pitcher_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 125 |
+
st.download_button(
|
| 126 |
+
label="Export Prop Model",
|
| 127 |
+
data=convert_df_to_csv(pitcher_frame),
|
| 128 |
+
file_name='MLB_pitcher_prop_export.csv',
|
| 129 |
+
mime='text/csv',
|
| 130 |
+
key='pitcher_prop_export',
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
with tab3:
|
| 134 |
+
st.info(t_stamp)
|
| 135 |
+
if st.button("Reset Data", key='reset3'):
|
| 136 |
+
st.cache_data.clear()
|
| 137 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 138 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 139 |
+
if split_var2 == 'Specific Teams':
|
| 140 |
+
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = hitter_stats['Team'].unique(), key='team_var2')
|
| 141 |
+
elif split_var2 == 'All':
|
| 142 |
+
team_var2 = hitter_stats.Team.values.tolist()
|
| 143 |
+
hitter_stats = hitter_stats[hitter_stats['Team'].isin(team_var2)]
|
| 144 |
+
hitter_frame = hitter_stats.set_index('Player')
|
| 145 |
+
hitter_frame = hitter_frame.sort_values(by='Hits + Runs + RBIs', ascending=False)
|
| 146 |
+
st.dataframe(hitter_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 147 |
+
st.download_button(
|
| 148 |
+
label="Export Prop Model",
|
| 149 |
+
data=convert_df_to_csv(hitter_frame),
|
| 150 |
+
file_name='MLB_hitter_prop_export.csv',
|
| 151 |
+
mime='text/csv',
|
| 152 |
+
key='hitter_prop_export',
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
with tab4:
|
| 156 |
+
st.info(t_stamp)
|
| 157 |
+
if st.button("Reset Data", key='reset4'):
|
| 158 |
+
st.cache_data.clear()
|
| 159 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 160 |
+
col1, col2 = st.columns([1, 5])
|
| 161 |
+
|
| 162 |
+
with col2:
|
| 163 |
+
df_hold_container = st.empty()
|
| 164 |
+
info_hold_container = st.empty()
|
| 165 |
+
plot_hold_container = st.empty()
|
| 166 |
+
|
| 167 |
+
with col1:
|
| 168 |
+
prop_group_var = st.selectbox('What kind of props are you simulating?', options = ['Pitchers', 'Hitters'])
|
| 169 |
+
if prop_group_var == 'Pitchers':
|
| 170 |
+
player_check = st.selectbox('Select player to simulate props', options = pitcher_stats['Player'].unique())
|
| 171 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Strikeouts', 'Walks', 'Hits', 'Homeruns', 'Earned Runs', 'Outs', 'Fantasy', 'FD_Fantasy', 'PrizePicks'])
|
| 172 |
+
elif prop_group_var == 'Hitters':
|
| 173 |
+
player_check = st.selectbox('Select player to simulate props', options = hitter_stats['Player'].unique())
|
| 174 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Total Bases', 'Walks', 'Steals', 'Hits', 'Singles', 'Doubles', 'Homeruns', 'RBIs', 'Runs', 'Hits + Runs + RBIs', 'Fantasy', 'FD_Fantasy', 'PrizePicks'])
|
| 175 |
+
|
| 176 |
+
ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
|
| 177 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 5.5, step = .5)
|
| 178 |
+
line_var = st.number_input('Type in the line on the prop (i.e. -120)', min_value = -1000, max_value = 1000, value = -150, step = 1)
|
| 179 |
+
line_var = line_var + 1
|
| 180 |
+
|
| 181 |
+
if st.button('Simulate Prop'):
|
| 182 |
+
with col2:
|
| 183 |
+
|
| 184 |
+
with df_hold_container.container():
|
| 185 |
+
|
| 186 |
+
if prop_group_var == 'Pitchers':
|
| 187 |
+
df = pitcher_stats
|
| 188 |
+
elif prop_group_var == 'Hitters':
|
| 189 |
+
df = hitter_stats
|
| 190 |
+
|
| 191 |
+
total_sims = 1000
|
| 192 |
+
|
| 193 |
+
df.replace("", 0, inplace=True)
|
| 194 |
+
|
| 195 |
+
player_var = df.loc[df['Player'] == player_check]
|
| 196 |
+
player_var = player_var.reset_index()
|
| 197 |
+
|
| 198 |
+
if prop_group_var == 'Pitchers':
|
| 199 |
+
if prop_type_var == "Walks":
|
| 200 |
+
df['Median'] = df['BB']
|
| 201 |
+
elif prop_type_var == "Hits":
|
| 202 |
+
df['Median'] = df['Hits']
|
| 203 |
+
elif prop_type_var == "Homeruns":
|
| 204 |
+
df['Median'] = df['HRs']
|
| 205 |
+
elif prop_type_var == "Earned Runs":
|
| 206 |
+
df['Median'] = df['ERs']
|
| 207 |
+
elif prop_type_var == "Strikeouts":
|
| 208 |
+
df['Median'] = df['Ks']
|
| 209 |
+
elif prop_type_var == "Outs":
|
| 210 |
+
df['Median'] = df['Outs']
|
| 211 |
+
elif prop_type_var == "Fantasy":
|
| 212 |
+
df['Median'] = df['Fantasy']
|
| 213 |
+
elif prop_type_var == "FD_Fantasy":
|
| 214 |
+
df['Median'] = df['FD_Fantasy']
|
| 215 |
+
elif prop_type_var == "PrizePicks":
|
| 216 |
+
df['Median'] = df['PrizePicks']
|
| 217 |
+
elif prop_group_var == 'Hitters':
|
| 218 |
+
if prop_type_var == "Walks":
|
| 219 |
+
df['Median'] = df['Walks']
|
| 220 |
+
elif prop_type_var == "Total Bases":
|
| 221 |
+
df['Median'] = df['Total Bases']
|
| 222 |
+
elif prop_type_var == "Hits + Runs + RBIs":
|
| 223 |
+
df['Median'] = df['Hits + Runs + RBIs']
|
| 224 |
+
elif prop_type_var == "Steals":
|
| 225 |
+
df['Median'] = df['Steals']
|
| 226 |
+
elif prop_type_var == "Hits":
|
| 227 |
+
df['Median'] = df['Hits']
|
| 228 |
+
elif prop_type_var == "Singles":
|
| 229 |
+
df['Median'] = df['Singles']
|
| 230 |
+
elif prop_type_var == "Doubles":
|
| 231 |
+
df['Median'] = df['Doubles']
|
| 232 |
+
elif prop_type_var == "Homeruns":
|
| 233 |
+
df['Median'] = df['HRs']
|
| 234 |
+
elif prop_type_var == "RBIs":
|
| 235 |
+
df['Median'] = df['RBIs']
|
| 236 |
+
elif prop_type_var == "Runs":
|
| 237 |
+
df['Median'] = df['Runs']
|
| 238 |
+
elif prop_type_var == "Fantasy":
|
| 239 |
+
df['Median'] = df['Fantasy']
|
| 240 |
+
elif prop_type_var == "FD_Fantasy":
|
| 241 |
+
df['Median'] = df['FD_Fantasy']
|
| 242 |
+
elif prop_type_var == "PrizePicks":
|
| 243 |
+
df['Median'] = df['PrizePicks']
|
| 244 |
+
|
| 245 |
+
flex_file = df
|
| 246 |
+
if prop_group_var == 'Pitchers':
|
| 247 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 248 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .80)
|
| 249 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 250 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 251 |
+
|
| 252 |
+
elif prop_group_var == 'Hitters':
|
| 253 |
+
flex_file['Floor'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * .20, 0)
|
| 254 |
+
flex_file['Ceiling'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] + (flex_file['Median'] * .80), flex_file['Median'] * 4)
|
| 255 |
+
flex_file['STD'] = flex_file['Median'] / 1.5
|
| 256 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 257 |
+
|
| 258 |
+
hold_file = flex_file
|
| 259 |
+
overall_file = flex_file
|
| 260 |
+
salary_file = flex_file
|
| 261 |
+
|
| 262 |
+
overall_players = overall_file[['Player']]
|
| 263 |
+
|
| 264 |
+
for x in range(0,total_sims):
|
| 265 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 266 |
+
|
| 267 |
+
overall_file=overall_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 268 |
+
overall_file.astype('int').dtypes
|
| 269 |
+
|
| 270 |
+
players_only = hold_file[['Player']]
|
| 271 |
+
|
| 272 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 273 |
+
|
| 274 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 275 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 276 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 277 |
+
if ou_var == 'Over':
|
| 278 |
+
players_only['beat_prop'] = overall_file[overall_file > prop_var].count(axis=1)/float(total_sims)
|
| 279 |
+
elif ou_var == 'Under':
|
| 280 |
+
players_only['beat_prop'] = (overall_file[overall_file < prop_var].count(axis=1)/float(total_sims))
|
| 281 |
+
|
| 282 |
+
players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))
|
| 283 |
+
|
| 284 |
+
players_only['Player'] = hold_file[['Player']]
|
| 285 |
+
|
| 286 |
+
final_outcomes = players_only[['Player', '10%', 'Mean_Outcome', '90%', 'implied_odds', 'beat_prop']]
|
| 287 |
+
final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
|
| 288 |
+
final_outcomes = final_outcomes.loc[final_outcomes['Player'] == player_check]
|
| 289 |
+
player_outcomes = player_outcomes.loc[player_outcomes['Player'] == player_check]
|
| 290 |
+
player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
|
| 291 |
+
player_outcomes = player_outcomes.reset_index()
|
| 292 |
+
player_outcomes.columns = ['Instance', 'Outcome']
|
| 293 |
+
|
| 294 |
+
x1 = player_outcomes.Outcome.to_numpy()
|
| 295 |
+
|
| 296 |
+
print(x1)
|
| 297 |
+
|
| 298 |
+
hist_data = [x1]
|
| 299 |
+
|
| 300 |
+
group_labels = ['player outcomes']
|
| 301 |
+
|
| 302 |
+
fig = ff.create_distplot(
|
| 303 |
+
hist_data, group_labels, bin_size=[.05])
|
| 304 |
+
fig.add_vline(x=prop_var, line_dash="dash", line_color="green")
|
| 305 |
+
|
| 306 |
+
with df_hold_container:
|
| 307 |
+
df_hold_container = st.empty()
|
| 308 |
+
format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
|
| 309 |
+
st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)
|
| 310 |
+
|
| 311 |
+
with info_hold_container:
|
| 312 |
+
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.')
|
| 313 |
+
|
| 314 |
+
with plot_hold_container:
|
| 315 |
+
st.dataframe(player_outcomes, use_container_width = True)
|
| 316 |
+
plot_hold_container = st.empty()
|
| 317 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 318 |
+
|
| 319 |
+
with tab5:
|
| 320 |
+
st.info(t_stamp)
|
| 321 |
+
st.info('The Over and Under percentages are a compositve 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.')
|
| 322 |
+
if st.button("Reset Data/Load Data", key='reset5'):
|
| 323 |
+
# Clear values from *all* all in-memory and on-disk data caches:
|
| 324 |
+
# i.e. clear values from both square and cube
|
| 325 |
+
st.cache_data.clear()
|
| 326 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, pick_frame, t_stamp = init_baselines()
|
| 327 |
+
col1, col2 = st.columns([1, 5])
|
| 328 |
+
|
| 329 |
+
with col2:
|
| 330 |
+
df_hold_container = st.empty()
|
| 331 |
+
info_hold_container = st.empty()
|
| 332 |
+
plot_hold_container = st.empty()
|
| 333 |
+
export_container = st.empty()
|
| 334 |
+
|
| 335 |
+
with col1:
|
| 336 |
+
game_select_var = st.selectbox('Select prop source', options = ['Draftkings', 'Pick6'])
|
| 337 |
+
if game_select_var == 'Draftkings':
|
| 338 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 339 |
+
working_source = prop_frame.copy
|
| 340 |
+
elif game_select_var == 'Pick6':
|
| 341 |
+
prop_df = pick_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 342 |
+
working_source = pick_frame.copy()
|
| 343 |
+
st.download_button(
|
| 344 |
+
label="Download Prop Source",
|
| 345 |
+
data=convert_df_to_csv(prop_df),
|
| 346 |
+
file_name='MLB_prop_source.csv',
|
| 347 |
+
mime='text/csv',
|
| 348 |
+
key='prop_source',
|
| 349 |
+
)
|
| 350 |
+
prop_type_var = st.selectbox('Select prop category', options = ['Strikeouts (Pitchers)', 'Total Outs (Pitchers)', 'Earned Runs (Pitchers)', 'Hits Against (Pitchers)',
|
| 351 |
+
'Walks Allowed (Pitchers)', 'Total Bases (Hitters)', 'Stolen Bases (Hitters)'])
|
| 352 |
+
|
| 353 |
+
if st.button('Simulate Prop Category'):
|
| 354 |
+
with col2:
|
| 355 |
+
|
| 356 |
+
with df_hold_container.container():
|
| 357 |
+
|
| 358 |
+
if prop_type_var == "Strikeouts (Pitchers)":
|
| 359 |
+
player_df = pitcher_stats
|
| 360 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'pitcher_strikeouts']
|
| 361 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 362 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 363 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 364 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 365 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 366 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 367 |
+
elif prop_type_var == "Total Outs (Pitchers)":
|
| 368 |
+
player_df = pitcher_stats
|
| 369 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'pitcher_outs']
|
| 370 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 371 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 372 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 373 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 374 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 375 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 376 |
+
elif prop_type_var == "Earned Runs (Pitchers)":
|
| 377 |
+
player_df = pitcher_stats
|
| 378 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'pitcher_earned_runs']
|
| 379 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 380 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 381 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 382 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 383 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 384 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 385 |
+
elif prop_type_var == "Hits Against (Pitchers)":
|
| 386 |
+
player_df = pitcher_stats
|
| 387 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'pitcher_hits_allowed']
|
| 388 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 389 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 390 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 391 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 392 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 393 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 394 |
+
elif prop_type_var == "Walks Allowed (Pitchers)":
|
| 395 |
+
player_df = pitcher_stats
|
| 396 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'pitcher_walks']
|
| 397 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 398 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 399 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 400 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 401 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 402 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 403 |
+
elif prop_type_var == "Total Bases (Hitters)":
|
| 404 |
+
player_df = hitter_stats
|
| 405 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'batter_total_bases']
|
| 406 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 407 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 408 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 409 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 410 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 411 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 412 |
+
elif prop_type_var == "Stolen Bases (Hitters)":
|
| 413 |
+
player_df = hitter_stats
|
| 414 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'batter_stolen_bases']
|
| 415 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 416 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 417 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 418 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 419 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 420 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 421 |
+
elif prop_type_var == "Hits (Hitters)":
|
| 422 |
+
player_df = hitter_stats
|
| 423 |
+
prop_df = prop_frame[prop_frame['prop_type'] == 'batter_hits']
|
| 424 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 425 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 426 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 427 |
+
prop_df['Over'] = np.where(prop_df['over_line'] < 0, (-(prop_df['over_line'])/((-(prop_df['over_line']))+100)), 100/(prop_df['over_line']+100))
|
| 428 |
+
prop_df['Under'] = np.where(prop_df['under_line'] < 0, (-(prop_df['under_line'])/((-(prop_df['under_line']))+100)), 100/(prop_df['under_line']+100))
|
| 429 |
+
df = pd.merge(player_df, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 430 |
+
|
| 431 |
+
prop_dict = dict(zip(df.Player, df.Prop))
|
| 432 |
+
over_dict = dict(zip(df.Player, df.Over))
|
| 433 |
+
under_dict = dict(zip(df.Player, df.Under))
|
| 434 |
+
|
| 435 |
+
total_sims = 1000
|
| 436 |
+
|
| 437 |
+
df.replace("", 0, inplace=True)
|
| 438 |
+
|
| 439 |
+
if prop_type_var == "Strikeouts (Pitchers)":
|
| 440 |
+
df['Median'] = df['Ks']
|
| 441 |
+
elif prop_type_var == "Earned Runs (Pitchers)":
|
| 442 |
+
df['Median'] = df['ERs']
|
| 443 |
+
elif prop_type_var == "Total Outs (Pitchers)":
|
| 444 |
+
df['Median'] = df['Outs']
|
| 445 |
+
elif prop_type_var == "Hits Against (Pitchers)":
|
| 446 |
+
df['Median'] = df['Hits']
|
| 447 |
+
elif prop_type_var == "Walks Allowed (Pitchers)":
|
| 448 |
+
df['Median'] = df['BB']
|
| 449 |
+
elif prop_type_var == "Total Bases (Hitters)":
|
| 450 |
+
df['Median'] = df['Total Bases']
|
| 451 |
+
elif prop_type_var == "Stolen Bases (Hitters)":
|
| 452 |
+
df['Median'] = df['Stolen Bases (Hitters)']
|
| 453 |
+
|
| 454 |
+
flex_file = df
|
| 455 |
+
if prop_type_var == 'Strikeouts (Pitchers)':
|
| 456 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 457 |
+
flex_file['Ceiling'] = flex_file['Median'] * 1.8
|
| 458 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 459 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 460 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 461 |
+
|
| 462 |
+
elif prop_type_var == 'Total Outs (Pitchers)':
|
| 463 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 464 |
+
flex_file['Ceiling'] = flex_file['Median'] * 1.8
|
| 465 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 466 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 467 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 468 |
+
|
| 469 |
+
elif prop_type_var == 'Earned Runs (Pitchers)':
|
| 470 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 471 |
+
flex_file['Ceiling'] = flex_file['Median'] * 1.8
|
| 472 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 473 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 474 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 475 |
+
|
| 476 |
+
elif prop_type_var == 'Hits Against (Pitchers)':
|
| 477 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 478 |
+
flex_file['Ceiling'] = flex_file['Median'] * 1.8
|
| 479 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 480 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 481 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 482 |
+
|
| 483 |
+
elif prop_type_var == 'Walks Allowed (Pitchers)':
|
| 484 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 485 |
+
flex_file['Ceiling'] = flex_file['Median'] * 1.8
|
| 486 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 487 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 488 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 489 |
+
|
| 490 |
+
elif prop_type_var == 'Total Bases (Hitters)':
|
| 491 |
+
flex_file['Floor'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * .20, 0)
|
| 492 |
+
flex_file['Ceiling'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * 1.8, flex_file['Median'] * 4)
|
| 493 |
+
flex_file['STD'] = flex_file['Median'] / 1.5
|
| 494 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 495 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 496 |
+
|
| 497 |
+
elif prop_type_var == 'Stolen Bases (Hitters)':
|
| 498 |
+
flex_file['Floor'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * .20, 0)
|
| 499 |
+
flex_file['Ceiling'] = np.where((prop_type_var == "Fantasy") | (prop_type_var == "FD_Fantasy") | (prop_type_var == "PrizePicks"), flex_file['Median'] * 1.8, flex_file['Median'] * 4)
|
| 500 |
+
flex_file['STD'] = flex_file['Median'] / 1.5
|
| 501 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 502 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 503 |
+
|
| 504 |
+
hold_file = flex_file
|
| 505 |
+
overall_file = flex_file
|
| 506 |
+
prop_file = flex_file
|
| 507 |
+
|
| 508 |
+
overall_players = overall_file[['Player']]
|
| 509 |
+
|
| 510 |
+
for x in range(0,total_sims):
|
| 511 |
+
prop_file[x] = prop_file['Prop']
|
| 512 |
+
|
| 513 |
+
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 514 |
+
|
| 515 |
+
for x in range(0,total_sims):
|
| 516 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 517 |
+
|
| 518 |
+
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 519 |
+
|
| 520 |
+
players_only = hold_file[['Player']]
|
| 521 |
+
|
| 522 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 523 |
+
|
| 524 |
+
prop_check = (overall_file - prop_file)
|
| 525 |
+
|
| 526 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 527 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 528 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 529 |
+
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 530 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 531 |
+
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 532 |
+
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 533 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 534 |
+
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 535 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 536 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 537 |
+
players_only['prop_threshold'] = .10
|
| 538 |
+
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 539 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 540 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 541 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 542 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 543 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 544 |
+
players_only['Edge'] = players_only['Bet_check']
|
| 545 |
+
|
| 546 |
+
players_only['Player'] = hold_file[['Player']]
|
| 547 |
+
|
| 548 |
+
final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 549 |
+
|
| 550 |
+
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
| 551 |
+
|
| 552 |
+
final_outcomes = final_outcomes.set_index('Player')
|
| 553 |
+
|
| 554 |
+
with df_hold_container:
|
| 555 |
+
df_hold_container = st.empty()
|
| 556 |
+
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 557 |
+
with export_container:
|
| 558 |
+
export_container = st.empty()
|
| 559 |
+
st.download_button(
|
| 560 |
+
label="Export Projections",
|
| 561 |
+
data=convert_df_to_csv(final_outcomes),
|
| 562 |
+
file_name='MLB_DFS_prop_proj.csv',
|
| 563 |
+
mime='text/csv',
|
| 564 |
+
key='prop_proj',
|
| 565 |
+
)
|
| 566 |
+
|
| 567 |
+
with tab6:
|
| 568 |
+
col1, col2, col3 = st.columns([2, 2, 2])
|
| 569 |
+
st.info(t_stamp)
|
| 570 |
+
st.info('This sheet is more or less a static represenation of the Stat Specific Simulations. ROR is rate of return based on hit rate and payout. Use the over and under EDGEs to place bets. 20%+ should be considered a 1 unit bet, 15-20% is .75 units, 10-15% is .50 units, 5-10% is .25 units, and 0-5% is .1 units.')
|
| 571 |
+
if st.button("Reset Data", key='reset6'):
|
| 572 |
+
st.cache_data.clear()
|
| 573 |
+
pitcher_stats, hitter_stats, team_frame, prop_frame, betsheet_frame, pick_frame, t_stamp = init_baselines()
|
| 574 |
+
with col1:
|
| 575 |
+
split_var6 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var6')
|
| 576 |
+
if split_var6 == 'Specific Teams':
|
| 577 |
+
team_var6 = st.multiselect('Which teams would you like to include in the tables?', options = betsheet_frame['Team'].unique(), key='team_var6')
|
| 578 |
+
elif split_var6 == 'All':
|
| 579 |
+
team_var6 = betsheet_frame.Team.values.tolist()
|
| 580 |
+
with col2:
|
| 581 |
+
prop_choice_var6 = st.radio("Would you like to view all prop types or specific ones?", ('All', 'Specific Props'), key='prop_choice_var6')
|
| 582 |
+
if prop_choice_var6 == 'Specific Props':
|
| 583 |
+
prop_var6 = st.multiselect('Which props would you like to include in the tables?', options = betsheet_frame['prop_type'].unique(), key='prop_var6')
|
| 584 |
+
elif prop_choice_var6 == 'All':
|
| 585 |
+
prop_var6 = betsheet_frame.prop_type.values.tolist()
|
| 586 |
+
with col3:
|
| 587 |
+
player_choice_var6 = st.radio("Would you like to view all players props or specific ones?", ('All', 'Specific Players'), key='player_choice_var6')
|
| 588 |
+
if player_choice_var6 == 'Specific Players':
|
| 589 |
+
player_var6 = st.multiselect('Which players would you like to include in the tables?', options = betsheet_frame['Player'].unique(), key='player_var6')
|
| 590 |
+
elif player_choice_var6 == 'All':
|
| 591 |
+
player_var6 = betsheet_frame.Player.values.tolist()
|
| 592 |
+
betsheet_disp = betsheet_frame.copy()
|
| 593 |
+
betsheet_disp = betsheet_disp[betsheet_disp['Team'].isin(team_var6)]
|
| 594 |
+
betsheet_disp = betsheet_disp[betsheet_disp['prop_type'].isin(prop_var6)]
|
| 595 |
+
betsheet_disp = betsheet_disp[betsheet_disp['Player'].isin(player_var6)]
|
| 596 |
+
betsheet_disp = betsheet_disp.sort_values(by='over_EDGE', ascending=False)
|
| 597 |
+
st.dataframe(betsheet_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=750, use_container_width = True)
|
| 598 |
+
st.download_button(
|
| 599 |
+
label="Export Betsheet",
|
| 600 |
+
data=convert_df_to_csv(betsheet_disp),
|
| 601 |
+
file_name='MLB_Betsheet_export.csv',
|
| 602 |
+
mime='text/csv',
|
| 603 |
+
key='MLB_Betsheet_export',
|
| 604 |
+
)
|
app.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
runtime: python
|
| 2 |
+
env: flex
|
| 3 |
+
|
| 4 |
+
runtime_config:
|
| 5 |
+
python_version: 3
|
| 6 |
+
|
| 7 |
+
entrypoint: streamlit run streamlit-app.py --server.port $PORT
|
| 8 |
+
|
| 9 |
+
automatic_scaling:
|
| 10 |
+
max_num_instances: 200
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
gspread
|
| 3 |
+
openpyxl
|
| 4 |
+
matplotlib
|
| 5 |
+
pymongo
|
| 6 |
+
pulp
|
| 7 |
+
docker
|
| 8 |
+
plotly
|
| 9 |
+
scipy
|