Spaces:
Build error
Build error
James McCool
commited on
Commit
·
cc5cc89
1
Parent(s):
ad70227
Refactor app.py to streamline database connections and enhance seed frame initialization. Removed hardcoded credentials and improved function signatures to include a 'split' parameter for limiting data retrieval. Updated user interface logic for selecting sports and contest types, ensuring better data handling and export functionality.
Browse files
app.py
CHANGED
|
@@ -8,47 +8,13 @@ import time
|
|
| 8 |
|
| 9 |
@st.cache_resource
|
| 10 |
def init_conn():
|
| 11 |
-
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
| 12 |
-
|
| 13 |
-
credentials = {
|
| 14 |
-
"type": "service_account",
|
| 15 |
-
"project_id": "model-sheets-connect",
|
| 16 |
-
"private_key_id": st.secrets['model_sheets_connect_pk'],
|
| 17 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQxDJXSzgkbwKYEDm\n48E8zGvupU8+Nk76xNPakrQKy2Y8+VJlq5psBtGchJTuUSHcXU5Mg2JhQsB376PJ\nsCw552K6Pw8fpeMDJDZuxpKSkaJR6k9G5Dhf5q8HDXnC5Rh/PRFuKJ2GGRpX7n+2\nhT/sCax0J8jfdTy/MDGiDfJqfQrOPrMKELtsGHR9Iv6F4vKiDqXpKfqH+02E9ptz\nBk+MNcbZ3m90M8ShfRu28ebebsASfarNMzc3dk7tb3utHOGXKCf4tF8yYKo7x8BZ\noO9X4gSfAgMBAAECggEAU8ByyMpSKlTCF32TJhXnVJi/kS+IhC/Qn5JUDMuk4LXr\naAEWsWO6kV/ZRVXArjmuSzuUVrXumISapM9Ps5Ytbl95CJmGDiLDwRL815nvv6k3\nUyAS8EGKjz74RpoIoH6E7EWCAzxlnUgTn+5oP9Flije97epYk3H+e2f1f5e1Nn1d\nYNe8U+1HqJgILcxA1TAUsARBfoD7+K3z/8DVPHI8IpzAh6kTHqhqC23Rram4XoQ6\nzj/ZdVBjvnKuazETfsD+Vl3jGLQA8cKQVV70xdz3xwLcNeHsbPbpGBpZUoF73c65\nkAXOrjYl0JD5yAk+hmYhXr6H9c6z5AieuZGDrhmlFQKBgQDzV6LRXmjn4854DP/J\nI82oX2GcI4eioDZPRukhiQLzYerMQBmyqZIRC+/LTCAhYQSjNgMa+ZKyvLqv48M0\n/x398op/+n3xTs+8L49SPI48/iV+mnH7k0WI/ycd4OOKh8rrmhl/0EWb9iitwJYe\nMjTV/QxNEpPBEXfR1/mvrN/lVQKBgQDuhomOxUhWVRVH6x03slmyRBn0Oiw4MW+r\nrt1hlNgtVmTc5Mu+4G0USMZwYuOB7F8xG4Foc7rIlwS7Ic83jMJxemtqAelwOLdV\nXRLrLWJfX8+O1z/UE15l2q3SUEnQ4esPHbQnZowHLm0mdL14qSVMl1mu1XfsoZ3z\nJZTQb48CIwKBgEWbzQRtKD8lKDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
| 18 |
-
"client_email": "gspread-connection@model-sheets-connect.iam.gserviceaccount.com",
|
| 19 |
-
"client_id": "100369174533302798535",
|
| 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%40model-sheets-connect.iam.gserviceaccount.com"
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
credentials2 = {
|
| 27 |
-
"type": "service_account",
|
| 28 |
-
"project_id": "sheets-api-connect-378620",
|
| 29 |
-
"private_key_id": st.secrets['sheets_api_connect_pk'],
|
| 30 |
-
"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",
|
| 31 |
-
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
| 32 |
-
"client_id": "106625872877651920064",
|
| 33 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 34 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 35 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 36 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
| 37 |
-
}
|
| 38 |
|
| 39 |
uri = st.secrets['mongo_uri']
|
| 40 |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 41 |
-
|
| 42 |
-
NFL_Data = st.secrets['NFL_Data']
|
| 43 |
-
|
| 44 |
-
NBA_Data = st.secrets['NBA_Data']
|
| 45 |
|
| 46 |
-
|
| 47 |
-
gc2 = gspread.service_account_from_dict(credentials2)
|
| 48 |
-
|
| 49 |
-
return gc, gc2, client, NFL_Data, NBA_Data
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 54 |
freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
|
|
@@ -56,14 +22,14 @@ dk_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'pro
|
|
| 56 |
fd_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']
|
| 57 |
|
| 58 |
@st.cache_data(ttl = 599)
|
| 59 |
-
def init_DK_seed_frames(sport):
|
| 60 |
if sport == 'NFL':
|
| 61 |
db = client["NFL_Database"]
|
| 62 |
elif sport == 'NBA':
|
| 63 |
db = client["NBA_DFS"]
|
| 64 |
|
| 65 |
collection = db[f"DK_{sport}_SD_seed_frame"]
|
| 66 |
-
cursor = collection.find()
|
| 67 |
|
| 68 |
raw_display = pd.DataFrame(list(cursor))
|
| 69 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -72,7 +38,7 @@ def init_DK_seed_frames(sport):
|
|
| 72 |
return DK_seed
|
| 73 |
|
| 74 |
@st.cache_data(ttl = 599)
|
| 75 |
-
def init_DK_secondary_seed_frames(sport):
|
| 76 |
|
| 77 |
if sport == 'NFL':
|
| 78 |
db = client["NFL_Database"]
|
|
@@ -80,7 +46,7 @@ def init_DK_secondary_seed_frames(sport):
|
|
| 80 |
db = client["NBA_DFS"]
|
| 81 |
|
| 82 |
collection = db[f"DK_{sport}_Secondary_SD_seed_frame"]
|
| 83 |
-
cursor = collection.find()
|
| 84 |
|
| 85 |
raw_display = pd.DataFrame(list(cursor))
|
| 86 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -89,7 +55,7 @@ def init_DK_secondary_seed_frames(sport):
|
|
| 89 |
return DK_second_seed
|
| 90 |
|
| 91 |
@st.cache_data(ttl = 599)
|
| 92 |
-
def init_DK_auxiliary_seed_frames(sport):
|
| 93 |
|
| 94 |
if sport == 'NFL':
|
| 95 |
db = client["NFL_Database"]
|
|
@@ -97,7 +63,7 @@ def init_DK_auxiliary_seed_frames(sport):
|
|
| 97 |
db = client["NBA_DFS"]
|
| 98 |
|
| 99 |
collection = db[f"DK_{sport}_Auxiliary_SD_seed_frame"]
|
| 100 |
-
cursor = collection.find()
|
| 101 |
|
| 102 |
raw_display = pd.DataFrame(list(cursor))
|
| 103 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -106,7 +72,7 @@ def init_DK_auxiliary_seed_frames(sport):
|
|
| 106 |
return DK_auxiliary_seed
|
| 107 |
|
| 108 |
@st.cache_data(ttl = 599)
|
| 109 |
-
def init_FD_seed_frames(sport):
|
| 110 |
|
| 111 |
if sport == 'NFL':
|
| 112 |
db = client["NFL_Database"]
|
|
@@ -114,7 +80,7 @@ def init_FD_seed_frames(sport):
|
|
| 114 |
db = client["NBA_DFS"]
|
| 115 |
|
| 116 |
collection = db[f"FD_{sport}_SD_seed_frame"]
|
| 117 |
-
cursor = collection.find()
|
| 118 |
|
| 119 |
raw_display = pd.DataFrame(list(cursor))
|
| 120 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -123,7 +89,7 @@ def init_FD_seed_frames(sport):
|
|
| 123 |
return FD_seed
|
| 124 |
|
| 125 |
@st.cache_data(ttl = 599)
|
| 126 |
-
def init_FD_secondary_seed_frames(sport):
|
| 127 |
|
| 128 |
if sport == 'NFL':
|
| 129 |
db = client["NFL_Database"]
|
|
@@ -131,7 +97,7 @@ def init_FD_secondary_seed_frames(sport):
|
|
| 131 |
db = client["NBA_DFS"]
|
| 132 |
|
| 133 |
collection = db[f"FD_{sport}_Secondary_SD_seed_frame"]
|
| 134 |
-
cursor = collection.find()
|
| 135 |
|
| 136 |
raw_display = pd.DataFrame(list(cursor))
|
| 137 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -140,7 +106,7 @@ def init_FD_secondary_seed_frames(sport):
|
|
| 140 |
return FD_second_seed
|
| 141 |
|
| 142 |
@st.cache_data(ttl = 599)
|
| 143 |
-
def init_FD_auxiliary_seed_frames(sport):
|
| 144 |
|
| 145 |
if sport == 'NFL':
|
| 146 |
db = client["NFL_Database"]
|
|
@@ -148,7 +114,7 @@ def init_FD_auxiliary_seed_frames(sport):
|
|
| 148 |
db = client["NBA_DFS"]
|
| 149 |
|
| 150 |
collection = db[f"FD_{sport}_Auxiliary_SD_seed_frame"]
|
| 151 |
-
cursor = collection.find()
|
| 152 |
|
| 153 |
raw_display = pd.DataFrame(list(cursor))
|
| 154 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
@@ -246,10 +212,9 @@ def calculate_FD_value_frequencies(np_array):
|
|
| 246 |
return combined_array
|
| 247 |
|
| 248 |
@st.cache_data
|
| 249 |
-
def sim_contest(Sim_size, seed_frame, maps_dict,
|
| 250 |
SimVar = 1
|
| 251 |
Sim_Winners = []
|
| 252 |
-
fp_array = seed_frame[:sharp_split, :]
|
| 253 |
|
| 254 |
# Pre-vectorize functions
|
| 255 |
vec_projection_map = np.vectorize(maps_dict['Projection_map'].__getitem__)
|
|
@@ -260,7 +225,7 @@ def sim_contest(Sim_size, seed_frame, maps_dict, sharp_split, Contest_Size):
|
|
| 260 |
st.write('Simulating contest on frames')
|
| 261 |
|
| 262 |
while SimVar <= Sim_size:
|
| 263 |
-
fp_random =
|
| 264 |
|
| 265 |
sample_arrays1 = np.c_[
|
| 266 |
fp_random,
|
|
@@ -285,6 +250,8 @@ def sim_contest(Sim_size, seed_frame, maps_dict, sharp_split, Contest_Size):
|
|
| 285 |
|
| 286 |
return Sim_Winners
|
| 287 |
|
|
|
|
|
|
|
| 288 |
tab1, tab2 = st.tabs(['Contest Sims', 'Data Export'])
|
| 289 |
with tab2:
|
| 290 |
col1, col2 = st.columns([1, 7])
|
|
@@ -296,31 +263,11 @@ with tab2:
|
|
| 296 |
dk_raw, fd_raw = init_baselines('NFL')
|
| 297 |
|
| 298 |
sport_var1 = st.radio("What sport are you working with?", ('NFL', 'NBA'), key='sport_var1')
|
| 299 |
-
dk_raw, fd_raw = init_baselines(sport_var1)
|
| 300 |
slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown', 'Auxiliary Showdown'), key='slate_var1')
|
|
|
|
| 301 |
|
| 302 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 303 |
if site_var1 == 'Draftkings':
|
| 304 |
-
if slate_var1 == 'Showdown':
|
| 305 |
-
DK_seed = init_DK_seed_frames(sport_var1)
|
| 306 |
-
if sport_var1 == 'NFL':
|
| 307 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 308 |
-
elif sport_var1 == 'NBA':
|
| 309 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 310 |
-
elif slate_var1 == 'Secondary Showdown':
|
| 311 |
-
DK_seed = init_DK_secondary_seed_frames(sport_var1)
|
| 312 |
-
if sport_var1 == 'NFL':
|
| 313 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 314 |
-
elif sport_var1 == 'NBA':
|
| 315 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 316 |
-
elif slate_var1 == 'Auxiliary Showdown':
|
| 317 |
-
DK_seed = init_DK_auxiliary_seed_frames(sport_var1)
|
| 318 |
-
if sport_var1 == 'NFL':
|
| 319 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 320 |
-
elif sport_var1 == 'NBA':
|
| 321 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 322 |
-
raw_baselines = dk_raw
|
| 323 |
-
column_names = dk_columns
|
| 324 |
|
| 325 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
| 326 |
if team_var1 == 'Specific Teams':
|
|
@@ -335,26 +282,6 @@ with tab2:
|
|
| 335 |
stack_var2 = [5, 4, 3, 2, 1, 0]
|
| 336 |
|
| 337 |
elif site_var1 == 'Fanduel':
|
| 338 |
-
if slate_var1 == 'Showdown':
|
| 339 |
-
FD_seed = init_FD_seed_frames(sport_var1)
|
| 340 |
-
if sport_var1 == 'NFL':
|
| 341 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 342 |
-
elif sport_var1 == 'NBA':
|
| 343 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 344 |
-
elif slate_var1 == 'Secondary Showdown':
|
| 345 |
-
FD_seed = init_FD_secondary_seed_frames(sport_var1)
|
| 346 |
-
if sport_var1 == 'NFL':
|
| 347 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 348 |
-
elif sport_var1 == 'NBA':
|
| 349 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 350 |
-
elif slate_var1 == 'Auxiliary Showdown':
|
| 351 |
-
FD_seed = init_FD_auxiliary_seed_frames(sport_var1)
|
| 352 |
-
if sport_var1 == 'NFL':
|
| 353 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 354 |
-
elif sport_var1 == 'NBA':
|
| 355 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 356 |
-
raw_baselines = fd_raw
|
| 357 |
-
column_names = fd_columns
|
| 358 |
|
| 359 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
| 360 |
if team_var1 == 'Specific Teams':
|
|
@@ -370,12 +297,58 @@ with tab2:
|
|
| 370 |
|
| 371 |
|
| 372 |
if st.button("Prepare data export", key='data_export'):
|
|
|
|
| 373 |
data_export = st.session_state.working_seed.copy()
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
mime='text/csv',
|
| 380 |
)
|
| 381 |
|
|
@@ -387,7 +360,24 @@ with tab2:
|
|
| 387 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], stack_var2)]
|
| 388 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 389 |
elif 'working_seed' not in st.session_state:
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], team_var2)]
|
| 392 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], stack_var2)]
|
| 393 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
|
@@ -398,7 +388,26 @@ with tab2:
|
|
| 398 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], stack_var2)]
|
| 399 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 400 |
elif 'working_seed' not in st.session_state:
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 8], team_var2)]
|
| 403 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], stack_var2)]
|
| 404 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
|
@@ -420,48 +429,11 @@ with tab1:
|
|
| 420 |
sim_slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown', 'Auxiliary Showdown'), key='sim_slate_var1')
|
| 421 |
sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')
|
| 422 |
if sim_site_var1 == 'Draftkings':
|
| 423 |
-
if sim_slate_var1 == 'Showdown':
|
| 424 |
-
DK_seed = init_DK_seed_frames(sim_sport_var1)
|
| 425 |
-
if sport_var1 == 'NFL':
|
| 426 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 427 |
-
elif sport_var1 == 'NBA':
|
| 428 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 429 |
-
elif sim_slate_var1 == 'Secondary Showdown':
|
| 430 |
-
DK_seed = init_DK_secondary_seed_frames(sim_sport_var1)
|
| 431 |
-
if sport_var1 == 'NFL':
|
| 432 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 433 |
-
elif sport_var1 == 'NBA':
|
| 434 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 435 |
-
elif sim_slate_var1 == 'Auxiliary Showdown':
|
| 436 |
-
DK_seed = init_DK_auxiliary_seed_frames(sim_sport_var1)
|
| 437 |
-
if sport_var1 == 'NFL':
|
| 438 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 439 |
-
elif sport_var1 == 'NBA':
|
| 440 |
-
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 441 |
raw_baselines = dk_raw
|
| 442 |
column_names = dk_columns
|
| 443 |
elif sim_site_var1 == 'Fanduel':
|
| 444 |
-
if sim_slate_var1 == 'Showdown':
|
| 445 |
-
FD_seed = init_FD_seed_frames(sim_sport_var1)
|
| 446 |
-
if sport_var1 == 'NFL':
|
| 447 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 448 |
-
elif sport_var1 == 'NBA':
|
| 449 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 450 |
-
elif sim_slate_var1 == 'Secondary Showdown':
|
| 451 |
-
FD_seed = init_FD_secondary_seed_frames(sim_sport_var1)
|
| 452 |
-
if sport_var1 == 'NFL':
|
| 453 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 454 |
-
elif sport_var1 == 'NBA':
|
| 455 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 456 |
-
elif sim_slate_var1 == 'Auxiliary Showdown':
|
| 457 |
-
FD_seed = init_FD_auxiliary_seed_frames(sim_sport_var1)
|
| 458 |
-
if sport_var1 == 'NFL':
|
| 459 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 460 |
-
elif sport_var1 == 'NBA':
|
| 461 |
-
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 462 |
raw_baselines = fd_raw
|
| 463 |
column_names = fd_columns
|
| 464 |
-
|
| 465 |
contest_var1 = st.selectbox("What contest size are you simulating?", ('Small', 'Medium', 'Large', 'Custom'))
|
| 466 |
if contest_var1 == 'Small':
|
| 467 |
Contest_Size = 1000
|
|
@@ -503,7 +475,7 @@ with tab1:
|
|
| 503 |
'STDev_map':dict(zip(raw_baselines.Player,raw_baselines.STDev)),
|
| 504 |
'cpt_STDev_map':dict(zip(raw_baselines.Player,raw_baselines['CPT_STDev']))
|
| 505 |
}
|
| 506 |
-
Sim_Winners = sim_contest(1000, st.session_state.working_seed, maps_dict,
|
| 507 |
Sim_Winner_Frame = pd.DataFrame(np.concatenate(Sim_Winners))
|
| 508 |
|
| 509 |
#st.table(Sim_Winner_Frame)
|
|
@@ -530,9 +502,47 @@ with tab1:
|
|
| 530 |
|
| 531 |
else:
|
| 532 |
if sim_site_var1 == 'Draftkings':
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
elif sim_site_var1 == 'Fanduel':
|
| 535 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
maps_dict = {
|
| 537 |
'Projection_map':dict(zip(raw_baselines.Player,raw_baselines.Median)),
|
| 538 |
'cpt_projection_map':dict(zip(raw_baselines.Player,raw_baselines.cpt_Median)),
|
|
@@ -544,7 +554,7 @@ with tab1:
|
|
| 544 |
'STDev_map':dict(zip(raw_baselines.Player,raw_baselines.STDev)),
|
| 545 |
'cpt_STDev_map':dict(zip(raw_baselines.Player,raw_baselines['CPT_STDev']))
|
| 546 |
}
|
| 547 |
-
Sim_Winners = sim_contest(1000, st.session_state.working_seed, maps_dict,
|
| 548 |
Sim_Winner_Frame = pd.DataFrame(np.concatenate(Sim_Winners))
|
| 549 |
|
| 550 |
#st.table(Sim_Winner_Frame)
|
|
|
|
| 8 |
|
| 9 |
@st.cache_resource
|
| 10 |
def init_conn():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
uri = st.secrets['mongo_uri']
|
| 13 |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
return client
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
client = init_conn()
|
| 18 |
|
| 19 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 20 |
freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
|
|
|
|
| 22 |
fd_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']
|
| 23 |
|
| 24 |
@st.cache_data(ttl = 599)
|
| 25 |
+
def init_DK_seed_frames(sport, split):
|
| 26 |
if sport == 'NFL':
|
| 27 |
db = client["NFL_Database"]
|
| 28 |
elif sport == 'NBA':
|
| 29 |
db = client["NBA_DFS"]
|
| 30 |
|
| 31 |
collection = db[f"DK_{sport}_SD_seed_frame"]
|
| 32 |
+
cursor = collection.find().limit(split)
|
| 33 |
|
| 34 |
raw_display = pd.DataFrame(list(cursor))
|
| 35 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 38 |
return DK_seed
|
| 39 |
|
| 40 |
@st.cache_data(ttl = 599)
|
| 41 |
+
def init_DK_secondary_seed_frames(sport, split):
|
| 42 |
|
| 43 |
if sport == 'NFL':
|
| 44 |
db = client["NFL_Database"]
|
|
|
|
| 46 |
db = client["NBA_DFS"]
|
| 47 |
|
| 48 |
collection = db[f"DK_{sport}_Secondary_SD_seed_frame"]
|
| 49 |
+
cursor = collection.find().limit(split)
|
| 50 |
|
| 51 |
raw_display = pd.DataFrame(list(cursor))
|
| 52 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 55 |
return DK_second_seed
|
| 56 |
|
| 57 |
@st.cache_data(ttl = 599)
|
| 58 |
+
def init_DK_auxiliary_seed_frames(sport, split):
|
| 59 |
|
| 60 |
if sport == 'NFL':
|
| 61 |
db = client["NFL_Database"]
|
|
|
|
| 63 |
db = client["NBA_DFS"]
|
| 64 |
|
| 65 |
collection = db[f"DK_{sport}_Auxiliary_SD_seed_frame"]
|
| 66 |
+
cursor = collection.find().limit(split)
|
| 67 |
|
| 68 |
raw_display = pd.DataFrame(list(cursor))
|
| 69 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 72 |
return DK_auxiliary_seed
|
| 73 |
|
| 74 |
@st.cache_data(ttl = 599)
|
| 75 |
+
def init_FD_seed_frames(sport, split):
|
| 76 |
|
| 77 |
if sport == 'NFL':
|
| 78 |
db = client["NFL_Database"]
|
|
|
|
| 80 |
db = client["NBA_DFS"]
|
| 81 |
|
| 82 |
collection = db[f"FD_{sport}_SD_seed_frame"]
|
| 83 |
+
cursor = collection.find().limit(split)
|
| 84 |
|
| 85 |
raw_display = pd.DataFrame(list(cursor))
|
| 86 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 89 |
return FD_seed
|
| 90 |
|
| 91 |
@st.cache_data(ttl = 599)
|
| 92 |
+
def init_FD_secondary_seed_frames(sport, split):
|
| 93 |
|
| 94 |
if sport == 'NFL':
|
| 95 |
db = client["NFL_Database"]
|
|
|
|
| 97 |
db = client["NBA_DFS"]
|
| 98 |
|
| 99 |
collection = db[f"FD_{sport}_Secondary_SD_seed_frame"]
|
| 100 |
+
cursor = collection.find().limit(split)
|
| 101 |
|
| 102 |
raw_display = pd.DataFrame(list(cursor))
|
| 103 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 106 |
return FD_second_seed
|
| 107 |
|
| 108 |
@st.cache_data(ttl = 599)
|
| 109 |
+
def init_FD_auxiliary_seed_frames(sport, split):
|
| 110 |
|
| 111 |
if sport == 'NFL':
|
| 112 |
db = client["NFL_Database"]
|
|
|
|
| 114 |
db = client["NBA_DFS"]
|
| 115 |
|
| 116 |
collection = db[f"FD_{sport}_Auxiliary_SD_seed_frame"]
|
| 117 |
+
cursor = collection.find().limit(split)
|
| 118 |
|
| 119 |
raw_display = pd.DataFrame(list(cursor))
|
| 120 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
|
|
|
| 212 |
return combined_array
|
| 213 |
|
| 214 |
@st.cache_data
|
| 215 |
+
def sim_contest(Sim_size, seed_frame, maps_dict, Contest_Size):
|
| 216 |
SimVar = 1
|
| 217 |
Sim_Winners = []
|
|
|
|
| 218 |
|
| 219 |
# Pre-vectorize functions
|
| 220 |
vec_projection_map = np.vectorize(maps_dict['Projection_map'].__getitem__)
|
|
|
|
| 225 |
st.write('Simulating contest on frames')
|
| 226 |
|
| 227 |
while SimVar <= Sim_size:
|
| 228 |
+
fp_random = seed_frame[np.random.choice(seed_frame.shape[0], Contest_Size)]
|
| 229 |
|
| 230 |
sample_arrays1 = np.c_[
|
| 231 |
fp_random,
|
|
|
|
| 250 |
|
| 251 |
return Sim_Winners
|
| 252 |
|
| 253 |
+
dk_raw, fd_raw = init_baselines('NFL')
|
| 254 |
+
|
| 255 |
tab1, tab2 = st.tabs(['Contest Sims', 'Data Export'])
|
| 256 |
with tab2:
|
| 257 |
col1, col2 = st.columns([1, 7])
|
|
|
|
| 263 |
dk_raw, fd_raw = init_baselines('NFL')
|
| 264 |
|
| 265 |
sport_var1 = st.radio("What sport are you working with?", ('NFL', 'NBA'), key='sport_var1')
|
|
|
|
| 266 |
slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown', 'Auxiliary Showdown'), key='slate_var1')
|
| 267 |
+
sharp_split_var = st.number_input("How many lineups do you want?", value=10000, max_value=500000, min_value=10000, step=10000)
|
| 268 |
|
| 269 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='site_var1')
|
| 270 |
if site_var1 == 'Draftkings':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
| 273 |
if team_var1 == 'Specific Teams':
|
|
|
|
| 282 |
stack_var2 = [5, 4, 3, 2, 1, 0]
|
| 283 |
|
| 284 |
elif site_var1 == 'Fanduel':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
team_var1 = st.radio("Do you want a frame with specific teams?", ('Full Slate', 'Specific Teams'), key='team_var1')
|
| 287 |
if team_var1 == 'Specific Teams':
|
|
|
|
| 297 |
|
| 298 |
|
| 299 |
if st.button("Prepare data export", key='data_export'):
|
| 300 |
+
if 'working_seed' in st.session_state:
|
| 301 |
data_export = st.session_state.working_seed.copy()
|
| 302 |
+
elif 'working_seed' not in st.session_state:
|
| 303 |
+
if site_var1 == 'Draftkings':
|
| 304 |
+
if slate_var1 == 'Showdown':
|
| 305 |
+
st.session_state.working_seed = init_DK_seed_frames(sport_var1, sharp_split_var)
|
| 306 |
+
if sport_var1 == 'NFL':
|
| 307 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 308 |
+
elif sport_var1 == 'NBA':
|
| 309 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 310 |
+
elif slate_var1 == 'Secondary Showdown':
|
| 311 |
+
st.session_state.working_seed = init_DK_secondary_seed_frames(sport_var1, sharp_split_var)
|
| 312 |
+
if sport_var1 == 'NFL':
|
| 313 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 314 |
+
elif sport_var1 == 'NBA':
|
| 315 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 316 |
+
elif slate_var1 == 'Auxiliary Showdown':
|
| 317 |
+
st.session_state.working_seed = init_DK_auxiliary_seed_frames(sport_var1, sharp_split_var)
|
| 318 |
+
if sport_var1 == 'NFL':
|
| 319 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 320 |
+
elif sport_var1 == 'NBA':
|
| 321 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 322 |
+
raw_baselines = dk_raw
|
| 323 |
+
column_names = dk_columns
|
| 324 |
+
elif site_var1 == 'Fanduel':
|
| 325 |
+
if slate_var1 == 'Showdown':
|
| 326 |
+
st.session_state.working_seed = init_FD_seed_frames(sport_var1, sharp_split_var)
|
| 327 |
+
if sport_var1 == 'NFL':
|
| 328 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 329 |
+
elif sport_var1 == 'NBA':
|
| 330 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 331 |
+
elif slate_var1 == 'Secondary Showdown':
|
| 332 |
+
st.session_state.working_seed = init_FD_secondary_seed_frames(sport_var1, sharp_split_var)
|
| 333 |
+
if sport_var1 == 'NFL':
|
| 334 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 335 |
+
elif sport_var1 == 'NBA':
|
| 336 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 337 |
+
elif slate_var1 == 'Auxiliary Showdown':
|
| 338 |
+
st.session_state.working_seed = init_FD_auxiliary_seed_frames(sport_var1, sharp_split_var)
|
| 339 |
+
if sport_var1 == 'NFL':
|
| 340 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 341 |
+
elif sport_var1 == 'NBA':
|
| 342 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 343 |
+
raw_baselines = fd_raw
|
| 344 |
+
column_names = fd_columns
|
| 345 |
+
data_export = st.session_state.working_seed.copy()
|
| 346 |
+
for col in range(6):
|
| 347 |
+
data_export[:, col] = np.array([export_id_dict.get(x, x) for x in data_export[:, col]])
|
| 348 |
+
st.download_button(
|
| 349 |
+
label="Export optimals set",
|
| 350 |
+
data=convert_df(data_export),
|
| 351 |
+
file_name='NFL_SD_optimals_export.csv',
|
| 352 |
mime='text/csv',
|
| 353 |
)
|
| 354 |
|
|
|
|
| 360 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], stack_var2)]
|
| 361 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 362 |
elif 'working_seed' not in st.session_state:
|
| 363 |
+
if slate_var1 == 'Showdown':
|
| 364 |
+
st.session_state.working_seed = init_DK_seed_frames(sport_var1, sharp_split_var)
|
| 365 |
+
if sport_var1 == 'NFL':
|
| 366 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 367 |
+
elif sport_var1 == 'NBA':
|
| 368 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 369 |
+
elif slate_var1 == 'Secondary Showdown':
|
| 370 |
+
st.session_state.working_seed = init_DK_secondary_seed_frames(sport_var1, sharp_split_var)
|
| 371 |
+
if sport_var1 == 'NFL':
|
| 372 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 373 |
+
elif sport_var1 == 'NBA':
|
| 374 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 375 |
+
elif slate_var1 == 'Auxiliary Showdown':
|
| 376 |
+
st.session_state.working_seed = init_DK_auxiliary_seed_frames(sport_var1, sharp_split_var)
|
| 377 |
+
if sport_var1 == 'NFL':
|
| 378 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 379 |
+
elif sport_var1 == 'NBA':
|
| 380 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 381 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], team_var2)]
|
| 382 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 10], stack_var2)]
|
| 383 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
|
|
|
| 388 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], stack_var2)]
|
| 389 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
| 390 |
elif 'working_seed' not in st.session_state:
|
| 391 |
+
if slate_var1 == 'Showdown':
|
| 392 |
+
st.session_state.working_seed = init_FD_seed_frames(sport_var1, sharp_split_var)
|
| 393 |
+
if sport_var1 == 'NFL':
|
| 394 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 395 |
+
elif sport_var1 == 'NBA':
|
| 396 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 397 |
+
elif slate_var1 == 'Secondary Showdown':
|
| 398 |
+
st.session_state.working_seed = init_FD_secondary_seed_frames(sport_var1, sharp_split_var)
|
| 399 |
+
if sport_var1 == 'NFL':
|
| 400 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 401 |
+
elif sport_var1 == 'NBA':
|
| 402 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 403 |
+
elif slate_var1 == 'Auxiliary Showdown':
|
| 404 |
+
st.session_state.working_seed = init_FD_auxiliary_seed_frames(sport_var1, sharp_split_var)
|
| 405 |
+
if sport_var1 == 'NFL':
|
| 406 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 407 |
+
elif sport_var1 == 'NBA':
|
| 408 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 409 |
+
raw_baselines = fd_raw
|
| 410 |
+
column_names = fd_columns
|
| 411 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 8], team_var2)]
|
| 412 |
st.session_state.working_seed = st.session_state.working_seed[np.isin(st.session_state.working_seed[:, 9], stack_var2)]
|
| 413 |
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:1000], columns=column_names)
|
|
|
|
| 429 |
sim_slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown', 'Auxiliary Showdown'), key='sim_slate_var1')
|
| 430 |
sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')
|
| 431 |
if sim_site_var1 == 'Draftkings':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
raw_baselines = dk_raw
|
| 433 |
column_names = dk_columns
|
| 434 |
elif sim_site_var1 == 'Fanduel':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
raw_baselines = fd_raw
|
| 436 |
column_names = fd_columns
|
|
|
|
| 437 |
contest_var1 = st.selectbox("What contest size are you simulating?", ('Small', 'Medium', 'Large', 'Custom'))
|
| 438 |
if contest_var1 == 'Small':
|
| 439 |
Contest_Size = 1000
|
|
|
|
| 475 |
'STDev_map':dict(zip(raw_baselines.Player,raw_baselines.STDev)),
|
| 476 |
'cpt_STDev_map':dict(zip(raw_baselines.Player,raw_baselines['CPT_STDev']))
|
| 477 |
}
|
| 478 |
+
Sim_Winners = sim_contest(1000, st.session_state.working_seed, maps_dict, Contest_Size)
|
| 479 |
Sim_Winner_Frame = pd.DataFrame(np.concatenate(Sim_Winners))
|
| 480 |
|
| 481 |
#st.table(Sim_Winner_Frame)
|
|
|
|
| 502 |
|
| 503 |
else:
|
| 504 |
if sim_site_var1 == 'Draftkings':
|
| 505 |
+
if sim_slate_var1 == 'Showdown':
|
| 506 |
+
st.session_state.working_seed = init_DK_seed_frames(sim_sport_var1, sharp_split_var)
|
| 507 |
+
if sport_var1 == 'NFL':
|
| 508 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 509 |
+
elif sport_var1 == 'NBA':
|
| 510 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 511 |
+
elif sim_slate_var1 == 'Secondary Showdown':
|
| 512 |
+
st.session_state.working_seed = init_DK_secondary_seed_frames(sim_sport_var1, sharp_split_var)
|
| 513 |
+
if sport_var1 == 'NFL':
|
| 514 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 515 |
+
elif sport_var1 == 'NBA':
|
| 516 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 517 |
+
elif sim_slate_var1 == 'Auxiliary Showdown':
|
| 518 |
+
st.session_state.working_seed = init_DK_auxiliary_seed_frames(sim_sport_var1, sharp_split_var)
|
| 519 |
+
if sport_var1 == 'NFL':
|
| 520 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 521 |
+
elif sport_var1 == 'NBA':
|
| 522 |
+
export_id_dict = dict(zip(dk_raw['Player'], dk_raw['player_id']))
|
| 523 |
+
raw_baselines = dk_raw
|
| 524 |
+
column_names = dk_columns
|
| 525 |
elif sim_site_var1 == 'Fanduel':
|
| 526 |
+
if sim_slate_var1 == 'Showdown':
|
| 527 |
+
st.session_state.working_seed = init_FD_seed_frames(sim_sport_var1, sharp_split_var)
|
| 528 |
+
if sport_var1 == 'NFL':
|
| 529 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 530 |
+
elif sport_var1 == 'NBA':
|
| 531 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 532 |
+
elif sim_slate_var1 == 'Secondary Showdown':
|
| 533 |
+
st.session_state.working_seed = init_FD_secondary_seed_frames(sim_sport_var1, sharp_split_var)
|
| 534 |
+
if sport_var1 == 'NFL':
|
| 535 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 536 |
+
elif sport_var1 == 'NBA':
|
| 537 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 538 |
+
elif sim_slate_var1 == 'Auxiliary Showdown':
|
| 539 |
+
st.session_state.working_seed = init_FD_auxiliary_seed_frames(sim_sport_var1, sharp_split_var)
|
| 540 |
+
if sport_var1 == 'NFL':
|
| 541 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 542 |
+
elif sport_var1 == 'NBA':
|
| 543 |
+
export_id_dict = dict(zip(fd_raw['Player'], fd_raw['player_id']))
|
| 544 |
+
raw_baselines = fd_raw
|
| 545 |
+
column_names = fd_columns
|
| 546 |
maps_dict = {
|
| 547 |
'Projection_map':dict(zip(raw_baselines.Player,raw_baselines.Median)),
|
| 548 |
'cpt_projection_map':dict(zip(raw_baselines.Player,raw_baselines.cpt_Median)),
|
|
|
|
| 554 |
'STDev_map':dict(zip(raw_baselines.Player,raw_baselines.STDev)),
|
| 555 |
'cpt_STDev_map':dict(zip(raw_baselines.Player,raw_baselines['CPT_STDev']))
|
| 556 |
}
|
| 557 |
+
Sim_Winners = sim_contest(1000, st.session_state.working_seed, maps_dict, Contest_Size)
|
| 558 |
Sim_Winner_Frame = pd.DataFrame(np.concatenate(Sim_Winners))
|
| 559 |
|
| 560 |
#st.table(Sim_Winner_Frame)
|