Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,64 +46,6 @@ player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_fi
|
|
| 46 |
|
| 47 |
freq_format = {'Proj Own': '{:.2%}', 'Exposure': '{:.2%}', 'Edge': '{:.2%}'}
|
| 48 |
|
| 49 |
-
@st.cache_resource(ttl = 60)
|
| 50 |
-
def set_slate_teams():
|
| 51 |
-
sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
| 52 |
-
worksheet = sh.worksheet('Site_Info')
|
| 53 |
-
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 54 |
-
|
| 55 |
-
return raw_display
|
| 56 |
-
|
| 57 |
-
@st.cache_resource(ttl = 60)
|
| 58 |
-
def player_stat_table():
|
| 59 |
-
sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
| 60 |
-
worksheet = sh.worksheet('Player_Projections')
|
| 61 |
-
raw_display = pd.DataFrame(worksheet.get_all_records())
|
| 62 |
-
|
| 63 |
-
return raw_display
|
| 64 |
-
|
| 65 |
-
@st.cache_resource(ttl = 60)
|
| 66 |
-
def load_dk_player_projections():
|
| 67 |
-
sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
| 68 |
-
worksheet = sh.worksheet('DK_ROO')
|
| 69 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 70 |
-
load_display.replace('', np.nan, inplace=True)
|
| 71 |
-
raw_display = load_display.dropna(subset=['Median'])
|
| 72 |
-
del load_display
|
| 73 |
-
|
| 74 |
-
return raw_display
|
| 75 |
-
|
| 76 |
-
@st.cache_resource(ttl = 60)
|
| 77 |
-
def load_fd_player_projections():
|
| 78 |
-
sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
| 79 |
-
worksheet = sh.worksheet('FD_ROO')
|
| 80 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 81 |
-
load_display.replace('', np.nan, inplace=True)
|
| 82 |
-
raw_display = load_display.dropna(subset=['Median'])
|
| 83 |
-
del load_display
|
| 84 |
-
|
| 85 |
-
return raw_display
|
| 86 |
-
|
| 87 |
-
@st.cache_resource(ttl = 60)
|
| 88 |
-
def set_export_ids():
|
| 89 |
-
sh = gc.open_by_url('https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348')
|
| 90 |
-
worksheet = sh.worksheet('DK_ROO')
|
| 91 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 92 |
-
load_display.replace('', np.nan, inplace=True)
|
| 93 |
-
raw_display = load_display.dropna(subset=['Median'])
|
| 94 |
-
dk_ids = dict(zip(raw_display['Player'], raw_display['player_id']))
|
| 95 |
-
|
| 96 |
-
worksheet = sh.worksheet('FD_ROO')
|
| 97 |
-
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 98 |
-
load_display.replace('', np.nan, inplace=True)
|
| 99 |
-
raw_display = load_display.dropna(subset=['Median'])
|
| 100 |
-
fd_ids = dict(zip(raw_display['Player'], raw_display['player_id']))
|
| 101 |
-
|
| 102 |
-
del load_display
|
| 103 |
-
del raw_display
|
| 104 |
-
|
| 105 |
-
return dk_ids, fd_ids
|
| 106 |
-
|
| 107 |
@st.cache_data
|
| 108 |
def convert_df_to_csv(df):
|
| 109 |
return df.to_csv().encode('utf-8')
|
|
@@ -198,12 +140,12 @@ def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
|
| 198 |
|
| 199 |
def get_overall_merged_df():
|
| 200 |
ref_dict = {
|
| 201 |
-
'pos':['RB', 'WR', '
|
| 202 |
-
'pos_dfs':['RB_Table', 'WR_Table', '
|
| 203 |
-
'pos_dicts':['rb_dict', 'wr_dict', '
|
| 204 |
}
|
| 205 |
|
| 206 |
-
for i in range(0,
|
| 207 |
ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i] =\
|
| 208 |
create_overall_dfs(pos_players, ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i], ref_dict['pos'][i])
|
| 209 |
|
|
@@ -226,7 +168,7 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
|
| 226 |
ranges_dict = {}
|
| 227 |
|
| 228 |
# Calculate ranges
|
| 229 |
-
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 20, 30
|
| 230 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
| 231 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
| 232 |
if max_var <= 10:
|
|
@@ -244,11 +186,11 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
|
| 244 |
|
| 245 |
# Generate random portfolios
|
| 246 |
rng = np.random.default_rng()
|
| 247 |
-
total_elements = [1,
|
| 248 |
-
keys = ['qb', 'rb', 'wr', '
|
| 249 |
|
| 250 |
all_choices = [rng.choice(ranges_dict[f"{key}_range"], size=(Total_Sample_Size, elem)) for key, elem in zip(keys, total_elements)]
|
| 251 |
-
RandomPortfolio = pd.DataFrame(np.hstack(all_choices), columns=['QB', 'RB1', '
|
| 252 |
RandomPortfolio['User/Field'] = 0
|
| 253 |
|
| 254 |
del O_merge
|
|
@@ -263,40 +205,16 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 263 |
stack_num = random.randint(1, 3)
|
| 264 |
stacking_dict = create_stack_options(raw_baselines, stack_num)
|
| 265 |
|
| 266 |
-
# # Create a dictionary for mapping positions to their corresponding dictionaries
|
| 267 |
-
# dict_map = {
|
| 268 |
-
# 'QB': qb_dict,
|
| 269 |
-
# 'RB1': full_pos_player_dict['pos_dicts'][0],
|
| 270 |
-
# 'RB2': full_pos_player_dict['pos_dicts'][0],
|
| 271 |
-
# 'WR1': full_pos_player_dict['pos_dicts'][1],
|
| 272 |
-
# 'WR2': full_pos_player_dict['pos_dicts'][1],
|
| 273 |
-
# 'WR3': full_pos_player_dict['pos_dicts'][1],
|
| 274 |
-
# 'TE': full_pos_player_dict['pos_dicts'][2],
|
| 275 |
-
# 'FLEX': full_pos_player_dict['pos_dicts'][3],
|
| 276 |
-
# 'DST': def_dict
|
| 277 |
-
# }
|
| 278 |
-
|
| 279 |
-
# # Apply mapping for each position
|
| 280 |
-
# for pos, mapping in dict_map.items():
|
| 281 |
-
# RandomPortfolio[pos] = RandomPortfolio[pos].map(mapping).astype("string[pyarrow]")
|
| 282 |
-
|
| 283 |
-
# # This part appears to be for filtering. Consider if it can be optimized depending on the data characteristics
|
| 284 |
-
# RandomPortfolio['plyr_list'] = RandomPortfolio.values.tolist()
|
| 285 |
-
# RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 286 |
-
# RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 10].drop(columns=['plyr_list','plyr_count']).reset_index(drop=True)
|
| 287 |
-
|
| 288 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 289 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 290 |
-
RandomPortfolio['RB2'] = pd.Series(list(RandomPortfolio['RB2'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 291 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['QB'].map(stacking_dict)), dtype="string[pyarrow]")
|
| 292 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 293 |
-
RandomPortfolio['
|
| 294 |
-
RandomPortfolio['
|
| 295 |
-
RandomPortfolio['FLEX'] = pd.Series(list(RandomPortfolio['FLEX'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
| 296 |
RandomPortfolio['DST'] = pd.Series(list(RandomPortfolio['DST'].map(def_dict)), dtype="string[pyarrow]")
|
| 297 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 298 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 299 |
-
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] ==
|
| 300 |
reset_index(drop=True)
|
| 301 |
|
| 302 |
del sizesplit
|
|
@@ -304,48 +222,40 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 304 |
del ranges_dict
|
| 305 |
del stack_num
|
| 306 |
del stacking_dict
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 311 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 312 |
-
RandomPortfolio['RB2s'] = RandomPortfolio['RB2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 313 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 314 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 315 |
-
RandomPortfolio['
|
| 316 |
-
RandomPortfolio['
|
| 317 |
-
RandomPortfolio['FLEXs'] = RandomPortfolio['FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 318 |
RandomPortfolio['DSTs'] = RandomPortfolio['DST'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 319 |
|
| 320 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 321 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 322 |
-
RandomPortfolio['RB2p'] = RandomPortfolio['RB2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 323 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 324 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 325 |
-
RandomPortfolio['
|
| 326 |
-
RandomPortfolio['
|
| 327 |
-
RandomPortfolio['FLEXp'] = RandomPortfolio['FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 328 |
RandomPortfolio['DSTp'] = RandomPortfolio['DST'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 329 |
|
| 330 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 331 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 332 |
-
RandomPortfolio['RB2o'] = RandomPortfolio['RB2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 333 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 334 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 335 |
-
RandomPortfolio['
|
| 336 |
-
RandomPortfolio['
|
| 337 |
-
RandomPortfolio['FLEXo'] = RandomPortfolio['FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 338 |
RandomPortfolio['DSTo'] = RandomPortfolio['DST'].map(maps_dict['Own_map']).astype(np.float16)
|
| 339 |
|
| 340 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 341 |
del RandomPortfolio
|
| 342 |
|
| 343 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 344 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 345 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 346 |
|
| 347 |
-
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[
|
| 348 |
-
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', '
|
| 349 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 350 |
del RandomPortArray
|
| 351 |
del RandomPortArrayOut
|
|
@@ -353,47 +263,38 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 353 |
if insert_port == 1:
|
| 354 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 355 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
| 356 |
-
CleanPortfolio['RB2'].map(maps_dict['Salary_map']),
|
| 357 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 358 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 359 |
-
CleanPortfolio['
|
| 360 |
-
CleanPortfolio['
|
| 361 |
-
CleanPortfolio['FLEX'].map(maps_dict['Salary_map']),
|
| 362 |
CleanPortfolio['DST'].map(maps_dict['Salary_map'])
|
| 363 |
]).astype(np.int16)
|
| 364 |
if insert_port == 1:
|
| 365 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 366 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
| 367 |
-
CleanPortfolio['RB2'].map(up_dict['Projection_map']),
|
| 368 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 369 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 370 |
-
CleanPortfolio['
|
| 371 |
-
CleanPortfolio['
|
| 372 |
-
CleanPortfolio['FLEX'].map(up_dict['Projection_map']),
|
| 373 |
CleanPortfolio['DST'].map(up_dict['Projection_map'])
|
| 374 |
]).astype(np.float16)
|
| 375 |
if insert_port == 1:
|
| 376 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 377 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
| 378 |
-
CleanPortfolio['RB2'].map(maps_dict['Own_map']),
|
| 379 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 380 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 381 |
-
CleanPortfolio['
|
| 382 |
-
CleanPortfolio['
|
| 383 |
-
CleanPortfolio['FLEX'].map(maps_dict['Own_map']),
|
| 384 |
CleanPortfolio['DST'].map(maps_dict['Own_map'])
|
| 385 |
]).astype(np.float16)
|
| 386 |
|
| 387 |
if site_var1 == 'Draftkings':
|
| 388 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 50000].reset_index(drop=True)
|
| 389 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (49500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
| 390 |
-
elif site_var1 == 'Fanduel':
|
| 391 |
-
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 60000].reset_index(drop=True)
|
| 392 |
-
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (59500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
| 393 |
|
| 394 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 395 |
|
| 396 |
-
RandomPortfolio = RandomPortfolio[['QB', 'RB1', '
|
| 397 |
|
| 398 |
return RandomPortfolio, maps_dict
|
| 399 |
|
|
@@ -405,120 +306,95 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
|
| 405 |
|
| 406 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 407 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 408 |
-
RandomPortfolio['RB2'] = pd.Series(list(RandomPortfolio['RB2'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 409 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['WR1'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 410 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 411 |
-
RandomPortfolio['
|
| 412 |
-
RandomPortfolio['
|
| 413 |
-
RandomPortfolio['FLEX'] = pd.Series(list(RandomPortfolio['FLEX'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
| 414 |
RandomPortfolio['DST'] = pd.Series(list(RandomPortfolio['DST'].map(def_dict)), dtype="string[pyarrow]")
|
| 415 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 416 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 417 |
-
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] ==
|
| 418 |
reset_index(drop=True)
|
| 419 |
|
| 420 |
del sizesplit
|
| 421 |
del full_pos_player_dict
|
| 422 |
-
del ranges_dict
|
| 423 |
-
|
| 424 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 425 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 426 |
-
RandomPortfolio['RB2s'] = RandomPortfolio['RB2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 427 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 428 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 429 |
-
RandomPortfolio['
|
| 430 |
-
RandomPortfolio['
|
| 431 |
-
RandomPortfolio['FLEXs'] = RandomPortfolio['FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 432 |
RandomPortfolio['DSTs'] = RandomPortfolio['DST'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 433 |
|
| 434 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 435 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 436 |
-
RandomPortfolio['RB2p'] = RandomPortfolio['RB2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 437 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 438 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 439 |
-
RandomPortfolio['
|
| 440 |
-
RandomPortfolio['
|
| 441 |
-
RandomPortfolio['FLEXp'] = RandomPortfolio['FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 442 |
RandomPortfolio['DSTp'] = RandomPortfolio['DST'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 443 |
|
| 444 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 445 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 446 |
-
RandomPortfolio['RB2o'] = RandomPortfolio['RB2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 447 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 448 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 449 |
-
RandomPortfolio['
|
| 450 |
-
RandomPortfolio['
|
| 451 |
-
RandomPortfolio['FLEXo'] = RandomPortfolio['FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 452 |
RandomPortfolio['DSTo'] = RandomPortfolio['DST'].map(maps_dict['Own_map']).astype(np.float16)
|
| 453 |
|
| 454 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 455 |
del RandomPortfolio
|
| 456 |
|
| 457 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 458 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 459 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 460 |
|
| 461 |
-
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[
|
| 462 |
-
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', '
|
| 463 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 464 |
del RandomPortArray
|
| 465 |
del RandomPortArrayOut
|
| 466 |
-
|
| 467 |
-
|
| 468 |
if insert_port == 1:
|
| 469 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 470 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
| 471 |
-
CleanPortfolio['RB2'].map(maps_dict['Salary_map']),
|
| 472 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 473 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 474 |
-
CleanPortfolio['
|
| 475 |
-
CleanPortfolio['
|
| 476 |
-
CleanPortfolio['FLEX'].map(maps_dict['Salary_map']),
|
| 477 |
CleanPortfolio['DST'].map(maps_dict['Salary_map'])
|
| 478 |
]).astype(np.int16)
|
| 479 |
if insert_port == 1:
|
| 480 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 481 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
| 482 |
-
CleanPortfolio['RB2'].map(up_dict['Projection_map']),
|
| 483 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 484 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 485 |
-
CleanPortfolio['
|
| 486 |
-
CleanPortfolio['
|
| 487 |
-
CleanPortfolio['FLEX'].map(up_dict['Projection_map']),
|
| 488 |
CleanPortfolio['DST'].map(up_dict['Projection_map'])
|
| 489 |
]).astype(np.float16)
|
| 490 |
if insert_port == 1:
|
| 491 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 492 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
| 493 |
-
CleanPortfolio['RB2'].map(maps_dict['Own_map']),
|
| 494 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 495 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 496 |
-
CleanPortfolio['
|
| 497 |
-
CleanPortfolio['
|
| 498 |
-
CleanPortfolio['FLEX'].map(maps_dict['Own_map']),
|
| 499 |
CleanPortfolio['DST'].map(maps_dict['Own_map'])
|
| 500 |
]).astype(np.float16)
|
| 501 |
|
| 502 |
if site_var1 == 'Draftkings':
|
| 503 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 50000].reset_index(drop=True)
|
| 504 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (49500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
| 505 |
-
elif site_var1 == 'Fanduel':
|
| 506 |
-
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 60000].reset_index(drop=True)
|
| 507 |
-
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (59500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
| 508 |
|
| 509 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 510 |
|
| 511 |
-
RandomPortfolio = RandomPortfolio[['QB', 'RB1', '
|
| 512 |
|
| 513 |
return RandomPortfolio, maps_dict
|
| 514 |
|
| 515 |
-
player_stats = player_stat_table()
|
| 516 |
-
dk_roo_raw = load_dk_player_projections()
|
| 517 |
-
fd_roo_raw = load_fd_player_projections()
|
| 518 |
-
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 519 |
-
site_slates = set_slate_teams()
|
| 520 |
-
dkid_dict, fdid_dict = set_export_ids()
|
| 521 |
-
|
| 522 |
static_exposure = pd.DataFrame(columns=['Player', 'count'])
|
| 523 |
overall_exposure = pd.DataFrame(columns=['Player', 'count'])
|
| 524 |
|
|
@@ -557,7 +433,7 @@ with tab1:
|
|
| 557 |
player_team_dict = dict(zip(proj_dataframe.Player, proj_dataframe.Team))
|
| 558 |
|
| 559 |
with col2:
|
| 560 |
-
st.info("The Portfolio file must contain only columns in order and explicitly named: 'QB', 'RB1', '
|
| 561 |
portfolio_file = st.file_uploader("Upload Portfolio File", key = 'portfolio_uploader')
|
| 562 |
|
| 563 |
if portfolio_file is not None:
|
|
@@ -569,201 +445,158 @@ with tab1:
|
|
| 569 |
|
| 570 |
try:
|
| 571 |
try:
|
| 572 |
-
portfolio_dataframe.columns=["QB", "RB1", "
|
| 573 |
split_portfolio = portfolio_dataframe
|
| 574 |
split_portfolio[['QB', 'QB_ID']] = split_portfolio.QB.str.split("(", n=1, expand = True)
|
| 575 |
split_portfolio[['RB1', 'RB1_ID']] = split_portfolio.RB1.str.split("(", n=1, expand = True)
|
| 576 |
-
split_portfolio[['RB2', 'RB2_ID']] = split_portfolio.RB2.str.split("(", n=1, expand = True)
|
| 577 |
split_portfolio[['WR1', 'WR1_ID']] = split_portfolio.WR1.str.split("(", n=1, expand = True)
|
| 578 |
split_portfolio[['WR2', 'WR2_ID']] = split_portfolio.WR2.str.split("(", n=1, expand = True)
|
| 579 |
-
split_portfolio[['
|
| 580 |
-
split_portfolio[['
|
| 581 |
-
split_portfolio[['FLEX', 'FLEX_ID']] = split_portfolio.FLEX.str.split("(", n=1, expand = True)
|
| 582 |
split_portfolio[['DST', 'DST_ID']] = split_portfolio.DST.str.split("(", n=1, expand = True)
|
| 583 |
|
| 584 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 585 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
| 586 |
-
split_portfolio['RB2'] = split_portfolio['RB2'].str.strip()
|
| 587 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 588 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 589 |
-
split_portfolio['
|
| 590 |
-
split_portfolio['
|
| 591 |
-
split_portfolio['FLEX'] = split_portfolio['FLEX'].str.strip()
|
| 592 |
split_portfolio['DST'] = split_portfolio['DST'].str.strip()
|
| 593 |
|
| 594 |
st.table(split_portfolio.head(10))
|
| 595 |
|
| 596 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 597 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 598 |
-
split_portfolio['RB2'].map(player_salary_dict),
|
| 599 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 600 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 601 |
-
split_portfolio['
|
| 602 |
-
split_portfolio['
|
| 603 |
-
split_portfolio['FLEX'].map(player_salary_dict),
|
| 604 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 605 |
|
| 606 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 607 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 608 |
-
split_portfolio['RB2'].map(player_proj_dict),
|
| 609 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 610 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 611 |
-
split_portfolio['
|
| 612 |
-
split_portfolio['
|
| 613 |
-
split_portfolio['FLEX'].map(player_proj_dict),
|
| 614 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 615 |
|
| 616 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 617 |
split_portfolio['RB1'].map(player_own_dict),
|
| 618 |
-
split_portfolio['RB2'].map(player_own_dict),
|
| 619 |
split_portfolio['WR1'].map(player_own_dict),
|
| 620 |
split_portfolio['WR2'].map(player_own_dict),
|
| 621 |
-
split_portfolio['
|
| 622 |
-
split_portfolio['
|
| 623 |
-
split_portfolio['FLEX'].map(player_own_dict),
|
| 624 |
split_portfolio['DST'].map(player_own_dict)])
|
| 625 |
|
| 626 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 627 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 628 |
-
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 629 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 630 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 631 |
-
split_portfolio['
|
| 632 |
-
split_portfolio['
|
| 633 |
-
split_portfolio['FLEX_team'] = split_portfolio['FLEX'].map(player_team_dict)
|
| 634 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 635 |
|
| 636 |
-
split_portfolio = split_portfolio[['QB', 'RB1', '
|
| 637 |
-
'RB1_team', '
|
| 638 |
-
|
| 639 |
-
split_portfolio['Main_Stack'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).index[0],axis=1)
|
| 640 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).values[0],axis=1)
|
| 641 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio['Main_Stack_Size'] - 1
|
| 642 |
|
| 643 |
|
| 644 |
except:
|
| 645 |
-
portfolio_dataframe.columns=["QB", "RB1", "
|
| 646 |
|
| 647 |
split_portfolio = portfolio_dataframe
|
| 648 |
split_portfolio[['QB_ID', 'QB']] = split_portfolio.QB.str.split(":", n=1, expand = True)
|
| 649 |
split_portfolio[['RB1_ID', 'RB1']] = split_portfolio.RB1.str.split(":", n=1, expand = True)
|
| 650 |
-
split_portfolio[['RB2_ID', 'RB2']] = split_portfolio.RB2.str.split(":", n=1, expand = True)
|
| 651 |
split_portfolio[['WR1_ID', 'WR1']] = split_portfolio.WR1.str.split(":", n=1, expand = True)
|
| 652 |
split_portfolio[['WR2_ID', 'WR2']] = split_portfolio.WR2.str.split(":", n=1, expand = True)
|
| 653 |
-
split_portfolio[['
|
| 654 |
-
split_portfolio[['
|
| 655 |
-
split_portfolio[['FLEX_ID', 'FLEX']] = split_portfolio.FLEX.str.split(":", n=1, expand = True)
|
| 656 |
split_portfolio[['DST_ID', 'DST']] = split_portfolio.DST.str.split(":", n=1, expand = True)
|
| 657 |
|
| 658 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 659 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
| 660 |
-
split_portfolio['RB2'] = split_portfolio['RB2'].str.strip()
|
| 661 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 662 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 663 |
-
split_portfolio['
|
| 664 |
-
split_portfolio['
|
| 665 |
-
split_portfolio['FLEX'] = split_portfolio['FLEX'].str.strip()
|
| 666 |
split_portfolio['DST'] = split_portfolio['DST'].str.strip()
|
| 667 |
|
| 668 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 669 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 670 |
-
split_portfolio['RB2'].map(player_salary_dict),
|
| 671 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 672 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 673 |
-
split_portfolio['
|
| 674 |
-
split_portfolio['
|
| 675 |
-
split_portfolio['FLEX'].map(player_salary_dict),
|
| 676 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 677 |
|
| 678 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 679 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 680 |
-
split_portfolio['RB2'].map(player_proj_dict),
|
| 681 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 682 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 683 |
-
split_portfolio['
|
| 684 |
-
split_portfolio['
|
| 685 |
-
split_portfolio['FLEX'].map(player_proj_dict),
|
| 686 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 687 |
|
| 688 |
st.table(split_portfolio.head(10))
|
| 689 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 690 |
split_portfolio['RB1'].map(player_own_dict),
|
| 691 |
-
split_portfolio['RB2'].map(player_own_dict),
|
| 692 |
split_portfolio['WR1'].map(player_own_dict),
|
| 693 |
split_portfolio['WR2'].map(player_own_dict),
|
| 694 |
-
split_portfolio['
|
| 695 |
-
split_portfolio['
|
| 696 |
-
split_portfolio['FLEX'].map(player_own_dict),
|
| 697 |
split_portfolio['DST'].map(player_own_dict)])
|
| 698 |
|
| 699 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 700 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 701 |
-
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 702 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 703 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 704 |
-
split_portfolio['
|
| 705 |
-
split_portfolio['
|
| 706 |
-
split_portfolio['FLEX_team'] = split_portfolio['FLEX'].map(player_team_dict)
|
| 707 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 708 |
|
| 709 |
-
split_portfolio = split_portfolio[['QB', 'RB1', '
|
| 710 |
-
'RB1_team', '
|
| 711 |
-
|
| 712 |
-
split_portfolio['Main_Stack'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).index[0],axis=1)
|
| 713 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).values[0],axis=1)
|
| 714 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio['Main_Stack_Size'] - 1
|
| 715 |
|
| 716 |
except:
|
| 717 |
split_portfolio = portfolio_dataframe
|
| 718 |
|
| 719 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 720 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 721 |
-
split_portfolio['RB2'].map(player_salary_dict),
|
| 722 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 723 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 724 |
-
split_portfolio['
|
| 725 |
-
split_portfolio['
|
| 726 |
-
split_portfolio['FLEX'].map(player_salary_dict),
|
| 727 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 728 |
|
| 729 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 730 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 731 |
-
split_portfolio['RB2'].map(player_proj_dict),
|
| 732 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 733 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 734 |
-
split_portfolio['
|
| 735 |
-
split_portfolio['
|
| 736 |
-
split_portfolio['FLEX'].map(player_proj_dict),
|
| 737 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 738 |
|
| 739 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 740 |
split_portfolio['RB1'].map(player_own_dict),
|
| 741 |
-
split_portfolio['RB2'].map(player_own_dict),
|
| 742 |
split_portfolio['WR1'].map(player_own_dict),
|
| 743 |
split_portfolio['WR2'].map(player_own_dict),
|
| 744 |
-
split_portfolio['
|
| 745 |
-
split_portfolio['
|
| 746 |
-
split_portfolio['FLEX'].map(player_own_dict),
|
| 747 |
split_portfolio['DST'].map(player_own_dict)])
|
| 748 |
|
| 749 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 750 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 751 |
-
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 752 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 753 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 754 |
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 755 |
-
split_portfolio['
|
| 756 |
-
split_portfolio['
|
| 757 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 758 |
|
| 759 |
-
split_portfolio = split_portfolio[['QB', 'RB1', '
|
| 760 |
-
'RB1_team', '
|
| 761 |
-
|
| 762 |
-
split_portfolio['Main_Stack'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).index[0],axis=1)
|
| 763 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio.iloc[:, 15:19].apply(lambda row: row.value_counts().nlargest(2).values[0],axis=1)
|
| 764 |
-
split_portfolio['Main_Stack_Size'] = split_portfolio['Main_Stack_Size'] - 1
|
| 765 |
|
| 766 |
-
for player_cols in split_portfolio.iloc[:, :
|
| 767 |
static_col_raw = split_portfolio[player_cols].value_counts()
|
| 768 |
static_col = static_col_raw.to_frame()
|
| 769 |
static_col.reset_index(inplace=True)
|
|
@@ -782,26 +615,9 @@ with tab1:
|
|
| 782 |
col1, col2 = st.columns([3, 3])
|
| 783 |
|
| 784 |
if portfolio_file is not None:
|
| 785 |
-
|
| 786 |
-
team_split_var1 = st.radio("Are you wanting to isolate any lineups with specific main stacks?", ('Full Portfolio', 'Specific Stacks'))
|
| 787 |
-
if team_split_var1 == 'Specific Stacks':
|
| 788 |
-
team_var1 = st.multiselect('Which main stacks would you like to include in the Portfolio?', options = split_portfolio['Main_Stack'].unique())
|
| 789 |
-
elif team_split_var1 == 'Full Portfolio':
|
| 790 |
-
team_var1 = split_portfolio.Main_Stack.values.tolist()
|
| 791 |
-
with col2:
|
| 792 |
-
player_split_var1 = st.radio("Are you wanting to isolate any lineups with specific players?", ('Full Players', 'Specific Players'))
|
| 793 |
-
if player_split_var1 == 'Specific Players':
|
| 794 |
-
find_var1 = st.multiselect('Which players must be included in the lineups?', options = static_exposure['Player'].unique())
|
| 795 |
-
elif player_split_var1 == 'Full Players':
|
| 796 |
-
find_var1 = static_exposure.Player.values.tolist()
|
| 797 |
-
|
| 798 |
-
split_portfolio = split_portfolio[split_portfolio['Main_Stack'].isin(team_var1)]
|
| 799 |
-
if player_split_var1 == 'Specific Players':
|
| 800 |
-
split_portfolio = split_portfolio[np.equal.outer(split_portfolio.to_numpy(copy=False), find_var1).any(axis=1).all(axis=1)]
|
| 801 |
-
elif player_split_var1 == 'Full Players':
|
| 802 |
-
split_portfolio = split_portfolio
|
| 803 |
|
| 804 |
-
for player_cols in split_portfolio.iloc[:, :
|
| 805 |
exposure_col_raw = split_portfolio[player_cols].value_counts()
|
| 806 |
exposure_col = exposure_col_raw.to_frame()
|
| 807 |
exposure_col.reset_index(inplace=True)
|
|
@@ -828,7 +644,7 @@ with tab1:
|
|
| 828 |
st.header('Portfolio View')
|
| 829 |
split_portfolio = split_portfolio.reset_index()
|
| 830 |
split_portfolio['Lineup'] = split_portfolio['index'] + 1
|
| 831 |
-
display_portfolio = split_portfolio[['Lineup', 'QB', 'RB1', '
|
| 832 |
display_portfolio = display_portfolio.set_index('Lineup')
|
| 833 |
st.dataframe(display_portfolio.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Ownership']).format(precision=2))
|
| 834 |
del split_portfolio
|
|
@@ -837,29 +653,10 @@ with tab1:
|
|
| 837 |
with tab2:
|
| 838 |
col1, col2 = st.columns([1, 7])
|
| 839 |
with col1:
|
| 840 |
-
st.info(t_stamp)
|
| 841 |
-
if st.button("Load/Reset Data", key='reset1'):
|
| 842 |
-
st.cache_data.clear()
|
| 843 |
-
dk_roo_raw = load_dk_player_projections()
|
| 844 |
-
fd_roo_raw = load_fd_player_projections()
|
| 845 |
-
t_stamp = f"Last Update: " + str(dk_roo_raw['timestamp'][0]) + f" CST"
|
| 846 |
-
site_slates = set_slate_teams()
|
| 847 |
-
dkid_dict, fdid_dict = set_export_ids()
|
| 848 |
|
| 849 |
-
slate_var1 =
|
| 850 |
-
site_var1 =
|
| 851 |
-
|
| 852 |
-
if slate_var1 == 'User':
|
| 853 |
-
raw_baselines = proj_dataframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', 'Own']]
|
| 854 |
-
elif slate_var1 != 'User':
|
| 855 |
-
raw_baselines = dk_roo_raw[dk_roo_raw['slate'] == str(slate_var1)]
|
| 856 |
-
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 857 |
-
elif site_var1 == 'Fanduel':
|
| 858 |
-
if slate_var1 == 'User':
|
| 859 |
-
raw_baselines = proj_dataframe
|
| 860 |
-
elif slate_var1 != 'User':
|
| 861 |
-
raw_baselines = fd_roo_raw[fd_roo_raw['slate'] == str(slate_var1)]
|
| 862 |
-
raw_baselines = raw_baselines[raw_baselines['version'] == 'overall']
|
| 863 |
st.info("If you are uploading a portfolio, note that there is an adjustments to projections and deviation mapping to prevent 'Projection Bias' and create a fair simulation")
|
| 864 |
insert_port1 = st.selectbox("Are you uploading a portfolio?", ('No', 'Yes'), key='insert_port1')
|
| 865 |
if insert_port1 == 'Yes':
|
|
@@ -931,45 +728,20 @@ with tab2:
|
|
| 931 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (10 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 932 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 933 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 934 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 935 |
if contest_var1 == 'Medium':
|
| 936 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (6 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 937 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 938 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 939 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 940 |
if contest_var1 == 'Large':
|
| 941 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 942 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (1.5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 943 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 944 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 945 |
Overall_Proj = OwnFrame[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
| 946 |
|
| 947 |
del OwnFrame
|
| 948 |
-
|
| 949 |
-
elif slate_var1 != 'User':
|
| 950 |
-
initial_proj = raw_baselines
|
| 951 |
-
drop_frame = initial_proj.drop_duplicates(subset = 'Player',keep = 'first')
|
| 952 |
-
OwnFrame = drop_frame[['Player', 'Team', 'Position', 'Median', 'Own', 'Floor', 'Ceiling', 'Salary']]
|
| 953 |
-
if contest_var1 == 'Small':
|
| 954 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (10 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 955 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 956 |
-
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 957 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (900 / OwnFrame['Own%'].sum())
|
| 958 |
-
if contest_var1 == 'Medium':
|
| 959 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (6 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 960 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 961 |
-
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 962 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (900 / OwnFrame['Own%'].sum())
|
| 963 |
-
if contest_var1 == 'Large':
|
| 964 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 965 |
-
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (1.5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 966 |
-
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 967 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (900 / OwnFrame['Own%'].sum())
|
| 968 |
-
Overall_Proj = OwnFrame[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
| 969 |
-
|
| 970 |
-
del initial_proj
|
| 971 |
-
del drop_frame
|
| 972 |
-
del OwnFrame
|
| 973 |
|
| 974 |
if insert_port == 1:
|
| 975 |
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
|
@@ -1039,13 +811,8 @@ with tab2:
|
|
| 1039 |
wrs_raw.dropna(subset=['Median']).reset_index(drop=True)
|
| 1040 |
wrs_raw = wrs_raw.reset_index(drop=True)
|
| 1041 |
wrs_raw = wrs_raw.sort_values(by=['Own', 'Median'], ascending=False)
|
| 1042 |
-
|
| 1043 |
-
tes_raw = Overall_Proj[Overall_Proj.Position == 'TE']
|
| 1044 |
-
tes_raw.dropna(subset=['Median']).reset_index(drop=True)
|
| 1045 |
-
tes_raw = tes_raw.reset_index(drop=True)
|
| 1046 |
-
tes_raw = tes_raw.sort_values(by=['Own', 'Value'], ascending=False)
|
| 1047 |
|
| 1048 |
-
pos_players = pd.concat([rbs_raw, wrs_raw
|
| 1049 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
| 1050 |
pos_players = pos_players.reset_index(drop=True)
|
| 1051 |
|
|
@@ -1053,7 +820,6 @@ with tab2:
|
|
| 1053 |
del defs_raw
|
| 1054 |
del rbs_raw
|
| 1055 |
del wrs_raw
|
| 1056 |
-
del tes_raw
|
| 1057 |
|
| 1058 |
if insert_port == 1:
|
| 1059 |
try:
|
|
@@ -1061,7 +827,7 @@ with tab2:
|
|
| 1061 |
Raw_Portfolio = pd.DataFrame()
|
| 1062 |
|
| 1063 |
# Loop through each position and split the data accordingly
|
| 1064 |
-
positions = ['QB', 'RB1', '
|
| 1065 |
for pos in positions:
|
| 1066 |
temp_df = UserPortfolio[pos].str.split("(", n=1, expand=True)
|
| 1067 |
temp_df.columns = [pos, 'Drop']
|
|
@@ -1078,7 +844,7 @@ with tab2:
|
|
| 1078 |
|
| 1079 |
# Create frequency table for players
|
| 1080 |
cleaport_players = pd.DataFrame(
|
| 1081 |
-
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:
|
| 1082 |
columns=['Player', 'Freq']
|
| 1083 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1084 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
@@ -1099,7 +865,7 @@ with tab2:
|
|
| 1099 |
|
| 1100 |
# Create frequency table for players
|
| 1101 |
cleaport_players = pd.DataFrame(
|
| 1102 |
-
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:
|
| 1103 |
columns=['Player', 'Freq']
|
| 1104 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1105 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
@@ -1111,15 +877,15 @@ with tab2:
|
|
| 1111 |
|
| 1112 |
elif insert_port == 0:
|
| 1113 |
CleanPortfolio = UserPortfolio
|
| 1114 |
-
cleaport_players = pd.DataFrame(np.column_stack(np.unique(CleanPortfolio.iloc[:,0:
|
| 1115 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1116 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
| 1117 |
nerf_frame = Overall_Proj
|
| 1118 |
|
| 1119 |
ref_dict = {
|
| 1120 |
-
'pos':['RB', 'WR', '
|
| 1121 |
-
'pos_dfs':['RB_Table', 'WR_Table', '
|
| 1122 |
-
'pos_dicts':['rb_dict', 'wr_dict', '
|
| 1123 |
}
|
| 1124 |
|
| 1125 |
maps_dict = {
|
|
@@ -1197,7 +963,7 @@ with tab2:
|
|
| 1197 |
else:
|
| 1198 |
sample_arrays = sample_arrays1
|
| 1199 |
|
| 1200 |
-
final_array = sample_arrays[sample_arrays[:,
|
| 1201 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
| 1202 |
Sim_Winners.append(best_lineup)
|
| 1203 |
SimVar += 1
|
|
@@ -1226,16 +992,7 @@ with tab2:
|
|
| 1226 |
# Conditional Replacement
|
| 1227 |
columns_to_replace = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 1228 |
|
| 1229 |
-
|
| 1230 |
-
replace_dict = dkid_dict
|
| 1231 |
-
elif site_var1 == 'Fanduel':
|
| 1232 |
-
replace_dict = fdid_dict
|
| 1233 |
-
|
| 1234 |
-
for col in columns_to_replace:
|
| 1235 |
-
Sim_Winner_Export[col].replace(replace_dict, inplace=True)
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
player_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,0:9].values, return_counts=True)),
|
| 1239 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1240 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 1241 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1263,7 +1020,7 @@ with tab2:
|
|
| 1263 |
|
| 1264 |
qb_freq = qb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1265 |
|
| 1266 |
-
rb_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,
|
| 1267 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1268 |
rb_freq['Freq'] = rb_freq['Freq'].astype(int)
|
| 1269 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1277,7 +1034,7 @@ with tab2:
|
|
| 1277 |
|
| 1278 |
rb_freq = rb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1279 |
|
| 1280 |
-
wr_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[
|
| 1281 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1282 |
wr_freq['Freq'] = wr_freq['Freq'].astype(int)
|
| 1283 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1291,21 +1048,7 @@ with tab2:
|
|
| 1291 |
|
| 1292 |
wr_freq = wr_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1293 |
|
| 1294 |
-
|
| 1295 |
-
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1296 |
-
te_freq['Freq'] = te_freq['Freq'].astype(int)
|
| 1297 |
-
te_freq['Position'] = te_freq['Player'].map(maps_dict['Pos_map'])
|
| 1298 |
-
te_freq['Salary'] = te_freq['Player'].map(maps_dict['Salary_map'])
|
| 1299 |
-
te_freq['Proj Own'] = te_freq['Player'].map(maps_dict['Own_map']) / 100
|
| 1300 |
-
te_freq['Exposure'] = te_freq['Freq']/Sim_size
|
| 1301 |
-
te_freq['Edge'] = te_freq['Exposure'] - te_freq['Proj Own']
|
| 1302 |
-
te_freq['Team'] = te_freq['Player'].map(maps_dict['Team_map'])
|
| 1303 |
-
for checkVar in range(len(team_list)):
|
| 1304 |
-
te_freq['Team'] = te_freq['Team'].replace(item_list, team_list)
|
| 1305 |
-
|
| 1306 |
-
te_freq = te_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1307 |
-
|
| 1308 |
-
flex_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[7]].values, return_counts=True)),
|
| 1309 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1310 |
flex_freq['Freq'] = flex_freq['Freq'].astype(int)
|
| 1311 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1319,7 +1062,7 @@ with tab2:
|
|
| 1319 |
|
| 1320 |
flex_freq = flex_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1321 |
|
| 1322 |
-
dst_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,
|
| 1323 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1324 |
dst_freq['Freq'] = dst_freq['Freq'].astype(int)
|
| 1325 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1346,7 +1089,7 @@ with tab2:
|
|
| 1346 |
|
| 1347 |
with st.container():
|
| 1348 |
freq_container = st.empty()
|
| 1349 |
-
tab1, tab2, tab3, tab4, tab5, tab6
|
| 1350 |
with tab1:
|
| 1351 |
st.dataframe(player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1352 |
st.download_button(
|
|
@@ -1380,14 +1123,6 @@ with tab2:
|
|
| 1380 |
mime='text/csv',
|
| 1381 |
)
|
| 1382 |
with tab5:
|
| 1383 |
-
st.dataframe(te_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1384 |
-
st.download_button(
|
| 1385 |
-
label="Export Exposures",
|
| 1386 |
-
data=convert_df_to_csv(te_freq),
|
| 1387 |
-
file_name='te_freq_export.csv',
|
| 1388 |
-
mime='text/csv',
|
| 1389 |
-
)
|
| 1390 |
-
with tab6:
|
| 1391 |
st.dataframe(flex_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1392 |
st.download_button(
|
| 1393 |
label="Export Exposures",
|
|
@@ -1395,7 +1130,7 @@ with tab2:
|
|
| 1395 |
file_name='flex_freq_export.csv',
|
| 1396 |
mime='text/csv',
|
| 1397 |
)
|
| 1398 |
-
with
|
| 1399 |
st.dataframe(dst_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1400 |
st.download_button(
|
| 1401 |
label="Export Exposures",
|
|
|
|
| 46 |
|
| 47 |
freq_format = {'Proj Own': '{:.2%}', 'Exposure': '{:.2%}', 'Edge': '{:.2%}'}
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@st.cache_data
|
| 50 |
def convert_df_to_csv(df):
|
| 51 |
return df.to_csv().encode('utf-8')
|
|
|
|
| 140 |
|
| 141 |
def get_overall_merged_df():
|
| 142 |
ref_dict = {
|
| 143 |
+
'pos':['RB', 'WR', 'FLEX'],
|
| 144 |
+
'pos_dfs':['RB_Table', 'WR_Table', 'FLEX_Table'],
|
| 145 |
+
'pos_dicts':['rb_dict', 'wr_dict', 'flex_dict']
|
| 146 |
}
|
| 147 |
|
| 148 |
+
for i in range(0,3):
|
| 149 |
ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i] =\
|
| 150 |
create_overall_dfs(pos_players, ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i], ref_dict['pos'][i])
|
| 151 |
|
|
|
|
| 168 |
ranges_dict = {}
|
| 169 |
|
| 170 |
# Calculate ranges
|
| 171 |
+
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 20, 30], ['RB', 'WR', 'FLEX']):
|
| 172 |
count = create_overall_dfs(pos_players, df, dict_val, key)
|
| 173 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
| 174 |
if max_var <= 10:
|
|
|
|
| 186 |
|
| 187 |
# Generate random portfolios
|
| 188 |
rng = np.random.default_rng()
|
| 189 |
+
total_elements = [1, 1, 2, 2, 1]
|
| 190 |
+
keys = ['qb', 'rb', 'wr', 'flex', 'dst']
|
| 191 |
|
| 192 |
all_choices = [rng.choice(ranges_dict[f"{key}_range"], size=(Total_Sample_Size, elem)) for key, elem in zip(keys, total_elements)]
|
| 193 |
+
RandomPortfolio = pd.DataFrame(np.hstack(all_choices), columns=['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST'])
|
| 194 |
RandomPortfolio['User/Field'] = 0
|
| 195 |
|
| 196 |
del O_merge
|
|
|
|
| 205 |
stack_num = random.randint(1, 3)
|
| 206 |
stacking_dict = create_stack_options(raw_baselines, stack_num)
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 209 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
|
|
|
| 210 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['QB'].map(stacking_dict)), dtype="string[pyarrow]")
|
| 211 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 212 |
+
RandomPortfolio['FLEX1'] = pd.Series(list(RandomPortfolio['FLEX1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
| 213 |
+
RandomPortfolio['FLEX2'] = pd.Series(list(RandomPortfolio['FLEX2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
|
|
|
| 214 |
RandomPortfolio['DST'] = pd.Series(list(RandomPortfolio['DST'].map(def_dict)), dtype="string[pyarrow]")
|
| 215 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 216 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 217 |
+
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 8].drop(columns=['plyr_list','plyr_count']).\
|
| 218 |
reset_index(drop=True)
|
| 219 |
|
| 220 |
del sizesplit
|
|
|
|
| 222 |
del ranges_dict
|
| 223 |
del stack_num
|
| 224 |
del stacking_dict
|
| 225 |
+
|
|
|
|
|
|
|
| 226 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 227 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
|
|
|
| 228 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 229 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 230 |
+
RandomPortfolio['FLEX1s'] = RandomPortfolio['FLEX1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 231 |
+
RandomPortfolio['FLEX2s'] = RandomPortfolio['FLEX2'].map(maps_dict['Salary_map']).astype(np.int32)
|
|
|
|
| 232 |
RandomPortfolio['DSTs'] = RandomPortfolio['DST'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 233 |
|
| 234 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 235 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
|
|
|
| 236 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 237 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 238 |
+
RandomPortfolio['FLEX1p'] = RandomPortfolio['FLEX1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 239 |
+
RandomPortfolio['FLEX2p'] = RandomPortfolio['FLEX2'].map(maps_dict['Projection_map']).astype(np.float16)
|
|
|
|
| 240 |
RandomPortfolio['DSTp'] = RandomPortfolio['DST'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 241 |
|
| 242 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 243 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
|
|
|
| 244 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 245 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 246 |
+
RandomPortfolio['FLEX1o'] = RandomPortfolio['FLEX1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 247 |
+
RandomPortfolio['FLEX2o'] = RandomPortfolio['FLEX2'].map(maps_dict['Own_map']).astype(np.float16)
|
|
|
|
| 248 |
RandomPortfolio['DSTo'] = RandomPortfolio['DST'].map(maps_dict['Own_map']).astype(np.float16)
|
| 249 |
|
| 250 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 251 |
del RandomPortfolio
|
| 252 |
|
| 253 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,8:17].astype(int))]
|
| 254 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,17:26].astype(np.double))]
|
| 255 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,26:35].astype(np.double))]
|
| 256 |
|
| 257 |
+
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[8:35], axis=1)
|
| 258 |
+
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'User/Field', 'Salary', 'Projection', 'Own'])
|
| 259 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 260 |
del RandomPortArray
|
| 261 |
del RandomPortArrayOut
|
|
|
|
| 263 |
if insert_port == 1:
|
| 264 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 265 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
|
|
|
| 266 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 267 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 268 |
+
CleanPortfolio['FLEX1'].map(maps_dict['Salary_map']),
|
| 269 |
+
CleanPortfolio['FLEX2'].map(maps_dict['Salary_map']),
|
|
|
|
| 270 |
CleanPortfolio['DST'].map(maps_dict['Salary_map'])
|
| 271 |
]).astype(np.int16)
|
| 272 |
if insert_port == 1:
|
| 273 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 274 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
|
|
|
| 275 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 276 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 277 |
+
CleanPortfolio['FLEX1'].map(up_dict['Projection_map']),
|
| 278 |
+
CleanPortfolio['FLEX2'].map(up_dict['Projection_map']),
|
|
|
|
| 279 |
CleanPortfolio['DST'].map(up_dict['Projection_map'])
|
| 280 |
]).astype(np.float16)
|
| 281 |
if insert_port == 1:
|
| 282 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 283 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
|
|
|
| 284 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 285 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 286 |
+
CleanPortfolio['FLEX1'].map(maps_dict['Own_map']),
|
| 287 |
+
CleanPortfolio['FLEX2'].map(maps_dict['Own_map']),
|
|
|
|
| 288 |
CleanPortfolio['DST'].map(maps_dict['Own_map'])
|
| 289 |
]).astype(np.float16)
|
| 290 |
|
| 291 |
if site_var1 == 'Draftkings':
|
| 292 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 50000].reset_index(drop=True)
|
| 293 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (49500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
|
|
|
|
|
|
|
|
|
| 294 |
|
| 295 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 296 |
|
| 297 |
+
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
| 298 |
|
| 299 |
return RandomPortfolio, maps_dict
|
| 300 |
|
|
|
|
| 306 |
|
| 307 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 308 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
|
|
|
| 309 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['WR1'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 310 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 311 |
+
RandomPortfolio['FLEX1'] = pd.Series(list(RandomPortfolio['FLEX1'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
| 312 |
+
RandomPortfolio['FLEX2'] = pd.Series(list(RandomPortfolio['FLEX2'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
|
|
|
| 313 |
RandomPortfolio['DST'] = pd.Series(list(RandomPortfolio['DST'].map(def_dict)), dtype="string[pyarrow]")
|
| 314 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 315 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 316 |
+
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 8].drop(columns=['plyr_list','plyr_count']).\
|
| 317 |
reset_index(drop=True)
|
| 318 |
|
| 319 |
del sizesplit
|
| 320 |
del full_pos_player_dict
|
| 321 |
+
del ranges_dict
|
| 322 |
+
|
| 323 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 324 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
|
|
|
| 325 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 326 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 327 |
+
RandomPortfolio['FLEX1s'] = RandomPortfolio['FLEX1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 328 |
+
RandomPortfolio['FLEX2s'] = RandomPortfolio['FLEX2'].map(maps_dict['Salary_map']).astype(np.int32)
|
|
|
|
| 329 |
RandomPortfolio['DSTs'] = RandomPortfolio['DST'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 330 |
|
| 331 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 332 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
|
|
|
| 333 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 334 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 335 |
+
RandomPortfolio['FLEX1p'] = RandomPortfolio['FLEX1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 336 |
+
RandomPortfolio['FLEX2p'] = RandomPortfolio['FLEX2'].map(maps_dict['Projection_map']).astype(np.float16)
|
|
|
|
| 337 |
RandomPortfolio['DSTp'] = RandomPortfolio['DST'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 338 |
|
| 339 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 340 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
|
|
|
| 341 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 342 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 343 |
+
RandomPortfolio['FLEX1o'] = RandomPortfolio['FLEX1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 344 |
+
RandomPortfolio['FLEX2o'] = RandomPortfolio['FLEX2'].map(maps_dict['Own_map']).astype(np.float16)
|
|
|
|
| 345 |
RandomPortfolio['DSTo'] = RandomPortfolio['DST'].map(maps_dict['Own_map']).astype(np.float16)
|
| 346 |
|
| 347 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 348 |
del RandomPortfolio
|
| 349 |
|
| 350 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,8:17].astype(int))]
|
| 351 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,17:26].astype(np.double))]
|
| 352 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,26:35].astype(np.double))]
|
| 353 |
|
| 354 |
+
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[8:35], axis=1)
|
| 355 |
+
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'User/Field', 'Salary', 'Projection', 'Own'])
|
| 356 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 357 |
del RandomPortArray
|
| 358 |
del RandomPortArrayOut
|
| 359 |
+
|
|
|
|
| 360 |
if insert_port == 1:
|
| 361 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 362 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
|
|
|
| 363 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 364 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 365 |
+
CleanPortfolio['FLEX1'].map(maps_dict['Salary_map']),
|
| 366 |
+
CleanPortfolio['FLEX2'].map(maps_dict['Salary_map']),
|
|
|
|
| 367 |
CleanPortfolio['DST'].map(maps_dict['Salary_map'])
|
| 368 |
]).astype(np.int16)
|
| 369 |
if insert_port == 1:
|
| 370 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 371 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
|
|
|
| 372 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 373 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 374 |
+
CleanPortfolio['FLEX1'].map(up_dict['Projection_map']),
|
| 375 |
+
CleanPortfolio['FLEX2'].map(up_dict['Projection_map']),
|
|
|
|
| 376 |
CleanPortfolio['DST'].map(up_dict['Projection_map'])
|
| 377 |
]).astype(np.float16)
|
| 378 |
if insert_port == 1:
|
| 379 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 380 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
|
|
|
| 381 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 382 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 383 |
+
CleanPortfolio['FLEX1'].map(maps_dict['Own_map']),
|
| 384 |
+
CleanPortfolio['FLEX2'].map(maps_dict['Own_map']),
|
|
|
|
| 385 |
CleanPortfolio['DST'].map(maps_dict['Own_map'])
|
| 386 |
]).astype(np.float16)
|
| 387 |
|
| 388 |
if site_var1 == 'Draftkings':
|
| 389 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] <= 50000].reset_index(drop=True)
|
| 390 |
RandomPortfolioDF = RandomPortfolioDF[RandomPortfolioDF['Salary'] >= (49500 - (5000 * (1 - (len(Teams_used) / 32)))) - (FieldStrength * 1000)].reset_index(drop=True)
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 393 |
|
| 394 |
+
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'User/Field', 'Salary', 'Projection', 'Own']]
|
| 395 |
|
| 396 |
return RandomPortfolio, maps_dict
|
| 397 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
static_exposure = pd.DataFrame(columns=['Player', 'count'])
|
| 399 |
overall_exposure = pd.DataFrame(columns=['Player', 'count'])
|
| 400 |
|
|
|
|
| 433 |
player_team_dict = dict(zip(proj_dataframe.Player, proj_dataframe.Team))
|
| 434 |
|
| 435 |
with col2:
|
| 436 |
+
st.info("The Portfolio file must contain only columns in order and explicitly named: 'QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', and 'DST'. Upload your projections first to avoid an error message.")
|
| 437 |
portfolio_file = st.file_uploader("Upload Portfolio File", key = 'portfolio_uploader')
|
| 438 |
|
| 439 |
if portfolio_file is not None:
|
|
|
|
| 445 |
|
| 446 |
try:
|
| 447 |
try:
|
| 448 |
+
portfolio_dataframe.columns=["QB", "RB1", "WR1", "WR2", "FLEX1", "FLEX2", "DST"]
|
| 449 |
split_portfolio = portfolio_dataframe
|
| 450 |
split_portfolio[['QB', 'QB_ID']] = split_portfolio.QB.str.split("(", n=1, expand = True)
|
| 451 |
split_portfolio[['RB1', 'RB1_ID']] = split_portfolio.RB1.str.split("(", n=1, expand = True)
|
|
|
|
| 452 |
split_portfolio[['WR1', 'WR1_ID']] = split_portfolio.WR1.str.split("(", n=1, expand = True)
|
| 453 |
split_portfolio[['WR2', 'WR2_ID']] = split_portfolio.WR2.str.split("(", n=1, expand = True)
|
| 454 |
+
split_portfolio[['FLEX1', 'FLEX1_ID']] = split_portfolio.FLEX1.str.split("(", n=1, expand = True)
|
| 455 |
+
split_portfolio[['FLEX2', 'FLEX2_ID']] = split_portfolio.FLEX2.str.split("(", n=1, expand = True)
|
|
|
|
| 456 |
split_portfolio[['DST', 'DST_ID']] = split_portfolio.DST.str.split("(", n=1, expand = True)
|
| 457 |
|
| 458 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 459 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
|
|
|
| 460 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 461 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 462 |
+
split_portfolio['FLEX1'] = split_portfolio['FLEX1'].str.strip()
|
| 463 |
+
split_portfolio['FLEX2'] = split_portfolio['FLEX2'].str.strip()
|
|
|
|
| 464 |
split_portfolio['DST'] = split_portfolio['DST'].str.strip()
|
| 465 |
|
| 466 |
st.table(split_portfolio.head(10))
|
| 467 |
|
| 468 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 469 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 470 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 471 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 472 |
+
split_portfolio['FLEX1'].map(player_salary_dict),
|
| 473 |
+
split_portfolio['FLEX2'].map(player_salary_dict),
|
|
|
|
| 474 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 475 |
|
| 476 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 477 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 478 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 479 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 480 |
+
split_portfolio['FLEX1'].map(player_proj_dict),
|
| 481 |
+
split_portfolio['FLEX2'].map(player_proj_dict),
|
|
|
|
| 482 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 483 |
|
| 484 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 485 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 486 |
split_portfolio['WR1'].map(player_own_dict),
|
| 487 |
split_portfolio['WR2'].map(player_own_dict),
|
| 488 |
+
split_portfolio['FLEX1'].map(player_own_dict),
|
| 489 |
+
split_portfolio['FLEX2'].map(player_own_dict),
|
|
|
|
| 490 |
split_portfolio['DST'].map(player_own_dict)])
|
| 491 |
|
| 492 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 493 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 494 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 495 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 496 |
+
split_portfolio['FLEX1_team'] = split_portfolio['FLEX1'].map(player_team_dict)
|
| 497 |
+
split_portfolio['FLEX2_team'] = split_portfolio['FLEX2'].map(player_team_dict)
|
|
|
|
| 498 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 499 |
|
| 500 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 501 |
+
'RB1_team', 'WR1_team', 'WR2_team', 'FLEX1_team', 'FLEX2_team', 'DST_team']]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
|
| 503 |
|
| 504 |
except:
|
| 505 |
+
portfolio_dataframe.columns=["QB", "RB1", "WR1", "WR2", "FLEX1", "FLEX2", "DST"]
|
| 506 |
|
| 507 |
split_portfolio = portfolio_dataframe
|
| 508 |
split_portfolio[['QB_ID', 'QB']] = split_portfolio.QB.str.split(":", n=1, expand = True)
|
| 509 |
split_portfolio[['RB1_ID', 'RB1']] = split_portfolio.RB1.str.split(":", n=1, expand = True)
|
|
|
|
| 510 |
split_portfolio[['WR1_ID', 'WR1']] = split_portfolio.WR1.str.split(":", n=1, expand = True)
|
| 511 |
split_portfolio[['WR2_ID', 'WR2']] = split_portfolio.WR2.str.split(":", n=1, expand = True)
|
| 512 |
+
split_portfolio[['FLEX1_ID', 'TE']] = split_portfolio.FLEX1.str.split(":", n=1, expand = True)
|
| 513 |
+
split_portfolio[['FLEX2_ID', 'FLEX']] = split_portfolio.FLEX2.str.split(":", n=1, expand = True)
|
|
|
|
| 514 |
split_portfolio[['DST_ID', 'DST']] = split_portfolio.DST.str.split(":", n=1, expand = True)
|
| 515 |
|
| 516 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 517 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
|
|
|
| 518 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 519 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 520 |
+
split_portfolio['FLEX1'] = split_portfolio['FLEX1'].str.strip()
|
| 521 |
+
split_portfolio['FLEX2'] = split_portfolio['FLEX2'].str.strip()
|
|
|
|
| 522 |
split_portfolio['DST'] = split_portfolio['DST'].str.strip()
|
| 523 |
|
| 524 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 525 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 526 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 527 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 528 |
+
split_portfolio['FLEX1'].map(player_salary_dict),
|
| 529 |
+
split_portfolio['FLEX2'].map(player_salary_dict),
|
|
|
|
| 530 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 531 |
|
| 532 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 533 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 534 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 535 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 536 |
+
split_portfolio['FLEX1'].map(player_proj_dict),
|
| 537 |
+
split_portfolio['FLEX2'].map(player_proj_dict),
|
|
|
|
| 538 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 539 |
|
| 540 |
st.table(split_portfolio.head(10))
|
| 541 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 542 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 543 |
split_portfolio['WR1'].map(player_own_dict),
|
| 544 |
split_portfolio['WR2'].map(player_own_dict),
|
| 545 |
+
split_portfolio['FLEX1'].map(player_own_dict),
|
| 546 |
+
split_portfolio['FLEX2'].map(player_own_dict),
|
|
|
|
| 547 |
split_portfolio['DST'].map(player_own_dict)])
|
| 548 |
|
| 549 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 550 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 551 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 552 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 553 |
+
split_portfolio['FLEX1_team'] = split_portfolio['FLEX1'].map(player_team_dict)
|
| 554 |
+
split_portfolio['FLEX2_team'] = split_portfolio['FLEX2'].map(player_team_dict)
|
|
|
|
| 555 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 556 |
|
| 557 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 558 |
+
'RB1_team', 'WR1_team', 'WR2_team', 'FLEX1_team', 'FLEX2_team', 'DST_team']]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
|
| 560 |
except:
|
| 561 |
split_portfolio = portfolio_dataframe
|
| 562 |
|
| 563 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 564 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 565 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 566 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 567 |
+
split_portfolio['FLEX1'].map(player_salary_dict),
|
| 568 |
+
split_portfolio['FLEX2'].map(player_salary_dict),
|
|
|
|
| 569 |
split_portfolio['DST'].map(player_salary_dict)])
|
| 570 |
|
| 571 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 572 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 573 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 574 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 575 |
+
split_portfolio['FLEX1'].map(player_proj_dict),
|
| 576 |
+
split_portfolio['FLEX2'].map(player_proj_dict),
|
|
|
|
| 577 |
split_portfolio['DST'].map(player_proj_dict)])
|
| 578 |
|
| 579 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 580 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 581 |
split_portfolio['WR1'].map(player_own_dict),
|
| 582 |
split_portfolio['WR2'].map(player_own_dict),
|
| 583 |
+
split_portfolio['FLEX1'].map(player_own_dict),
|
| 584 |
+
split_portfolio['FLEX2'].map(player_own_dict),
|
|
|
|
| 585 |
split_portfolio['DST'].map(player_own_dict)])
|
| 586 |
|
| 587 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 588 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 589 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 590 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 591 |
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 592 |
+
split_portfolio['FLEX1_team'] = split_portfolio['FLEX1'].map(player_team_dict)
|
| 593 |
+
split_portfolio['FLEX2_team'] = split_portfolio['FLEX2'].map(player_team_dict)
|
| 594 |
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 595 |
|
| 596 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 597 |
+
'RB1_team', 'WR1_team', 'WR2_team', 'FLEX1_team', 'FLEX2_team', 'DST_team']]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
|
| 599 |
+
for player_cols in split_portfolio.iloc[:, :7]:
|
| 600 |
static_col_raw = split_portfolio[player_cols].value_counts()
|
| 601 |
static_col = static_col_raw.to_frame()
|
| 602 |
static_col.reset_index(inplace=True)
|
|
|
|
| 615 |
col1, col2 = st.columns([3, 3])
|
| 616 |
|
| 617 |
if portfolio_file is not None:
|
| 618 |
+
split_portfolio = split_portfolio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
+
for player_cols in split_portfolio.iloc[:, :7]:
|
| 621 |
exposure_col_raw = split_portfolio[player_cols].value_counts()
|
| 622 |
exposure_col = exposure_col_raw.to_frame()
|
| 623 |
exposure_col.reset_index(inplace=True)
|
|
|
|
| 644 |
st.header('Portfolio View')
|
| 645 |
split_portfolio = split_portfolio.reset_index()
|
| 646 |
split_portfolio['Lineup'] = split_portfolio['index'] + 1
|
| 647 |
+
display_portfolio = split_portfolio[['Lineup', 'QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST', 'Salary', 'Projection', 'Ownership']]
|
| 648 |
display_portfolio = display_portfolio.set_index('Lineup')
|
| 649 |
st.dataframe(display_portfolio.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Ownership']).format(precision=2))
|
| 650 |
del split_portfolio
|
|
|
|
| 653 |
with tab2:
|
| 654 |
col1, col2 = st.columns([1, 7])
|
| 655 |
with col1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 656 |
|
| 657 |
+
slate_var1 = 'User'
|
| 658 |
+
site_var1 = 'Draftkings'
|
| 659 |
+
raw_baselines = proj_dataframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Median', 'Own']]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
st.info("If you are uploading a portfolio, note that there is an adjustments to projections and deviation mapping to prevent 'Projection Bias' and create a fair simulation")
|
| 661 |
insert_port1 = st.selectbox("Are you uploading a portfolio?", ('No', 'Yes'), key='insert_port1')
|
| 662 |
if insert_port1 == 'Yes':
|
|
|
|
| 728 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (10 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 729 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 730 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 731 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (700 / OwnFrame['Own%'].sum())
|
| 732 |
if contest_var1 == 'Medium':
|
| 733 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (6 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 734 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 735 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 736 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (700 / OwnFrame['Own%'].sum())
|
| 737 |
if contest_var1 == 'Large':
|
| 738 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] == 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (3 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] == 'QB', 'Own'].mean(), OwnFrame['Own'])
|
| 739 |
OwnFrame['Own%'] = np.where((OwnFrame['Position'] != 'QB') & (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean() >= 0), OwnFrame['Own'] * (1.5 * (OwnFrame['Own'] - OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean())/100) + OwnFrame.loc[OwnFrame['Position'] != 'QB', 'Own'].mean(), OwnFrame['Own%'])
|
| 740 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 741 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (700 / OwnFrame['Own%'].sum())
|
| 742 |
Overall_Proj = OwnFrame[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
| 743 |
|
| 744 |
del OwnFrame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
|
| 746 |
if insert_port == 1:
|
| 747 |
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']]
|
|
|
|
| 811 |
wrs_raw.dropna(subset=['Median']).reset_index(drop=True)
|
| 812 |
wrs_raw = wrs_raw.reset_index(drop=True)
|
| 813 |
wrs_raw = wrs_raw.sort_values(by=['Own', 'Median'], ascending=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
|
| 815 |
+
pos_players = pd.concat([rbs_raw, wrs_raw])
|
| 816 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
| 817 |
pos_players = pos_players.reset_index(drop=True)
|
| 818 |
|
|
|
|
| 820 |
del defs_raw
|
| 821 |
del rbs_raw
|
| 822 |
del wrs_raw
|
|
|
|
| 823 |
|
| 824 |
if insert_port == 1:
|
| 825 |
try:
|
|
|
|
| 827 |
Raw_Portfolio = pd.DataFrame()
|
| 828 |
|
| 829 |
# Loop through each position and split the data accordingly
|
| 830 |
+
positions = ['QB', 'RB1', 'WR1', 'WR2', 'FLEX1', 'FLEX2', 'DST']
|
| 831 |
for pos in positions:
|
| 832 |
temp_df = UserPortfolio[pos].str.split("(", n=1, expand=True)
|
| 833 |
temp_df.columns = [pos, 'Drop']
|
|
|
|
| 844 |
|
| 845 |
# Create frequency table for players
|
| 846 |
cleaport_players = pd.DataFrame(
|
| 847 |
+
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:7].values, return_counts=True)),
|
| 848 |
columns=['Player', 'Freq']
|
| 849 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 850 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
|
|
| 865 |
|
| 866 |
# Create frequency table for players
|
| 867 |
cleaport_players = pd.DataFrame(
|
| 868 |
+
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:7].values, return_counts=True)),
|
| 869 |
columns=['Player', 'Freq']
|
| 870 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 871 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
|
|
| 877 |
|
| 878 |
elif insert_port == 0:
|
| 879 |
CleanPortfolio = UserPortfolio
|
| 880 |
+
cleaport_players = pd.DataFrame(np.column_stack(np.unique(CleanPortfolio.iloc[:,0:7].values, return_counts=True)),
|
| 881 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 882 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
| 883 |
nerf_frame = Overall_Proj
|
| 884 |
|
| 885 |
ref_dict = {
|
| 886 |
+
'pos':['RB', 'WR', 'FLEX'],
|
| 887 |
+
'pos_dfs':['RB_Table', 'WR_Table', 'FLEX_Table'],
|
| 888 |
+
'pos_dicts':['rb_dict', 'wr_dict', 'flex_dict']
|
| 889 |
}
|
| 890 |
|
| 891 |
maps_dict = {
|
|
|
|
| 963 |
else:
|
| 964 |
sample_arrays = sample_arrays1
|
| 965 |
|
| 966 |
+
final_array = sample_arrays[sample_arrays[:, 8].argsort()[::-1]]
|
| 967 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
| 968 |
Sim_Winners.append(best_lineup)
|
| 969 |
SimVar += 1
|
|
|
|
| 992 |
# Conditional Replacement
|
| 993 |
columns_to_replace = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'TE', 'FLEX', 'DST']
|
| 994 |
|
| 995 |
+
player_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,0:7].values, return_counts=True)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 997 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 998 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1020 |
|
| 1021 |
qb_freq = qb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1022 |
|
| 1023 |
+
rb_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,1:2].values, return_counts=True)),
|
| 1024 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1025 |
rb_freq['Freq'] = rb_freq['Freq'].astype(int)
|
| 1026 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1034 |
|
| 1035 |
rb_freq = rb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1036 |
|
| 1037 |
+
wr_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[2, 3]].values, return_counts=True)),
|
| 1038 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1039 |
wr_freq['Freq'] = wr_freq['Freq'].astype(int)
|
| 1040 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1048 |
|
| 1049 |
wr_freq = wr_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1050 |
|
| 1051 |
+
flex_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[4, 5]].values, return_counts=True)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1052 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1053 |
flex_freq['Freq'] = flex_freq['Freq'].astype(int)
|
| 1054 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1062 |
|
| 1063 |
flex_freq = flex_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1064 |
|
| 1065 |
+
dst_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,5:6].values, return_counts=True)),
|
| 1066 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1067 |
dst_freq['Freq'] = dst_freq['Freq'].astype(int)
|
| 1068 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1089 |
|
| 1090 |
with st.container():
|
| 1091 |
freq_container = st.empty()
|
| 1092 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB Exposures', 'WR Exposures', 'FLEX Exposures', 'DST Exposures'])
|
| 1093 |
with tab1:
|
| 1094 |
st.dataframe(player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1095 |
st.download_button(
|
|
|
|
| 1123 |
mime='text/csv',
|
| 1124 |
)
|
| 1125 |
with tab5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1126 |
st.dataframe(flex_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1127 |
st.download_button(
|
| 1128 |
label="Export Exposures",
|
|
|
|
| 1130 |
file_name='flex_freq_export.csv',
|
| 1131 |
mime='text/csv',
|
| 1132 |
)
|
| 1133 |
+
with tab6:
|
| 1134 |
st.dataframe(dst_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1135 |
st.download_button(
|
| 1136 |
label="Export Exposures",
|