Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
eb25c8a
1
Parent(s):
184b936
Aimed to add NBA as an option for the seed frame source
Browse files
app.py
CHANGED
|
@@ -38,16 +38,17 @@ def init_conn():
|
|
| 38 |
|
| 39 |
uri = st.secrets['mongo_uri']
|
| 40 |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000)
|
| 41 |
-
db = client["testing_db"]
|
| 42 |
|
| 43 |
NFL_Data = st.secrets['NFL_Data']
|
| 44 |
|
|
|
|
|
|
|
| 45 |
gc = gspread.service_account_from_dict(credentials)
|
| 46 |
gc2 = gspread.service_account_from_dict(credentials2)
|
| 47 |
|
| 48 |
-
return gc, gc2,
|
| 49 |
|
| 50 |
-
gcservice_account, gcservice_account2,
|
| 51 |
|
| 52 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 53 |
freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
|
|
@@ -55,9 +56,13 @@ dk_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'pro
|
|
| 55 |
fd_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']
|
| 56 |
|
| 57 |
@st.cache_data(ttl = 599)
|
| 58 |
-
def init_DK_seed_frames():
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
cursor = collection.find()
|
| 62 |
|
| 63 |
raw_display = pd.DataFrame(list(cursor))
|
|
@@ -67,9 +72,14 @@ def init_DK_seed_frames():
|
|
| 67 |
return DK_seed
|
| 68 |
|
| 69 |
@st.cache_data(ttl = 599)
|
| 70 |
-
def init_DK_secondary_seed_frames():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
collection = db["
|
| 73 |
cursor = collection.find()
|
| 74 |
|
| 75 |
raw_display = pd.DataFrame(list(cursor))
|
|
@@ -79,9 +89,14 @@ def init_DK_secondary_seed_frames():
|
|
| 79 |
return DK_second_seed
|
| 80 |
|
| 81 |
@st.cache_data(ttl = 599)
|
| 82 |
-
def init_FD_seed_frames():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
collection = db["
|
| 85 |
cursor = collection.find()
|
| 86 |
|
| 87 |
raw_display = pd.DataFrame(list(cursor))
|
|
@@ -91,9 +106,14 @@ def init_FD_seed_frames():
|
|
| 91 |
return FD_seed
|
| 92 |
|
| 93 |
@st.cache_data(ttl = 599)
|
| 94 |
-
def init_FD_secondary_seed_frames():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
collection = db["
|
| 97 |
cursor = collection.find()
|
| 98 |
|
| 99 |
raw_display = pd.DataFrame(list(cursor))
|
|
@@ -103,27 +123,53 @@ def init_FD_secondary_seed_frames():
|
|
| 103 |
return FD_second_seed
|
| 104 |
|
| 105 |
@st.cache_data(ttl = 599)
|
| 106 |
-
def init_baselines():
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
return dk_raw, fd_raw
|
| 129 |
|
|
@@ -189,15 +235,16 @@ with tab2:
|
|
| 189 |
for key in st.session_state.keys():
|
| 190 |
del st.session_state[key]
|
| 191 |
dk_raw, fd_raw = init_baselines()
|
| 192 |
-
|
|
|
|
| 193 |
slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown'))
|
| 194 |
|
| 195 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
| 196 |
if site_var1 == 'Draftkings':
|
| 197 |
if slate_var1 == 'Showdown':
|
| 198 |
-
DK_seed = init_DK_seed_frames()
|
| 199 |
elif slate_var1 == 'Secondary Showdown':
|
| 200 |
-
DK_seed = init_DK_secondary_seed_frames()
|
| 201 |
raw_baselines = dk_raw
|
| 202 |
column_names = dk_columns
|
| 203 |
|
|
@@ -215,9 +262,9 @@ with tab2:
|
|
| 215 |
|
| 216 |
elif site_var1 == 'Fanduel':
|
| 217 |
if slate_var1 == 'Showdown':
|
| 218 |
-
FD_seed = init_FD_seed_frames()
|
| 219 |
elif slate_var1 == 'Secondary Showdown':
|
| 220 |
-
FD_seed = init_FD_secondary_seed_frames()
|
| 221 |
raw_baselines = fd_raw
|
| 222 |
column_names = fd_columns
|
| 223 |
|
|
@@ -279,20 +326,21 @@ with tab1:
|
|
| 279 |
for key in st.session_state.keys():
|
| 280 |
del st.session_state[key]
|
| 281 |
dk_raw, fd_raw = init_baselines()
|
|
|
|
| 282 |
sim_slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown'), key='sim_slate_var1')
|
| 283 |
sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')
|
| 284 |
if sim_site_var1 == 'Draftkings':
|
| 285 |
if sim_slate_var1 == 'Showdown':
|
| 286 |
-
DK_seed = init_DK_seed_frames()
|
| 287 |
elif sim_slate_var1 == 'Secondary Showdown':
|
| 288 |
-
DK_seed = init_DK_secondary_seed_frames()
|
| 289 |
raw_baselines = dk_raw
|
| 290 |
column_names = dk_columns
|
| 291 |
elif sim_site_var1 == 'Fanduel':
|
| 292 |
if sim_slate_var1 == 'Showdown':
|
| 293 |
-
FD_seed = init_FD_seed_frames()
|
| 294 |
elif sim_slate_var1 == 'Secondary Showdown':
|
| 295 |
-
FD_seed = init_FD_secondary_seed_frames()
|
| 296 |
raw_baselines = fd_raw
|
| 297 |
column_names = fd_columns
|
| 298 |
|
|
|
|
| 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 |
gc = gspread.service_account_from_dict(credentials)
|
| 47 |
gc2 = gspread.service_account_from_dict(credentials2)
|
| 48 |
|
| 49 |
+
return gc, gc2, client, NFL_Data, NBA_Data
|
| 50 |
|
| 51 |
+
gcservice_account, gcservice_account2, client, NFL_Data, NBA_Data = init_conn()
|
| 52 |
|
| 53 |
percentages_format = {'Exposure': '{:.2%}'}
|
| 54 |
freq_format = {'Exposure': '{:.2%}', 'Proj Own': '{:.2%}', 'Edge': '{:.2%}'}
|
|
|
|
| 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["testing_db"]
|
| 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))
|
|
|
|
| 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["testing_db"]
|
| 79 |
+
elif sport == 'NBA':
|
| 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))
|
|
|
|
| 89 |
return DK_second_seed
|
| 90 |
|
| 91 |
@st.cache_data(ttl = 599)
|
| 92 |
+
def init_FD_seed_frames(sport):
|
| 93 |
+
|
| 94 |
+
if sport == 'NFL':
|
| 95 |
+
db = client["testing_db"]
|
| 96 |
+
elif sport == 'NBA':
|
| 97 |
+
db = client["NBA_DFS"]
|
| 98 |
|
| 99 |
+
collection = db[f"FD_{sport}_SD_seed_frame"]
|
| 100 |
cursor = collection.find()
|
| 101 |
|
| 102 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
| 106 |
return FD_seed
|
| 107 |
|
| 108 |
@st.cache_data(ttl = 599)
|
| 109 |
+
def init_FD_secondary_seed_frames(sport):
|
| 110 |
+
|
| 111 |
+
if sport == 'NFL':
|
| 112 |
+
db = client["testing_db"]
|
| 113 |
+
elif sport == 'NBA':
|
| 114 |
+
db = client["NBA_DFS"]
|
| 115 |
|
| 116 |
+
collection = db[f"FD_{sport}_Secondary_SD_seed_frame"]
|
| 117 |
cursor = collection.find()
|
| 118 |
|
| 119 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
| 123 |
return FD_second_seed
|
| 124 |
|
| 125 |
@st.cache_data(ttl = 599)
|
| 126 |
+
def init_baselines(sport):
|
| 127 |
+
if sport == 'NFL':
|
| 128 |
+
try:
|
| 129 |
+
sh = gcservice_account.open_by_url(NFL_Data)
|
| 130 |
+
except:
|
| 131 |
+
sh = gcservice_account2.open_by_url(NFL_Data)
|
| 132 |
+
|
| 133 |
+
worksheet = sh.worksheet('DK_SD_ROO')
|
| 134 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 135 |
+
load_display.replace('', np.nan, inplace=True)
|
| 136 |
+
load_display['STDev'] = load_display['Median'] / 4
|
| 137 |
+
load_display = load_display.drop_duplicates(subset=['Player'], keep='first')
|
| 138 |
+
|
| 139 |
+
dk_raw = load_display.dropna(subset=['Median'])
|
| 140 |
+
|
| 141 |
+
worksheet = sh.worksheet('FD_SD_ROO')
|
| 142 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 143 |
+
load_display.replace('', np.nan, inplace=True)
|
| 144 |
+
load_display['STDev'] = load_display['Median'] / 4
|
| 145 |
+
load_display = load_display.drop_duplicates(subset=['Player'], keep='first')
|
| 146 |
+
|
| 147 |
+
fd_raw = load_display.dropna(subset=['Median'])
|
| 148 |
|
| 149 |
+
elif sport == 'NBA':
|
| 150 |
+
|
| 151 |
+
try:
|
| 152 |
+
sh = gcservice_account.open_by_url(NBA_Data)
|
| 153 |
+
except:
|
| 154 |
+
sh = gcservice_account2.open_by_url(NBA_Data)
|
| 155 |
+
|
| 156 |
+
worksheet = sh.worksheet('Player_Level_SD_ROO')
|
| 157 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 158 |
+
load_display.replace('', np.nan, inplace=True)
|
| 159 |
+
load_display['STDev'] = load_display['Median'] / 4
|
| 160 |
+
load_display = load_display[load_display['site'] == 'Draftkings']
|
| 161 |
+
load_display = load_display.drop_duplicates(subset=['Player'], keep='first')
|
| 162 |
+
|
| 163 |
+
dk_raw = load_display.dropna(subset=['Median'])
|
| 164 |
+
|
| 165 |
+
worksheet = sh.worksheet('Player_Level_SD_ROO')
|
| 166 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 167 |
+
load_display.replace('', np.nan, inplace=True)
|
| 168 |
+
load_display['STDev'] = load_display['Median'] / 4
|
| 169 |
+
load_display = load_display[load_display['site'] == 'Fanduel']
|
| 170 |
+
load_display = load_display.drop_duplicates(subset=['Player'], keep='first')
|
| 171 |
+
|
| 172 |
+
fd_raw = load_display.dropna(subset=['Median'])
|
| 173 |
|
| 174 |
return dk_raw, fd_raw
|
| 175 |
|
|
|
|
| 235 |
for key in st.session_state.keys():
|
| 236 |
del st.session_state[key]
|
| 237 |
dk_raw, fd_raw = init_baselines()
|
| 238 |
+
|
| 239 |
+
sport_var1 = st.radio("What sport are you working with?", ('NFL', 'NBA'))
|
| 240 |
slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown'))
|
| 241 |
|
| 242 |
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
| 243 |
if site_var1 == 'Draftkings':
|
| 244 |
if slate_var1 == 'Showdown':
|
| 245 |
+
DK_seed = init_DK_seed_frames(sport_var1)
|
| 246 |
elif slate_var1 == 'Secondary Showdown':
|
| 247 |
+
DK_seed = init_DK_secondary_seed_frames(sport_var1)
|
| 248 |
raw_baselines = dk_raw
|
| 249 |
column_names = dk_columns
|
| 250 |
|
|
|
|
| 262 |
|
| 263 |
elif site_var1 == 'Fanduel':
|
| 264 |
if slate_var1 == 'Showdown':
|
| 265 |
+
FD_seed = init_FD_seed_frames(sport_var1)
|
| 266 |
elif slate_var1 == 'Secondary Showdown':
|
| 267 |
+
FD_seed = init_FD_secondary_seed_frames(sport_var1)
|
| 268 |
raw_baselines = fd_raw
|
| 269 |
column_names = fd_columns
|
| 270 |
|
|
|
|
| 326 |
for key in st.session_state.keys():
|
| 327 |
del st.session_state[key]
|
| 328 |
dk_raw, fd_raw = init_baselines()
|
| 329 |
+
sim_sport_var1 = st.radio("What sport are you working with?", ('NFL', 'NBA'))
|
| 330 |
sim_slate_var1 = st.radio("Which data are you loading?", ('Showdown', 'Secondary Showdown'), key='sim_slate_var1')
|
| 331 |
sim_site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'), key='sim_site_var1')
|
| 332 |
if sim_site_var1 == 'Draftkings':
|
| 333 |
if sim_slate_var1 == 'Showdown':
|
| 334 |
+
DK_seed = init_DK_seed_frames(sim_sport_var1)
|
| 335 |
elif sim_slate_var1 == 'Secondary Showdown':
|
| 336 |
+
DK_seed = init_DK_secondary_seed_frames(sim_sport_var1)
|
| 337 |
raw_baselines = dk_raw
|
| 338 |
column_names = dk_columns
|
| 339 |
elif sim_site_var1 == 'Fanduel':
|
| 340 |
if sim_slate_var1 == 'Showdown':
|
| 341 |
+
FD_seed = init_FD_seed_frames(sim_sport_var1)
|
| 342 |
elif sim_slate_var1 == 'Secondary Showdown':
|
| 343 |
+
FD_seed = init_FD_secondary_seed_frames(sim_sport_var1)
|
| 344 |
raw_baselines = fd_raw
|
| 345 |
column_names = fd_columns
|
| 346 |
|