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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import gspread
|
| 5 |
+
|
| 6 |
+
st.set_page_config(layout="wide")
|
| 7 |
+
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def init_conn():
|
| 10 |
+
scope = ['https://www.googleapis.com/auth/spreadsheets',
|
| 11 |
+
"https://www.googleapis.com/auth/drive"]
|
| 12 |
+
|
| 13 |
+
credentials = {
|
| 14 |
+
"type": "service_account",
|
| 15 |
+
"project_id": "sheets-api-connect-378620",
|
| 16 |
+
"private_key_id": "1005124050c80d085e2c5b344345715978dd9cc9",
|
| 17 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkK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Zqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
| 18 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 19 |
+
"client_id": "106625872877651920064",
|
| 20 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 21 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 22 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 23 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
gc = gspread.service_account_from_dict(credentials)
|
| 27 |
+
return gc
|
| 28 |
+
|
| 29 |
+
gcservice_account = init_conn()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
wrong_acro = ['WSH', 'AZ']
|
| 34 |
+
right_acro = ['WAS', 'ARI']
|
| 35 |
+
|
| 36 |
+
game_format = {'Win Percentage': '{:.2%}','First Inning Lead Percentage': '{:.2%}',
|
| 37 |
+
'Fifth Inning Lead Percentage': '{:.2%}', '8+ runs': '{:.2%}', 'DK LevX': '{:.2%}', 'FD LevX': '{:.2%}'}
|
| 38 |
+
|
| 39 |
+
team_roo_format = {'Top Score%': '{:.2%}','0 Runs': '{:.2%}', '1 Run': '{:.2%}', '2 Runs': '{:.2%}', '3 Runs': '{:.2%}', '4 Runs': '{:.2%}',
|
| 40 |
+
'5 Runs': '{:.2%}','6 Runs': '{:.2%}', '7 Runs': '{:.2%}', '8 Runs': '{:.2%}', '9 Runs': '{:.2%}', '10 Runs': '{:.2%}'}
|
| 41 |
+
|
| 42 |
+
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
| 43 |
+
'4x%': '{:.2%}','GPP%': '{:.2%}'}
|
| 44 |
+
|
| 45 |
+
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
| 46 |
+
|
| 47 |
+
@st.cache_resource(ttl = 600)
|
| 48 |
+
def player_stat_table():
|
| 49 |
+
sh = gcservice_account.open_by_url(all_dk_player_projections)
|
| 50 |
+
worksheet = sh.worksheet('Player_Projections')
|
| 51 |
+
player_stats = pd.DataFrame(worksheet.get_all_records())
|
| 52 |
+
|
| 53 |
+
worksheet = sh.worksheet('DK_Stacks')
|
| 54 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 55 |
+
raw_display = load_display
|
| 56 |
+
dk_stacks_raw = raw_display.sort_values(by='Own', ascending=False)
|
| 57 |
+
|
| 58 |
+
worksheet = sh.worksheet('FD_Stacks')
|
| 59 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 60 |
+
raw_display = load_display
|
| 61 |
+
fd_stacks_raw = raw_display.sort_values(by='Own', ascending=False)
|
| 62 |
+
|
| 63 |
+
worksheet = sh.worksheet('DK_ROO')
|
| 64 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 65 |
+
load_display.replace('', np.nan, inplace=True)
|
| 66 |
+
dk_roo_raw = load_display.dropna(subset=['Median'])
|
| 67 |
+
|
| 68 |
+
worksheet = sh.worksheet('FD_ROO')
|
| 69 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 70 |
+
load_display.replace('', np.nan, inplace=True)
|
| 71 |
+
fd_roo_raw = load_display.dropna(subset=['Median'])
|
| 72 |
+
|
| 73 |
+
worksheet = sh.worksheet('Site_Info')
|
| 74 |
+
site_slates = pd.DataFrame(worksheet.get_all_records())
|
| 75 |
+
|
| 76 |
+
return player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, site_slates
|
| 77 |
+
|
| 78 |
+
@st.cache_data
|
| 79 |
+
def convert_df_to_csv(df):
|
| 80 |
+
return df.to_csv().encode('utf-8')
|
| 81 |
+
|
| 82 |
+
player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, site_slates = player_stat_table()
|
| 83 |
+
opp_dict = dict(zip(dk_roo_raw.Team, dk_roo_raw.Opp))
|
| 84 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 85 |
+
|
| 86 |
+
tab1, tab2 = st.tabs(['Uploads and Info', 'Pivot Finder'])
|
| 87 |
+
|
| 88 |
+
with tab1:
|
| 89 |
+
st.info("The Projections file can have any columns in any order, but must contain columns explicitly named: 'Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', and 'Own'.")
|
| 90 |
+
col1, col2 = st.columns([1, 5])
|
| 91 |
+
|
| 92 |
+
with col1:
|
| 93 |
+
proj_file = st.file_uploader("Upload Projections File", key = 'proj_uploader')
|
| 94 |
+
|
| 95 |
+
if proj_file is not None:
|
| 96 |
+
try:
|
| 97 |
+
proj_dataframe = pd.read_csv(proj_file)
|
| 98 |
+
except:
|
| 99 |
+
proj_dataframe = pd.read_excel(proj_file)
|
| 100 |
+
with col2:
|
| 101 |
+
if proj_file is not None:
|
| 102 |
+
st.dataframe(proj_dataframe.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 103 |
+
|
| 104 |
+
with tab2:
|
| 105 |
+
col1, col2 = st.columns([1, 5])
|
| 106 |
+
with col1:
|
| 107 |
+
st.info(t_stamp)
|
| 108 |
+
if st.button("Load/Reset Data", key='reset1'):
|
| 109 |
+
st.cache_data.clear()
|
| 110 |
+
player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, site_slates = player_stat_table()
|
| 111 |
+
opp_dict = dict(zip(dk_roo_raw.Team, dk_roo_raw.Opp))
|
| 112 |
+
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 113 |
+
data_var1 = st.radio("Which data are you loading?", ('Paydirt', 'User'), key='data_var1')
|
| 114 |
+
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 115 |
+
if site_var1 == 'Draftkings':
|
| 116 |
+
if data_var1 == 'User':
|
| 117 |
+
raw_baselines = proj_dataframe
|
| 118 |
+
elif data_var1 != 'User':
|
| 119 |
+
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == 'Main Slate']
|
| 120 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 121 |
+
elif site_var1 == 'Fanduel':
|
| 122 |
+
if data_var1 == 'User':
|
| 123 |
+
raw_baselines = proj_dataframe
|
| 124 |
+
elif data_var1 != 'User':
|
| 125 |
+
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == 'Main Slate']
|
| 126 |
+
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 127 |
+
player_check = st.selectbox('Select player to create comps', options = dk_roo_raw['Player'].unique(), key='dk_player')
|
| 128 |
+
Salary_var = st.number_input('Acceptable +/- Salary range', min_value = 0, max_value = 1000, value = 300, step = 100)
|
| 129 |
+
Median_var = st.number_input('Acceptable +/- Median range', min_value = 0, max_value = 10, value = 3, step = 1)
|
| 130 |
+
pos_var1 = st.radio("Compare to all positions or specific positions?", ('All Positions', 'Specific Positions'), key='pos_var1')
|
| 131 |
+
if pos_var1 == 'Specific Positions':
|
| 132 |
+
pos_var_list = st.multiselect('Which positions would you like to include?', options = raw_baselines['Position'].unique(), key='pos_var_list')
|
| 133 |
+
elif pos_var1 == 'All Positions':
|
| 134 |
+
pos_var_list = raw_baselines.Position.values.tolist()
|
| 135 |
+
split_var1 = st.radio("Are you running the full slate or certain games?", ('Full Slate Run', 'Specific Games'), key='split_var1')
|
| 136 |
+
if split_var1 == 'Specific Games':
|
| 137 |
+
team_var1 = st.multiselect('Which teams would you like to include?', options = raw_baselines['Team'].unique(), key='team_var1')
|
| 138 |
+
elif split_var1 == 'Full Slate Run':
|
| 139 |
+
team_var1 = raw_baselines.Team.values.tolist()
|
| 140 |
+
|
| 141 |
+
with col2:
|
| 142 |
+
hold_container = st.empty()
|
| 143 |
+
if st.button('Simulate appropriate pivots'):
|
| 144 |
+
with hold_container:
|
| 145 |
+
if site_var1 == 'Draftkings':
|
| 146 |
+
working_roo = raw_baselines
|
| 147 |
+
working_roo.replace('', 0, inplace=True)
|
| 148 |
+
if site_var1 == 'Fanduel':
|
| 149 |
+
working_roo = raw_baselines
|
| 150 |
+
working_roo.replace('', 0, inplace=True)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
own_dict = dict(zip(working_roo.Player, working_roo.Own))
|
| 154 |
+
team_dict = dict(zip(working_roo.Player, working_roo.Team))
|
| 155 |
+
opp_dict = dict(zip(working_roo.Player, working_roo.Opp))
|
| 156 |
+
total_sims = 1000
|
| 157 |
+
|
| 158 |
+
player_var = working_roo.loc[working_roo['Player'] == player_check]
|
| 159 |
+
player_var = player_var.reset_index()
|
| 160 |
+
|
| 161 |
+
working_roo = working_roo[working_roo['Position'].isin(pos_var_list)]
|
| 162 |
+
working_roo = working_roo[working_roo['Team'].isin(team_var1)]
|
| 163 |
+
working_roo = working_roo.loc[(working_roo['Salary'] >= player_var['Salary'][0] - Salary_var) & (working_roo['Salary'] <= player_var['Salary'][0] + Salary_var)]
|
| 164 |
+
working_roo = working_roo.loc[(working_roo['Median'] >= player_var['Median'][0] - Median_var) & (working_roo['Median'] <= player_var['Median'][0] + Median_var)]
|
| 165 |
+
|
| 166 |
+
flex_file = working_roo[['Player', 'Position', 'Salary', 'Median']]
|
| 167 |
+
flex_file['Floor_raw'] = flex_file['Median'] * .20
|
| 168 |
+
flex_file['Ceiling_raw'] = flex_file['Median'] * 1.9
|
| 169 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * .33), flex_file['Floor_raw'])
|
| 170 |
+
flex_file['Floor'] = np.where(flex_file['Position'] == 'RB', (flex_file['Median'] * .15), flex_file['Floor_raw'])
|
| 171 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'QB', (flex_file['Median'] * 1.75), flex_file['Ceiling_raw'])
|
| 172 |
+
flex_file['Ceiling'] = np.where(flex_file['Position'] == 'RB', (flex_file['Median'] * 1.85), flex_file['Ceiling_raw'])
|
| 173 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
| 174 |
+
flex_file = flex_file[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD']]
|
| 175 |
+
hold_file = flex_file
|
| 176 |
+
overall_file = flex_file
|
| 177 |
+
salary_file = flex_file
|
| 178 |
+
|
| 179 |
+
overall_players = overall_file[['Player']]
|
| 180 |
+
|
| 181 |
+
for x in range(0,total_sims):
|
| 182 |
+
salary_file[x] = salary_file['Salary']
|
| 183 |
+
|
| 184 |
+
salary_file=salary_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 185 |
+
salary_file.astype('int').dtypes
|
| 186 |
+
|
| 187 |
+
salary_file = salary_file.div(1000)
|
| 188 |
+
|
| 189 |
+
for x in range(0,total_sims):
|
| 190 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
| 191 |
+
|
| 192 |
+
overall_file=overall_file.drop(['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
| 193 |
+
overall_file.astype('int').dtypes
|
| 194 |
+
|
| 195 |
+
players_only = hold_file[['Player']]
|
| 196 |
+
raw_lineups_file = players_only
|
| 197 |
+
|
| 198 |
+
for x in range(0,total_sims):
|
| 199 |
+
maps_dict = {'proj_map':dict(zip(hold_file.Player,hold_file[x]))}
|
| 200 |
+
raw_lineups_file[x] = sum([raw_lineups_file['Player'].map(maps_dict['proj_map'])])
|
| 201 |
+
players_only[x] = raw_lineups_file[x].rank(ascending=False)
|
| 202 |
+
|
| 203 |
+
players_only=players_only.drop(['Player'], axis=1)
|
| 204 |
+
players_only.astype('int').dtypes
|
| 205 |
+
|
| 206 |
+
salary_2x_check = (overall_file - (salary_file*2))
|
| 207 |
+
salary_3x_check = (overall_file - (salary_file*3))
|
| 208 |
+
salary_4x_check = (overall_file - (salary_file*4))
|
| 209 |
+
|
| 210 |
+
players_only['Average_Rank'] = players_only.mean(axis=1)
|
| 211 |
+
players_only['Top_finish'] = players_only[players_only == 1].count(axis=1)/total_sims
|
| 212 |
+
players_only['Top_5_finish'] = players_only[players_only <= 5].count(axis=1)/total_sims
|
| 213 |
+
players_only['Top_10_finish'] = players_only[players_only <= 10].count(axis=1)/total_sims
|
| 214 |
+
players_only['20+%'] = overall_file[overall_file >= 20].count(axis=1)/float(total_sims)
|
| 215 |
+
players_only['2x%'] = salary_2x_check[salary_2x_check >= 1].count(axis=1)/float(total_sims)
|
| 216 |
+
players_only['3x%'] = salary_3x_check[salary_3x_check >= 1].count(axis=1)/float(total_sims)
|
| 217 |
+
players_only['4x%'] = salary_4x_check[salary_4x_check >= 1].count(axis=1)/float(total_sims)
|
| 218 |
+
|
| 219 |
+
players_only['Player'] = hold_file[['Player']]
|
| 220 |
+
|
| 221 |
+
final_outcomes = players_only[['Player', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 222 |
+
|
| 223 |
+
final_Proj = pd.merge(hold_file, final_outcomes, on="Player")
|
| 224 |
+
final_Proj = final_Proj[['Player', 'Position', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%']]
|
| 225 |
+
final_Proj['Own'] = final_Proj['Player'].map(own_dict)
|
| 226 |
+
final_Proj['Team'] = final_Proj['Player'].map(team_dict)
|
| 227 |
+
final_Proj['Opp'] = final_Proj['Player'].map(opp_dict)
|
| 228 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own']]
|
| 229 |
+
final_Proj['Projection Rank'] = final_Proj.Median.rank(pct = True)
|
| 230 |
+
final_Proj['Own Rank'] = final_Proj.Own.rank(pct = True)
|
| 231 |
+
final_Proj['LevX'] = 0
|
| 232 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'QB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 233 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'TE', final_Proj[['Projection Rank', '2x%']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 234 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'RB', final_Proj[['Projection Rank', 'Top_5_finish']].mean(axis=1) + final_Proj['20+%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 235 |
+
final_Proj['LevX'] = np.where(final_Proj['Position'] == 'WR', final_Proj[['Projection Rank', 'Top_10_finish']].mean(axis=1) + final_Proj['4x%'] - final_Proj['Own Rank'], final_Proj['LevX'])
|
| 236 |
+
final_Proj['CPT_Own'] = final_Proj['Own'] / 4
|
| 237 |
+
|
| 238 |
+
final_Proj = final_Proj[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'LevX']]
|
| 239 |
+
final_Proj = final_Proj.set_index('Player')
|
| 240 |
+
final_Proj = final_Proj.sort_values(by='Top_finish', ascending=False)
|
| 241 |
+
|
| 242 |
+
with hold_container:
|
| 243 |
+
hold_container = st.empty()
|
| 244 |
+
final_Proj = final_Proj
|
| 245 |
+
st.dataframe(final_Proj.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(player_roo_format, precision=2), use_container_width = True)
|
| 246 |
+
|
| 247 |
+
st.download_button(
|
| 248 |
+
label="Export Tables",
|
| 249 |
+
data=convert_df_to_csv(final_Proj),
|
| 250 |
+
file_name='NFL_pivot_export.csv',
|
| 251 |
+
mime='text/csv',
|
| 252 |
+
)
|