James McCool
commited on
Commit
·
42e193f
1
Parent(s):
b6016b0
Enhance DK and FD lineup initialization in Streamlit app by adding priority variable and mix options for improved data handling. Update UI to include priority selection for optimals, allowing users to customize lineup generation based on projection and ownership metrics.
Browse files- src/streamlit_app.py +146 -76
src/streamlit_app.py
CHANGED
|
@@ -4,6 +4,7 @@ import pandas as pd
|
|
| 4 |
import pymongo
|
| 5 |
import re
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
st.set_page_config(layout="wide")
|
| 9 |
|
|
@@ -170,7 +171,10 @@ def init_baselines():
|
|
| 170 |
return player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map
|
| 171 |
|
| 172 |
@st.cache_resource(ttl = 60)
|
| 173 |
-
def init_DK_lineups(type_var, slate_var):
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
if type_var == 'Regular':
|
| 176 |
if slate_var == 'Main':
|
|
@@ -180,9 +184,14 @@ def init_DK_lineups(type_var, slate_var):
|
|
| 180 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 181 |
|
| 182 |
collection = db['DK_NFL_seed_frame']
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 186 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 187 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 188 |
# Map names
|
|
@@ -194,9 +203,14 @@ def init_DK_lineups(type_var, slate_var):
|
|
| 194 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 195 |
|
| 196 |
collection = db['DK_NFL_Secondary_seed_frame']
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 200 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 201 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 202 |
# Map names
|
|
@@ -208,9 +222,14 @@ def init_DK_lineups(type_var, slate_var):
|
|
| 208 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 209 |
|
| 210 |
collection = db['DK_NFL_Late_seed_frame']
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 214 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 215 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 216 |
# Map names
|
|
@@ -218,21 +237,36 @@ def init_DK_lineups(type_var, slate_var):
|
|
| 218 |
elif type_var == 'Showdown':
|
| 219 |
if slate_var == 'Main':
|
| 220 |
collection = db['DK_NFL_SD_seed_frame']
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 224 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 225 |
elif slate_var == 'Secondary':
|
| 226 |
collection = db['DK_NFL_Secondary_SD_seed_frame']
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 230 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 231 |
elif slate_var == 'Auxiliary':
|
| 232 |
collection = db['DK_NFL_Auxiliary_SD_seed_frame']
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
-
raw_display = pd.DataFrame(list(cursor))
|
| 236 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 237 |
|
| 238 |
DK_seed = raw_display.to_numpy()
|
|
@@ -240,75 +274,108 @@ def init_DK_lineups(type_var, slate_var):
|
|
| 240 |
return DK_seed
|
| 241 |
|
| 242 |
@st.cache_resource(ttl = 60)
|
| 243 |
-
def init_FD_lineups(type_var, slate_var):
|
| 244 |
-
|
| 245 |
-
if type_var == 'Regular':
|
| 246 |
-
if slate_var == 'Main':
|
| 247 |
-
collection = db['FD_NFL_name_map']
|
| 248 |
-
cursor = collection.find()
|
| 249 |
-
raw_data = pd.DataFrame(list(cursor))
|
| 250 |
-
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
raw_display = pd.DataFrame(list(cursor))
|
| 256 |
-
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 257 |
-
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 258 |
-
# Map names
|
| 259 |
-
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 260 |
-
elif slate_var == 'Secondary':
|
| 261 |
-
collection = db['FD_NFL_Secondary_name_map']
|
| 262 |
-
cursor = collection.find()
|
| 263 |
-
raw_data = pd.DataFrame(list(cursor))
|
| 264 |
-
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 265 |
-
|
| 266 |
-
collection = db['FD_NFL_Secondary_seed_frame']
|
| 267 |
-
cursor = collection.find().limit(10000)
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
raw_display = pd.DataFrame(list(cursor))
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
raw_display = pd.DataFrame(list(cursor))
|
| 284 |
-
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 285 |
-
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 286 |
-
# Map names
|
| 287 |
-
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
raw_display = pd.DataFrame(list(cursor))
|
| 295 |
-
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 296 |
-
elif slate_var == 'Secondary':
|
| 297 |
-
collection = db['FD_NFL_Secondary_SD_seed_frame']
|
| 298 |
-
cursor = collection.find().limit(10000)
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
raw_display = pd.DataFrame(list(cursor))
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
raw_display = pd.DataFrame(list(cursor))
|
| 307 |
-
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 308 |
-
|
| 309 |
-
FD_seed = raw_display.to_numpy()
|
| 310 |
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
@st.cache_data
|
| 314 |
def convert_df_to_csv(df):
|
|
@@ -334,8 +401,8 @@ with app_load_reset_column:
|
|
| 334 |
if st.button("Load/Reset Data", key='reset_data_button'):
|
| 335 |
st.cache_data.clear()
|
| 336 |
player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map = init_baselines()
|
| 337 |
-
dk_lineups = init_DK_lineups('Regular', 'Main')
|
| 338 |
-
fd_lineups = init_FD_lineups('Regular', 'Main')
|
| 339 |
for key in st.session_state.keys():
|
| 340 |
del st.session_state[key]
|
| 341 |
with app_view_site_column:
|
|
@@ -901,7 +968,10 @@ elif selected_tab == 'Optimals':
|
|
| 901 |
st.header("Optimals")
|
| 902 |
with st.expander("Info and Filters"):
|
| 903 |
st.info("These filters will display various optimals in the table below to pick from. If you want to export the entire set of 10,000 optimals, hit the 'Prepare full data export' button. If you would like to apply the filters here to the 10,000 optimals before you export, use the 'Prepare full data export (Filter)' button.")
|
| 904 |
-
optimals_site_col, optimals_macro_col, optimals_salary_col, optimals_stacks_col = st.columns(
|
|
|
|
|
|
|
|
|
|
| 905 |
with optimals_site_col:
|
| 906 |
slate_type_var3 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'), key='slate_type_var3_radio')
|
| 907 |
if slate_type_var3 == 'Regular':
|
|
@@ -917,14 +987,14 @@ elif selected_tab == 'Optimals':
|
|
| 917 |
slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'), key='slate_var3_radio')
|
| 918 |
if slate_type_var3 == 'Regular':
|
| 919 |
if site_var == 'Draftkings':
|
| 920 |
-
dk_lineups = init_DK_lineups(slate_type_var3, slate_var3)
|
| 921 |
elif site_var == 'Fanduel':
|
| 922 |
-
fd_lineups = init_FD_lineups(slate_type_var3, slate_var3)
|
| 923 |
elif slate_type_var3 == 'Showdown':
|
| 924 |
if site_var == 'Draftkings':
|
| 925 |
-
dk_lineups = init_DK_lineups(slate_type_var3, slate_var3)
|
| 926 |
elif site_var == 'Fanduel':
|
| 927 |
-
fd_lineups = init_FD_lineups(slate_type_var3, slate_var3)
|
| 928 |
with optimals_macro_col:
|
| 929 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1, key='lineup_num_var_input')
|
| 930 |
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1_radio')
|
|
|
|
| 4 |
import pymongo
|
| 5 |
import re
|
| 6 |
import os
|
| 7 |
+
import math
|
| 8 |
|
| 9 |
st.set_page_config(layout="wide")
|
| 10 |
|
|
|
|
| 171 |
return player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map
|
| 172 |
|
| 173 |
@st.cache_resource(ttl = 60)
|
| 174 |
+
def init_DK_lineups(type_var, slate_var, prio_var, prio_mix):
|
| 175 |
+
|
| 176 |
+
if prio_var == 'Mix':
|
| 177 |
+
prio_var = None
|
| 178 |
|
| 179 |
if type_var == 'Regular':
|
| 180 |
if slate_var == 'Main':
|
|
|
|
| 184 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 185 |
|
| 186 |
collection = db['DK_NFL_seed_frame']
|
| 187 |
+
if prio_var == None:
|
| 188 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 189 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 190 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 191 |
+
else:
|
| 192 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 193 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 194 |
|
|
|
|
| 195 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 196 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 197 |
# Map names
|
|
|
|
| 203 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 204 |
|
| 205 |
collection = db['DK_NFL_Secondary_seed_frame']
|
| 206 |
+
if prio_var == None:
|
| 207 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 208 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 209 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 210 |
+
else:
|
| 211 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 212 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 213 |
|
|
|
|
| 214 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 215 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 216 |
# Map names
|
|
|
|
| 222 |
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 223 |
|
| 224 |
collection = db['DK_NFL_Late_seed_frame']
|
| 225 |
+
if prio_var == None:
|
| 226 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 227 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 228 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 229 |
+
else:
|
| 230 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 231 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 232 |
|
|
|
|
| 233 |
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 234 |
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 235 |
# Map names
|
|
|
|
| 237 |
elif type_var == 'Showdown':
|
| 238 |
if slate_var == 'Main':
|
| 239 |
collection = db['DK_NFL_SD_seed_frame']
|
| 240 |
+
if prio_var == None:
|
| 241 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 242 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 243 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 244 |
+
else:
|
| 245 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 246 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 247 |
|
|
|
|
| 248 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 249 |
elif slate_var == 'Secondary':
|
| 250 |
collection = db['DK_NFL_Secondary_SD_seed_frame']
|
| 251 |
+
if prio_var == None:
|
| 252 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 253 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 254 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 255 |
+
else:
|
| 256 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 257 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 258 |
|
|
|
|
| 259 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 260 |
elif slate_var == 'Auxiliary':
|
| 261 |
collection = db['DK_NFL_Auxiliary_SD_seed_frame']
|
| 262 |
+
if prio_var == None:
|
| 263 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 264 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 265 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 266 |
+
else:
|
| 267 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 268 |
+
raw_display = pd.DataFrame(list(cursor))
|
| 269 |
|
|
|
|
| 270 |
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 271 |
|
| 272 |
DK_seed = raw_display.to_numpy()
|
|
|
|
| 274 |
return DK_seed
|
| 275 |
|
| 276 |
@st.cache_resource(ttl = 60)
|
| 277 |
+
def init_FD_lineups(type_var, slate_var, prio_var, prio_mix):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
+
if prio_var == 'Mix':
|
| 280 |
+
prio_var = None
|
| 281 |
+
|
| 282 |
+
if type_var == 'Regular':
|
| 283 |
+
if slate_var == 'Main':
|
| 284 |
+
collection = db['FD_NFL_name_map']
|
| 285 |
+
cursor = collection.find()
|
| 286 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 287 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 288 |
|
| 289 |
+
collection = db['FD_NFL_seed_frame']
|
| 290 |
+
if prio_var == None:
|
| 291 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 292 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 293 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 294 |
+
else:
|
| 295 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 296 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 299 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 300 |
+
# Map names
|
| 301 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 302 |
+
elif slate_var == 'Secondary':
|
| 303 |
+
collection = db['FD_NFL_Secondary_name_map']
|
| 304 |
+
cursor = collection.find()
|
| 305 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 306 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 307 |
+
|
| 308 |
+
collection = db['FD_NFL_Secondary_seed_frame']
|
| 309 |
+
if prio_var == None:
|
| 310 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 311 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 312 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 313 |
+
else:
|
| 314 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 315 |
raw_display = pd.DataFrame(list(cursor))
|
| 316 |
+
|
| 317 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 318 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 319 |
+
# Map names
|
| 320 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 321 |
+
elif slate_var == 'Auxiliary':
|
| 322 |
+
collection = db['FD_NFL_Late_name_map']
|
| 323 |
+
cursor = collection.find()
|
| 324 |
+
raw_data = pd.DataFrame(list(cursor))
|
| 325 |
+
names_dict = dict(zip(raw_data['key'], raw_data['value']))
|
| 326 |
+
|
| 327 |
+
collection = db['FD_NFL_Late_seed_frame']
|
| 328 |
+
if prio_var == None:
|
| 329 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 330 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 331 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 332 |
+
else:
|
| 333 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 334 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
+
raw_display = raw_display[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 337 |
+
dict_columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 338 |
+
# Map names
|
| 339 |
+
raw_display[dict_columns] = raw_display[dict_columns].apply(lambda x: x.map(names_dict))
|
| 340 |
|
| 341 |
+
elif type_var == 'Showdown':
|
| 342 |
+
if slate_var == 'Main':
|
| 343 |
+
collection = db['FD_NFL_SD_seed_frame']
|
| 344 |
+
if prio_var == None:
|
| 345 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 346 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 347 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 348 |
+
else:
|
| 349 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 350 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 353 |
+
elif slate_var == 'Secondary':
|
| 354 |
+
collection = db['FD_NFL_Secondary_SD_seed_frame']
|
| 355 |
+
if prio_var == None:
|
| 356 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 357 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 358 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 359 |
+
else:
|
| 360 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 361 |
raw_display = pd.DataFrame(list(cursor))
|
| 362 |
+
|
| 363 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 364 |
+
elif slate_var == 'Auxiliary':
|
| 365 |
+
collection = db['FD_NFL_Auxiliary_SD_seed_frame']
|
| 366 |
+
if prio_var == None:
|
| 367 |
+
cursor1 = collection.find().limit(math.ceil(10000 * (prio_mix / 100)))
|
| 368 |
+
cursor2 = collection.find().sort('Own', -1).limit(math.ceil(10000 * ((100 - prio_mix) / 100)))
|
| 369 |
+
raw_display = pd.concat([pd.DataFrame(list(cursor1)), pd.DataFrame(list(cursor2))])
|
| 370 |
+
else:
|
| 371 |
+
cursor = collection.find().sort(prio_var, -1).limit(10000)
|
| 372 |
raw_display = pd.DataFrame(list(cursor))
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
+
raw_display = raw_display[['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5', 'salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own']]
|
| 375 |
+
|
| 376 |
+
FD_seed = raw_display.to_numpy()
|
| 377 |
+
|
| 378 |
+
return FD_seed
|
| 379 |
|
| 380 |
@st.cache_data
|
| 381 |
def convert_df_to_csv(df):
|
|
|
|
| 401 |
if st.button("Load/Reset Data", key='reset_data_button'):
|
| 402 |
st.cache_data.clear()
|
| 403 |
player_stats, dk_stacks_raw, fd_stacks_raw, dk_roo_raw, fd_roo_raw, dk_sd_roo_raw, fd_sd_roo_raw, dk_id_map, fd_id_map, dk_sd_id_map, fd_sd_id_map = init_baselines()
|
| 404 |
+
dk_lineups = init_DK_lineups('Regular', 'Main', 'proj', 50)
|
| 405 |
+
fd_lineups = init_FD_lineups('Regular', 'Main', 'proj', 50)
|
| 406 |
for key in st.session_state.keys():
|
| 407 |
del st.session_state[key]
|
| 408 |
with app_view_site_column:
|
|
|
|
| 968 |
st.header("Optimals")
|
| 969 |
with st.expander("Info and Filters"):
|
| 970 |
st.info("These filters will display various optimals in the table below to pick from. If you want to export the entire set of 10,000 optimals, hit the 'Prepare full data export' button. If you would like to apply the filters here to the 10,000 optimals before you export, use the 'Prepare full data export (Filter)' button.")
|
| 971 |
+
prio_col, optimals_site_col, optimals_macro_col, optimals_salary_col, optimals_stacks_col = st.columns(5)
|
| 972 |
+
with prio_col:
|
| 973 |
+
prio_var = st.radio("Which priority variable do you want to use?", ('proj', 'Own', 'Mix'), key='prio_var_radio')
|
| 974 |
+
prio_mix = st.number_input("If Mix, what split of Projection/Ownership to dedicate to Projection?", min_value=0, max_value=100, value=50, step=1)
|
| 975 |
with optimals_site_col:
|
| 976 |
slate_type_var3 = st.radio("Which slate type are you loading?", ('Regular', 'Showdown'), key='slate_type_var3_radio')
|
| 977 |
if slate_type_var3 == 'Regular':
|
|
|
|
| 987 |
slate_var3 = st.radio("Which slate data are you loading?", ('Main', 'Secondary', 'Auxiliary'), key='slate_var3_radio')
|
| 988 |
if slate_type_var3 == 'Regular':
|
| 989 |
if site_var == 'Draftkings':
|
| 990 |
+
dk_lineups = init_DK_lineups(slate_type_var3, slate_var3, prio_var, prio_mix)
|
| 991 |
elif site_var == 'Fanduel':
|
| 992 |
+
fd_lineups = init_FD_lineups(slate_type_var3, slate_var3, prio_var, prio_mix)
|
| 993 |
elif slate_type_var3 == 'Showdown':
|
| 994 |
if site_var == 'Draftkings':
|
| 995 |
+
dk_lineups = init_DK_lineups(slate_type_var3, slate_var3, prio_var, prio_mix)
|
| 996 |
elif site_var == 'Fanduel':
|
| 997 |
+
fd_lineups = init_FD_lineups(slate_type_var3, slate_var3, prio_var, prio_mix)
|
| 998 |
with optimals_macro_col:
|
| 999 |
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1, key='lineup_num_var_input')
|
| 1000 |
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1_radio')
|