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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pulp
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import random
|
| 5 |
+
import sys
|
| 6 |
+
import openpyxl
|
| 7 |
+
import re
|
| 8 |
+
import time
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import matplotlib
|
| 11 |
+
from matplotlib.colors import LinearSegmentedColormap
|
| 12 |
+
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
|
| 13 |
+
import json
|
| 14 |
+
import requests
|
| 15 |
+
import gspread
|
| 16 |
+
import plotly.express as px
|
| 17 |
+
|
| 18 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 19 |
+
"https://www.googleapis.com/auth/drive"]
|
| 20 |
+
|
| 21 |
+
credentials = {
|
| 22 |
+
"type": "service_account",
|
| 23 |
+
"project_id": "sheets-api-connect-378620",
|
| 24 |
+
"private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
|
| 25 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\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",
|
| 26 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 27 |
+
"client_id": "106625872877651920064",
|
| 28 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 29 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 30 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 31 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
gc = gspread.service_account_from_dict(credentials)
|
| 35 |
+
|
| 36 |
+
st.set_page_config(layout="wide")
|
| 37 |
+
|
| 38 |
+
game_format = {'Win%': '{:.2%}', 'Vegas': '{:.2%}', 'Win% Diff': '{:.2%}'}
|
| 39 |
+
american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead Percentage': '{:.2%}'}
|
| 40 |
+
|
| 41 |
+
master_hold = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=694077504'
|
| 42 |
+
|
| 43 |
+
@st.cache_data
|
| 44 |
+
def game_betting_model():
|
| 45 |
+
sh = gc.open_by_url(master_hold)
|
| 46 |
+
worksheet = sh.worksheet('Game_Betting')
|
| 47 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 48 |
+
raw_display.replace('#DIV/0!', np.nan, inplace=True)
|
| 49 |
+
raw_display = raw_display.dropna()
|
| 50 |
+
|
| 51 |
+
return raw_display
|
| 52 |
+
|
| 53 |
+
@st.cache_data
|
| 54 |
+
def player_stat_table():
|
| 55 |
+
sh = gc.open_by_url(master_hold)
|
| 56 |
+
worksheet = sh.worksheet('Prop_Table')
|
| 57 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 58 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 59 |
+
raw_display = raw_display.dropna()
|
| 60 |
+
|
| 61 |
+
return raw_display
|
| 62 |
+
|
| 63 |
+
@st.cache_data
|
| 64 |
+
def player_prop_table():
|
| 65 |
+
sh = gc.open_by_url(master_hold)
|
| 66 |
+
worksheet = sh.worksheet('prop_frame')
|
| 67 |
+
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 68 |
+
raw_display.replace('', np.nan, inplace=True)
|
| 69 |
+
raw_display = raw_display.dropna()
|
| 70 |
+
|
| 71 |
+
return raw_display
|
| 72 |
+
|
| 73 |
+
return raw_display
|
| 74 |
+
|
| 75 |
+
game_model = game_betting_model()
|
| 76 |
+
overall_stats = player_stat_table()
|
| 77 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 78 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 79 |
+
prop_frame = player_prop_table()
|
| 80 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 81 |
+
|
| 82 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Game Betting Model", "QB Projections", "RB/WR/TE Projections", "Player Prop Simulations", "Stat Specific Simulations"])
|
| 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 |
+
game_model = game_betting_model()
|
| 92 |
+
overall_stats = player_stat_table()
|
| 93 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 94 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 95 |
+
prop_frame = player_prop_table()
|
| 96 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 97 |
+
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
| 98 |
+
team_frame = game_model
|
| 99 |
+
if line_var1 == 'Percentage':
|
| 100 |
+
team_frame = team_frame[['team', 'Opp', 'Win%', 'Vegas', 'Win% Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
|
| 101 |
+
team_frame = team_frame.set_index('team')
|
| 102 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
| 103 |
+
if line_var1 == 'American':
|
| 104 |
+
team_frame = team_frame[['team', 'Opp', 'Win Line', 'Vegas Line', 'Line Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
|
| 105 |
+
team_frame = team_frame.set_index('team')
|
| 106 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 107 |
+
|
| 108 |
+
st.download_button(
|
| 109 |
+
label="Export Team Model",
|
| 110 |
+
data=convert_df_to_csv(team_frame),
|
| 111 |
+
file_name='NFL_team_betting_export.csv',
|
| 112 |
+
mime='text/csv',
|
| 113 |
+
key='team_export',
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
with tab2:
|
| 117 |
+
st.info(t_stamp)
|
| 118 |
+
if st.button("Reset Data", key='reset2'):
|
| 119 |
+
st.cache_data.clear()
|
| 120 |
+
game_model = game_betting_model()
|
| 121 |
+
overall_stats = player_stat_table()
|
| 122 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 123 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 124 |
+
prop_frame = player_prop_table()
|
| 125 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 126 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
| 127 |
+
if split_var1 == 'Specific Teams':
|
| 128 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = qb_stats['Team'].unique(), key='team_var1')
|
| 129 |
+
elif split_var1 == 'All':
|
| 130 |
+
team_var1 = qb_stats.Team.values.tolist()
|
| 131 |
+
qb_stats = qb_stats[qb_stats['Team'].isin(team_var1)]
|
| 132 |
+
qb_stats_disp = qb_stats.set_index('Player')
|
| 133 |
+
qb_stats_disp = qb_stats_disp.sort_values(by='PPR', ascending=False)
|
| 134 |
+
st.dataframe(qb_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 135 |
+
st.download_button(
|
| 136 |
+
label="Export Prop Model",
|
| 137 |
+
data=convert_df_to_csv(qb_stats_disp),
|
| 138 |
+
file_name='NFL_qb_stats_export.csv',
|
| 139 |
+
mime='text/csv',
|
| 140 |
+
key='pitcher_prop_export',
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
with tab3:
|
| 144 |
+
st.info(t_stamp)
|
| 145 |
+
if st.button("Reset Data", key='reset3'):
|
| 146 |
+
st.cache_data.clear()
|
| 147 |
+
game_model = game_betting_model()
|
| 148 |
+
overall_stats = player_stat_table()
|
| 149 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 150 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 151 |
+
prop_frame = player_prop_table()
|
| 152 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 153 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
| 154 |
+
if split_var2 == 'Specific Teams':
|
| 155 |
+
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = non_qb_stats['Team'].unique(), key='team_var2')
|
| 156 |
+
elif split_var2 == 'All':
|
| 157 |
+
team_var2 = non_qb_stats.Team.values.tolist()
|
| 158 |
+
non_qb_stats = non_qb_stats[non_qb_stats['Team'].isin(team_var2)]
|
| 159 |
+
non_qb_stats_disp = non_qb_stats.set_index('Player')
|
| 160 |
+
non_qb_stats_disp = non_qb_stats_disp.sort_values(by='PPR', ascending=False)
|
| 161 |
+
st.dataframe(non_qb_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 162 |
+
st.download_button(
|
| 163 |
+
label="Export Prop Model",
|
| 164 |
+
data=convert_df_to_csv(non_qb_stats_disp),
|
| 165 |
+
file_name='NFL_nonqb_stats_export.csv',
|
| 166 |
+
mime='text/csv',
|
| 167 |
+
key='hitter_prop_export',
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
with tab4:
|
| 171 |
+
st.info(t_stamp)
|
| 172 |
+
if st.button("Reset Data", key='reset4'):
|
| 173 |
+
st.cache_data.clear()
|
| 174 |
+
game_model = game_betting_model()
|
| 175 |
+
overall_stats = player_stat_table()
|
| 176 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 177 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 178 |
+
prop_frame = player_prop_table()
|
| 179 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 180 |
+
col1, col2 = st.columns([1, 5])
|
| 181 |
+
|
| 182 |
+
with col2:
|
| 183 |
+
df_hold_container = st.empty()
|
| 184 |
+
info_hold_container = st.empty()
|
| 185 |
+
plot_hold_container = st.empty()
|
| 186 |
+
|
| 187 |
+
with col1:
|
| 188 |
+
player_check = st.selectbox('Select player to simulate props', options = overall_stats['Player'].unique())
|
| 189 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Pass Yards', 'Pass TDs', 'Rush Yards', 'Rush TDs', 'Receptions', 'Rec Yards', 'Rec TDs', 'Fantasy', 'FD Fantasy', 'PrizePicks'])
|
| 190 |
+
|
| 191 |
+
ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
|
| 192 |
+
if prop_type_var == 'Pass Yards':
|
| 193 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 100.0, max_value = 400.5, value = 250.5, step = .5)
|
| 194 |
+
elif prop_type_var == 'Pass TDs':
|
| 195 |
+
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)
|
| 196 |
+
elif prop_type_var == 'Rush Yards':
|
| 197 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 155.5, value = 25.5, step = .5)
|
| 198 |
+
elif prop_type_var == 'Rush TDs':
|
| 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 == 'Receptions':
|
| 201 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 15.5, value = 5.5, step = .5)
|
| 202 |
+
elif prop_type_var == 'Rec Yards':
|
| 203 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 155.5, value = 25.5, step = .5)
|
| 204 |
+
elif prop_type_var == 'Rec TDs':
|
| 205 |
+
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)
|
| 206 |
+
elif prop_type_var == 'Fantasy':
|
| 207 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
| 208 |
+
elif prop_type_var == 'FD Fantasy':
|
| 209 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
| 210 |
+
elif prop_type_var == 'PrizePicks':
|
| 211 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
| 212 |
+
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)
|
| 213 |
+
line_var = line_var + 1
|
| 214 |
+
|
| 215 |
+
if st.button('Simulate Prop'):
|
| 216 |
+
with col2:
|
| 217 |
+
|
| 218 |
+
with df_hold_container.container():
|
| 219 |
+
|
| 220 |
+
df = overall_stats
|
| 221 |
+
|
| 222 |
+
total_sims = 5000
|
| 223 |
+
|
| 224 |
+
df.replace("", 0, inplace=True)
|
| 225 |
+
|
| 226 |
+
player_var = df.loc[df['Player'] == player_check]
|
| 227 |
+
player_var = player_var.reset_index()
|
| 228 |
+
|
| 229 |
+
if prop_type_var == 'Pass Yards':
|
| 230 |
+
df['Median'] = df['pass_yards']
|
| 231 |
+
elif prop_type_var == 'Pass TDs':
|
| 232 |
+
df['Median'] = df['pass_tds']
|
| 233 |
+
elif prop_type_var == 'Rush Yards':
|
| 234 |
+
df['Median'] = df['rush_yards']
|
| 235 |
+
elif prop_type_var == 'Rush TDs':
|
| 236 |
+
df['Median'] = df['rush_tds']
|
| 237 |
+
elif prop_type_var == 'Receptions':
|
| 238 |
+
df['Median'] = df['rec']
|
| 239 |
+
elif prop_type_var == 'Rec Yards':
|
| 240 |
+
df['Median'] = df['rec_yards']
|
| 241 |
+
elif prop_type_var == 'Rec TDs':
|
| 242 |
+
df['Median'] = df['rec_tds']
|
| 243 |
+
elif prop_type_var == 'Fantasy':
|
| 244 |
+
df['Median'] = df['PPR']
|
| 245 |
+
elif prop_type_var == 'FD Fantasy':
|
| 246 |
+
df['Median'] = df['Half_PPF']
|
| 247 |
+
elif prop_type_var == 'PrizePicks':
|
| 248 |
+
df['Median'] = df['Half_PPF']
|
| 249 |
+
|
| 250 |
+
flex_file = df
|
| 251 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 252 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .80)
|
| 253 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 254 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 255 |
+
|
| 256 |
+
hold_file = flex_file
|
| 257 |
+
overall_file = flex_file
|
| 258 |
+
salary_file = flex_file
|
| 259 |
+
|
| 260 |
+
overall_players = overall_file[['Player']]
|
| 261 |
+
|
| 262 |
+
for x in range(0,total_sims):
|
| 263 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 264 |
+
|
| 265 |
+
overall_file=overall_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 266 |
+
overall_file.astype('int').dtypes
|
| 267 |
+
|
| 268 |
+
players_only = hold_file[['Player']]
|
| 269 |
+
|
| 270 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 271 |
+
|
| 272 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 273 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 274 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 275 |
+
if ou_var == 'Over':
|
| 276 |
+
players_only['beat_prop'] = overall_file[overall_file > prop_var].count(axis=1)/float(total_sims)
|
| 277 |
+
elif ou_var == 'Under':
|
| 278 |
+
players_only['beat_prop'] = (overall_file[overall_file < prop_var].count(axis=1)/float(total_sims))
|
| 279 |
+
|
| 280 |
+
players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))
|
| 281 |
+
|
| 282 |
+
players_only['Player'] = hold_file[['Player']]
|
| 283 |
+
|
| 284 |
+
final_outcomes = players_only[['Player', '10%', 'Mean_Outcome', '90%', 'implied_odds', 'beat_prop']]
|
| 285 |
+
final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
|
| 286 |
+
final_outcomes = final_outcomes.loc[final_outcomes['Player'] == player_check]
|
| 287 |
+
player_outcomes = player_outcomes.loc[player_outcomes['Player'] == player_check]
|
| 288 |
+
player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
|
| 289 |
+
player_outcomes = player_outcomes.reset_index()
|
| 290 |
+
player_outcomes.columns = ['Instance', 'Outcome']
|
| 291 |
+
|
| 292 |
+
x1 = player_outcomes.Outcome.to_numpy()
|
| 293 |
+
|
| 294 |
+
print(x1)
|
| 295 |
+
|
| 296 |
+
hist_data = [x1]
|
| 297 |
+
|
| 298 |
+
group_labels = ['player outcomes']
|
| 299 |
+
|
| 300 |
+
fig = px.histogram(
|
| 301 |
+
player_outcomes, x='Outcome')
|
| 302 |
+
fig.add_vline(x=prop_var, line_dash="dash", line_color="green")
|
| 303 |
+
|
| 304 |
+
with df_hold_container:
|
| 305 |
+
df_hold_container = st.empty()
|
| 306 |
+
format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
|
| 307 |
+
st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)
|
| 308 |
+
|
| 309 |
+
with info_hold_container:
|
| 310 |
+
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.')
|
| 311 |
+
|
| 312 |
+
with plot_hold_container:
|
| 313 |
+
st.dataframe(player_outcomes, use_container_width = True)
|
| 314 |
+
plot_hold_container = st.empty()
|
| 315 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 316 |
+
|
| 317 |
+
with tab5:
|
| 318 |
+
st.info(t_stamp)
|
| 319 |
+
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.')
|
| 320 |
+
if st.button("Reset Data/Load Data", key='reset5'):
|
| 321 |
+
st.cache_data.clear()
|
| 322 |
+
game_model = game_betting_model()
|
| 323 |
+
overall_stats = player_stat_table()
|
| 324 |
+
qb_stats = overall_stats.loc[overall_stats['Position'] == 'QB']
|
| 325 |
+
non_qb_stats = overall_stats.loc[overall_stats['Position'] != 'QB']
|
| 326 |
+
prop_frame = player_prop_table()
|
| 327 |
+
t_stamp = f"Last Update: " + str(prop_frame['timestamp'][0]) + f" CST"
|
| 328 |
+
col1, col2 = st.columns([1, 5])
|
| 329 |
+
|
| 330 |
+
with col2:
|
| 331 |
+
df_hold_container = st.empty()
|
| 332 |
+
info_hold_container = st.empty()
|
| 333 |
+
plot_hold_container = st.empty()
|
| 334 |
+
export_container = st.empty()
|
| 335 |
+
|
| 336 |
+
with col1:
|
| 337 |
+
prop_type_var = st.selectbox('Select prop category', options = ['Pass Yards', 'Rush Yards', 'Receiving Yards'])
|
| 338 |
+
|
| 339 |
+
if st.button('Simulate Prop Category'):
|
| 340 |
+
with col2:
|
| 341 |
+
|
| 342 |
+
with df_hold_container.container():
|
| 343 |
+
|
| 344 |
+
if prop_type_var == "Pass Yards":
|
| 345 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 346 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'pass_yards']
|
| 347 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 348 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 349 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 350 |
+
st.table(prop_df)
|
| 351 |
+
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))
|
| 352 |
+
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))
|
| 353 |
+
df = pd.merge(overall_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 354 |
+
elif prop_type_var == "Rush Yards":
|
| 355 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 356 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'rush_yards']
|
| 357 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 358 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 359 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 360 |
+
st.table(prop_df)
|
| 361 |
+
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))
|
| 362 |
+
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))
|
| 363 |
+
df = pd.merge(overall_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 364 |
+
elif prop_type_var == "Receiving Yards":
|
| 365 |
+
prop_df = prop_frame[['Player', 'over_prop', 'over_line', 'under_line', 'prop_type']]
|
| 366 |
+
prop_df = prop_df.loc[prop_df['prop_type'] == 'rec_yards']
|
| 367 |
+
prop_df = prop_df[['Player', 'over_prop', 'over_line', 'under_line']]
|
| 368 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
| 369 |
+
prop_df = prop_df.loc[prop_df['Prop'] != 0]
|
| 370 |
+
st.table(prop_df)
|
| 371 |
+
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))
|
| 372 |
+
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))
|
| 373 |
+
df = pd.merge(overall_stats, prop_df, how='left', left_on=['Player'], right_on = ['Player'])
|
| 374 |
+
|
| 375 |
+
prop_dict = dict(zip(df.Player, df.Prop))
|
| 376 |
+
over_dict = dict(zip(df.Player, df.Over))
|
| 377 |
+
under_dict = dict(zip(df.Player, df.Under))
|
| 378 |
+
|
| 379 |
+
total_sims = 1000
|
| 380 |
+
|
| 381 |
+
df.replace("", 0, inplace=True)
|
| 382 |
+
|
| 383 |
+
if prop_type_var == "Pass Yards":
|
| 384 |
+
df['Median'] = df['pass_yards']
|
| 385 |
+
elif prop_type_var == "Rush Yards":
|
| 386 |
+
df['Median'] = df['rush_yards']
|
| 387 |
+
elif prop_type_var == "Receiving Yards":
|
| 388 |
+
df['Median'] = df['rec_yards']
|
| 389 |
+
|
| 390 |
+
flex_file = df
|
| 391 |
+
flex_file['Floor'] = flex_file['Median'] * .20
|
| 392 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * .80)
|
| 393 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 394 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
| 395 |
+
flex_file = flex_file[['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 396 |
+
|
| 397 |
+
hold_file = flex_file
|
| 398 |
+
overall_file = flex_file
|
| 399 |
+
prop_file = flex_file
|
| 400 |
+
|
| 401 |
+
overall_players = overall_file[['Player']]
|
| 402 |
+
|
| 403 |
+
for x in range(0,total_sims):
|
| 404 |
+
prop_file[x] = prop_file['Prop']
|
| 405 |
+
|
| 406 |
+
prop_file = prop_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 407 |
+
|
| 408 |
+
for x in range(0,total_sims):
|
| 409 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 410 |
+
|
| 411 |
+
overall_file=overall_file.drop(['Player', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 412 |
+
|
| 413 |
+
players_only = hold_file[['Player']]
|
| 414 |
+
|
| 415 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
| 416 |
+
|
| 417 |
+
prop_check = (overall_file - prop_file)
|
| 418 |
+
|
| 419 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
| 420 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
| 421 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
| 422 |
+
players_only['Over'] = prop_check[prop_check > 0].count(axis=1)/float(total_sims)
|
| 423 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
| 424 |
+
players_only['Over%'] = players_only[["Over", "Imp Over"]].mean(axis=1)
|
| 425 |
+
players_only['Under'] = prop_check[prop_check < 0].count(axis=1)/float(total_sims)
|
| 426 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
| 427 |
+
players_only['Under%'] = players_only[["Under", "Imp Under"]].mean(axis=1)
|
| 428 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
| 429 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
| 430 |
+
players_only['prop_threshold'] = .10
|
| 431 |
+
players_only = players_only.loc[players_only['Mean_Outcome'] > 0]
|
| 432 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
| 433 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
| 434 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
| 435 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
| 436 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
| 437 |
+
players_only['Edge'] = players_only['Bet_check']
|
| 438 |
+
|
| 439 |
+
players_only['Player'] = hold_file[['Player']]
|
| 440 |
+
|
| 441 |
+
final_outcomes = players_only[['Player', 'Prop', 'Mean_Outcome', 'Imp Over', 'Over%', 'Imp Under', 'Under%', 'Bet?', 'Edge']]
|
| 442 |
+
|
| 443 |
+
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
| 444 |
+
|
| 445 |
+
final_outcomes = final_outcomes.set_index('Player')
|
| 446 |
+
|
| 447 |
+
with df_hold_container:
|
| 448 |
+
df_hold_container = st.empty()
|
| 449 |
+
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 450 |
+
with export_container:
|
| 451 |
+
export_container = st.empty()
|
| 452 |
+
st.download_button(
|
| 453 |
+
label="Export Projections",
|
| 454 |
+
data=convert_df_to_csv(final_outcomes),
|
| 455 |
+
file_name='NFL_prop_proj.csv',
|
| 456 |
+
mime='text/csv',
|
| 457 |
+
key='prop_proj',
|
| 458 |
+
)
|
| 459 |
+
|