Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -116,8 +116,17 @@ def create_stack_options(player_data, wr_var):
|
|
| 116 |
|
| 117 |
return correl_dict
|
| 118 |
|
| 119 |
-
def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
| 120 |
-
if pos == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
pos_players = pos_players.sort_values(by='Value', ascending=False)
|
| 122 |
table_name_raw = pos_players.reset_index(drop=True)
|
| 123 |
overall_table_name = table_name_raw.head(round(len(table_name_raw)))
|
|
@@ -126,6 +135,7 @@ def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
|
| 126 |
|
| 127 |
del pos_players
|
| 128 |
del table_name_raw
|
|
|
|
| 129 |
elif pos != "FLEX":
|
| 130 |
table_name_raw = pos_players[pos_players['Position'].str.contains(pos)].reset_index(drop=True)
|
| 131 |
overall_table_name = table_name_raw.head(round(len(table_name_raw)))
|
|
@@ -140,14 +150,14 @@ def create_overall_dfs(pos_players, table_name, dict_name, pos):
|
|
| 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,
|
| 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 |
|
| 152 |
df_out = pd.concat(ref_dict['pos_dfs'], ignore_index=True)
|
| 153 |
|
|
@@ -168,29 +178,26 @@ def create_random_portfolio(Total_Sample_Size, raw_baselines):
|
|
| 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:
|
| 175 |
ranges_dict['qb_range'] = round(max_var)
|
| 176 |
-
ranges_dict['dst_range'] = round(max_var)
|
| 177 |
elif max_var > 10 and max_var <= 16:
|
| 178 |
ranges_dict['qb_range'] = round(max_var / 1.5)
|
| 179 |
-
ranges_dict['dst_range'] = round(max_var)
|
| 180 |
elif max_var > 16:
|
| 181 |
ranges_dict['qb_range'] = round(max_var / 2)
|
| 182 |
-
ranges_dict['dst_range'] = round(max_var)
|
| 183 |
# Generate unique ranges
|
| 184 |
# for key, value in ranges_dict.items():
|
| 185 |
# ranges_dict[f"{key}_Uniques"] = list(range(0, value, 1))
|
| 186 |
|
| 187 |
# Generate random portfolios
|
| 188 |
rng = np.random.default_rng()
|
| 189 |
-
total_elements = [1,
|
| 190 |
-
keys = ['qb', 'rb', 'wr', 'flex', '
|
| 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', '
|
| 194 |
RandomPortfolio['User/Field'] = 0
|
| 195 |
|
| 196 |
del O_merge
|
|
@@ -207,14 +214,15 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 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['
|
| 213 |
-
RandomPortfolio['
|
| 214 |
-
RandomPortfolio['
|
| 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'] ==
|
| 218 |
reset_index(drop=True)
|
| 219 |
|
| 220 |
del sizesplit
|
|
@@ -225,38 +233,41 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 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['
|
| 231 |
-
RandomPortfolio['
|
| 232 |
-
RandomPortfolio['
|
| 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['
|
| 239 |
-
RandomPortfolio['
|
| 240 |
-
RandomPortfolio['
|
| 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['
|
| 247 |
-
RandomPortfolio['
|
| 248 |
-
RandomPortfolio['
|
| 249 |
|
| 250 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 251 |
del RandomPortfolio
|
| 252 |
|
| 253 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 254 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 255 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 256 |
# st.write(RandomPortArray[:,:100])
|
| 257 |
-
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[
|
| 258 |
# st.write(RandomPortArrayOut[:,:100])
|
| 259 |
-
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'WR1', 'WR2', '
|
| 260 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 261 |
del RandomPortArray
|
| 262 |
del RandomPortArrayOut
|
|
@@ -264,29 +275,32 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 264 |
if insert_port == 1:
|
| 265 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 266 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
|
|
|
| 267 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 268 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 269 |
-
CleanPortfolio['
|
| 270 |
-
CleanPortfolio['
|
| 271 |
-
CleanPortfolio['
|
| 272 |
]).astype(np.int16)
|
| 273 |
if insert_port == 1:
|
| 274 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 275 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
|
|
|
| 276 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 277 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 278 |
-
CleanPortfolio['
|
| 279 |
-
CleanPortfolio['
|
| 280 |
-
CleanPortfolio['
|
| 281 |
]).astype(np.float16)
|
| 282 |
if insert_port == 1:
|
| 283 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 284 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
|
|
|
| 285 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 286 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 287 |
-
CleanPortfolio['
|
| 288 |
-
CleanPortfolio['
|
| 289 |
-
CleanPortfolio['
|
| 290 |
]).astype(np.float16)
|
| 291 |
|
| 292 |
if site_var1 == 'Draftkings':
|
|
@@ -295,7 +309,7 @@ def get_correlated_portfolio_for_sim(Total_Sample_Size):
|
|
| 295 |
|
| 296 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 297 |
|
| 298 |
-
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'WR1', 'WR2', '
|
| 299 |
|
| 300 |
return RandomPortfolio, maps_dict
|
| 301 |
|
|
@@ -307,54 +321,58 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
|
| 307 |
|
| 308 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 309 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
|
|
|
| 310 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['WR1'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 311 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 312 |
-
RandomPortfolio['
|
| 313 |
-
RandomPortfolio['
|
| 314 |
-
RandomPortfolio['
|
| 315 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 316 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 317 |
-
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] ==
|
| 318 |
reset_index(drop=True)
|
| 319 |
|
| 320 |
del sizesplit
|
| 321 |
del full_pos_player_dict
|
| 322 |
-
del ranges_dict
|
| 323 |
|
| 324 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 325 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
|
|
|
| 326 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 327 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 328 |
-
RandomPortfolio['
|
| 329 |
-
RandomPortfolio['
|
| 330 |
-
RandomPortfolio['
|
| 331 |
|
| 332 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 333 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
|
|
|
| 334 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 335 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 336 |
-
RandomPortfolio['
|
| 337 |
-
RandomPortfolio['
|
| 338 |
-
RandomPortfolio['
|
| 339 |
|
| 340 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 341 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
|
|
|
| 342 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 343 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 344 |
-
RandomPortfolio['
|
| 345 |
-
RandomPortfolio['
|
| 346 |
-
RandomPortfolio['
|
| 347 |
|
| 348 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 349 |
del RandomPortfolio
|
| 350 |
|
| 351 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 352 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 353 |
-
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,
|
| 354 |
# st.write(RandomPortArray[:,:100])
|
| 355 |
-
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[
|
| 356 |
# st.write(RandomPortArrayOut[:,:100])
|
| 357 |
-
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'WR1', 'WR2', '
|
| 358 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 359 |
del RandomPortArray
|
| 360 |
del RandomPortArrayOut
|
|
@@ -362,29 +380,32 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
|
| 362 |
if insert_port == 1:
|
| 363 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 364 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
|
|
|
| 365 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 366 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 367 |
-
CleanPortfolio['
|
| 368 |
-
CleanPortfolio['
|
| 369 |
-
CleanPortfolio['
|
| 370 |
]).astype(np.int16)
|
| 371 |
if insert_port == 1:
|
| 372 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 373 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
|
|
|
| 374 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 375 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 376 |
-
CleanPortfolio['
|
| 377 |
-
CleanPortfolio['
|
| 378 |
-
CleanPortfolio['
|
| 379 |
]).astype(np.float16)
|
| 380 |
if insert_port == 1:
|
| 381 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 382 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
|
|
|
| 383 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 384 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 385 |
-
CleanPortfolio['
|
| 386 |
-
CleanPortfolio['
|
| 387 |
-
CleanPortfolio['
|
| 388 |
]).astype(np.float16)
|
| 389 |
|
| 390 |
if site_var1 == 'Draftkings':
|
|
@@ -393,7 +414,7 @@ def get_uncorrelated_portfolio_for_sim(Total_Sample_Size):
|
|
| 393 |
|
| 394 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 395 |
|
| 396 |
-
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'WR1', 'WR2', '
|
| 397 |
|
| 398 |
return RandomPortfolio, maps_dict
|
| 399 |
|
|
@@ -435,7 +456,7 @@ with tab1:
|
|
| 435 |
player_team_dict = dict(zip(proj_dataframe.Player, proj_dataframe.Team))
|
| 436 |
|
| 437 |
with col2:
|
| 438 |
-
st.info("The Portfolio file must contain only columns in order and explicitly named: 'QB', 'RB1', 'WR1', 'WR2', '
|
| 439 |
portfolio_file = st.file_uploader("Upload Portfolio File", key = 'portfolio_uploader')
|
| 440 |
|
| 441 |
if portfolio_file is not None:
|
|
@@ -447,158 +468,173 @@ with tab1:
|
|
| 447 |
|
| 448 |
try:
|
| 449 |
try:
|
| 450 |
-
portfolio_dataframe.columns=["QB", "RB1", "WR1", "WR2", "
|
| 451 |
split_portfolio = portfolio_dataframe
|
| 452 |
split_portfolio[['QB', 'QB_ID']] = split_portfolio.QB.str.split("(", n=1, expand = True)
|
| 453 |
split_portfolio[['RB1', 'RB1_ID']] = split_portfolio.RB1.str.split("(", n=1, expand = True)
|
|
|
|
| 454 |
split_portfolio[['WR1', 'WR1_ID']] = split_portfolio.WR1.str.split("(", n=1, expand = True)
|
| 455 |
split_portfolio[['WR2', 'WR2_ID']] = split_portfolio.WR2.str.split("(", n=1, expand = True)
|
| 456 |
-
split_portfolio[['
|
| 457 |
-
split_portfolio[['
|
| 458 |
-
split_portfolio[['
|
| 459 |
|
| 460 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 461 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
|
|
|
| 462 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 463 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 464 |
-
split_portfolio['
|
| 465 |
-
split_portfolio['
|
| 466 |
-
split_portfolio['
|
| 467 |
|
| 468 |
st.table(split_portfolio.head(10))
|
| 469 |
|
| 470 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 471 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 472 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 473 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 474 |
-
split_portfolio['
|
| 475 |
-
split_portfolio['
|
| 476 |
-
split_portfolio['
|
| 477 |
|
| 478 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 479 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 480 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 481 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 482 |
-
split_portfolio['
|
| 483 |
-
split_portfolio['
|
| 484 |
-
split_portfolio['
|
| 485 |
|
| 486 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 487 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 488 |
split_portfolio['WR1'].map(player_own_dict),
|
| 489 |
split_portfolio['WR2'].map(player_own_dict),
|
| 490 |
-
split_portfolio['
|
| 491 |
-
split_portfolio['
|
| 492 |
-
split_portfolio['
|
| 493 |
|
| 494 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 495 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 496 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 497 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 498 |
-
split_portfolio['
|
| 499 |
-
split_portfolio['
|
| 500 |
-
split_portfolio['
|
| 501 |
|
| 502 |
-
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', '
|
| 503 |
-
'RB1_team', 'WR1_team', 'WR2_team', '
|
| 504 |
|
| 505 |
|
| 506 |
except:
|
| 507 |
-
portfolio_dataframe.columns=["QB", "RB1", "WR1", "WR2", "
|
| 508 |
|
| 509 |
split_portfolio = portfolio_dataframe
|
| 510 |
split_portfolio[['QB_ID', 'QB']] = split_portfolio.QB.str.split(":", n=1, expand = True)
|
| 511 |
split_portfolio[['RB1_ID', 'RB1']] = split_portfolio.RB1.str.split(":", n=1, expand = True)
|
|
|
|
| 512 |
split_portfolio[['WR1_ID', 'WR1']] = split_portfolio.WR1.str.split(":", n=1, expand = True)
|
| 513 |
split_portfolio[['WR2_ID', 'WR2']] = split_portfolio.WR2.str.split(":", n=1, expand = True)
|
| 514 |
-
split_portfolio[['
|
| 515 |
-
split_portfolio[['
|
| 516 |
-
split_portfolio[['
|
| 517 |
|
| 518 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 519 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
|
|
|
| 520 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 521 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 522 |
-
split_portfolio['
|
| 523 |
-
split_portfolio['
|
| 524 |
-
split_portfolio['
|
| 525 |
|
| 526 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 527 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 528 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 529 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 530 |
-
split_portfolio['
|
| 531 |
-
split_portfolio['
|
| 532 |
-
split_portfolio['
|
| 533 |
|
| 534 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 535 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 536 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 537 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 538 |
-
split_portfolio['
|
| 539 |
-
split_portfolio['
|
| 540 |
-
split_portfolio['
|
| 541 |
|
| 542 |
st.table(split_portfolio.head(10))
|
| 543 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 544 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 545 |
split_portfolio['WR1'].map(player_own_dict),
|
| 546 |
split_portfolio['WR2'].map(player_own_dict),
|
| 547 |
-
split_portfolio['
|
| 548 |
-
split_portfolio['
|
| 549 |
-
split_portfolio['
|
| 550 |
|
| 551 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 552 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 553 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 554 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 555 |
-
split_portfolio['
|
| 556 |
-
split_portfolio['
|
| 557 |
-
split_portfolio['
|
| 558 |
|
| 559 |
-
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', '
|
| 560 |
-
'RB1_team', 'WR1_team', 'WR2_team', '
|
| 561 |
|
| 562 |
except:
|
| 563 |
split_portfolio = portfolio_dataframe
|
| 564 |
|
| 565 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 566 |
split_portfolio['RB1'].map(player_salary_dict),
|
|
|
|
| 567 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 568 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 569 |
-
split_portfolio['
|
| 570 |
-
split_portfolio['
|
| 571 |
-
split_portfolio['
|
| 572 |
|
| 573 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 574 |
split_portfolio['RB1'].map(player_proj_dict),
|
|
|
|
| 575 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 576 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 577 |
-
split_portfolio['
|
| 578 |
-
split_portfolio['
|
| 579 |
-
split_portfolio['
|
| 580 |
|
| 581 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 582 |
split_portfolio['RB1'].map(player_own_dict),
|
|
|
|
| 583 |
split_portfolio['WR1'].map(player_own_dict),
|
| 584 |
split_portfolio['WR2'].map(player_own_dict),
|
| 585 |
-
split_portfolio['
|
| 586 |
-
split_portfolio['
|
| 587 |
-
split_portfolio['
|
| 588 |
|
| 589 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 590 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
|
|
|
| 591 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 592 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 593 |
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 594 |
-
split_portfolio['
|
| 595 |
-
split_portfolio['
|
| 596 |
-
split_portfolio['DST_team'] = split_portfolio['DST'].map(player_team_dict)
|
| 597 |
|
| 598 |
-
split_portfolio = split_portfolio[['QB', 'RB1', 'WR1', 'WR2', '
|
| 599 |
-
'RB1_team', 'WR1_team', 'WR2_team', '
|
| 600 |
|
| 601 |
-
for player_cols in split_portfolio.iloc[:, :
|
| 602 |
static_col_raw = split_portfolio[player_cols].value_counts()
|
| 603 |
static_col = static_col_raw.to_frame()
|
| 604 |
static_col.reset_index(inplace=True)
|
|
@@ -619,7 +655,7 @@ with tab1:
|
|
| 619 |
if portfolio_file is not None:
|
| 620 |
split_portfolio = split_portfolio
|
| 621 |
|
| 622 |
-
for player_cols in split_portfolio.iloc[:, :
|
| 623 |
exposure_col_raw = split_portfolio[player_cols].value_counts()
|
| 624 |
exposure_col = exposure_col_raw.to_frame()
|
| 625 |
exposure_col.reset_index(inplace=True)
|
|
@@ -646,7 +682,7 @@ with tab1:
|
|
| 646 |
st.header('Portfolio View')
|
| 647 |
split_portfolio = split_portfolio.reset_index()
|
| 648 |
split_portfolio['Lineup'] = split_portfolio['index'] + 1
|
| 649 |
-
display_portfolio = split_portfolio[['Lineup', 'QB', 'RB1', 'WR1', 'WR2', '
|
| 650 |
display_portfolio = display_portfolio.set_index('Lineup')
|
| 651 |
st.dataframe(display_portfolio.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Ownership']).format(precision=2))
|
| 652 |
del split_portfolio
|
|
@@ -731,25 +767,25 @@ with tab2:
|
|
| 731 |
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'])
|
| 732 |
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%'])
|
| 733 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 734 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 735 |
if contest_var1 == 'Medium':
|
| 736 |
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'])
|
| 737 |
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%'])
|
| 738 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 739 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 740 |
if contest_var1 == 'Large':
|
| 741 |
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'])
|
| 742 |
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%'])
|
| 743 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 744 |
-
OwnFrame['Own'] = OwnFrame['Own%'] * (
|
| 745 |
Overall_Proj = OwnFrame[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
| 746 |
|
| 747 |
del OwnFrame
|
| 748 |
|
| 749 |
if insert_port == 1:
|
| 750 |
-
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', '
|
| 751 |
elif insert_port == 0:
|
| 752 |
-
UserPortfolio = pd.DataFrame(columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', '
|
| 753 |
|
| 754 |
Overall_Proj.replace('', np.nan, inplace=True)
|
| 755 |
Overall_Proj = Overall_Proj.dropna(subset=['Median'])
|
|
@@ -819,6 +855,10 @@ with tab2:
|
|
| 819 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
| 820 |
pos_players = pos_players.reset_index(drop=True)
|
| 821 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
del qbs_raw
|
| 823 |
del defs_raw
|
| 824 |
del rbs_raw
|
|
@@ -830,7 +870,7 @@ with tab2:
|
|
| 830 |
Raw_Portfolio = pd.DataFrame()
|
| 831 |
|
| 832 |
# Loop through each position and split the data accordingly
|
| 833 |
-
positions = ['QB', 'RB1', 'WR1', 'WR2', '
|
| 834 |
for pos in positions:
|
| 835 |
temp_df = UserPortfolio[pos].str.split("(", n=1, expand=True)
|
| 836 |
temp_df.columns = [pos, 'Drop']
|
|
@@ -847,7 +887,7 @@ with tab2:
|
|
| 847 |
|
| 848 |
# Create frequency table for players
|
| 849 |
cleaport_players = pd.DataFrame(
|
| 850 |
-
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:
|
| 851 |
columns=['Player', 'Freq']
|
| 852 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 853 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
@@ -868,7 +908,7 @@ with tab2:
|
|
| 868 |
|
| 869 |
# Create frequency table for players
|
| 870 |
cleaport_players = pd.DataFrame(
|
| 871 |
-
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:
|
| 872 |
columns=['Player', 'Freq']
|
| 873 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 874 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
@@ -880,15 +920,15 @@ with tab2:
|
|
| 880 |
|
| 881 |
elif insert_port == 0:
|
| 882 |
CleanPortfolio = UserPortfolio
|
| 883 |
-
cleaport_players = pd.DataFrame(np.column_stack(np.unique(CleanPortfolio.iloc[:,0:
|
| 884 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 885 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
| 886 |
nerf_frame = Overall_Proj
|
| 887 |
|
| 888 |
ref_dict = {
|
| 889 |
-
'pos':['RB', 'WR', 'FLEX'],
|
| 890 |
-
'pos_dfs':['RB_Table', 'WR_Table', 'FLEX_Table'],
|
| 891 |
-
'pos_dicts':['rb_dict', 'wr_dict', 'flex_dict']
|
| 892 |
}
|
| 893 |
|
| 894 |
maps_dict = {
|
|
@@ -966,7 +1006,7 @@ with tab2:
|
|
| 966 |
else:
|
| 967 |
sample_arrays = sample_arrays1
|
| 968 |
|
| 969 |
-
final_array = sample_arrays[sample_arrays[:,
|
| 970 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
| 971 |
Sim_Winners.append(best_lineup)
|
| 972 |
SimVar += 1
|
|
@@ -993,9 +1033,9 @@ with tab2:
|
|
| 993 |
Sim_Winner_Export = Sim_Winner_Frame.copy()
|
| 994 |
|
| 995 |
# Conditional Replacement
|
| 996 |
-
columns_to_replace = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', '
|
| 997 |
|
| 998 |
-
player_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,0:
|
| 999 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1000 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 1001 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1023,7 +1063,7 @@ with tab2:
|
|
| 1023 |
|
| 1024 |
qb_freq = qb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1025 |
|
| 1026 |
-
rb_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,1:
|
| 1027 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1028 |
rb_freq['Freq'] = rb_freq['Freq'].astype(int)
|
| 1029 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1037,7 +1077,7 @@ with tab2:
|
|
| 1037 |
|
| 1038 |
rb_freq = rb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1039 |
|
| 1040 |
-
wr_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[
|
| 1041 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1042 |
wr_freq['Freq'] = wr_freq['Freq'].astype(int)
|
| 1043 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1051,7 +1091,7 @@ with tab2:
|
|
| 1051 |
|
| 1052 |
wr_freq = wr_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1053 |
|
| 1054 |
-
flex_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,
|
| 1055 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1056 |
flex_freq['Freq'] = flex_freq['Freq'].astype(int)
|
| 1057 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1065,7 +1105,7 @@ with tab2:
|
|
| 1065 |
|
| 1066 |
flex_freq = flex_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1067 |
|
| 1068 |
-
dst_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,
|
| 1069 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1070 |
dst_freq['Freq'] = dst_freq['Freq'].astype(int)
|
| 1071 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
|
@@ -1092,7 +1132,7 @@ with tab2:
|
|
| 1092 |
|
| 1093 |
with st.container():
|
| 1094 |
freq_container = st.empty()
|
| 1095 |
-
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB Exposures', 'WR Exposures', 'FLEX Exposures', '
|
| 1096 |
with tab1:
|
| 1097 |
st.dataframe(player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1098 |
st.download_button(
|
|
@@ -1138,6 +1178,6 @@ with tab2:
|
|
| 1138 |
st.download_button(
|
| 1139 |
label="Export Exposures",
|
| 1140 |
data=convert_df_to_csv(dst_freq),
|
| 1141 |
-
file_name='
|
| 1142 |
mime='text/csv',
|
| 1143 |
)
|
|
|
|
| 116 |
|
| 117 |
return correl_dict
|
| 118 |
|
| 119 |
+
def create_overall_dfs(s_pos_players, pos_players, table_name, dict_name, pos):
|
| 120 |
+
if pos == "S_FLEX":
|
| 121 |
+
table_name_raw = s_pos_players.reset_index(drop=True)
|
| 122 |
+
overall_table_name = table_name_raw.head(round(len(table_name_raw)))
|
| 123 |
+
overall_table_name = overall_table_name.assign(Var = range(0,len(overall_table_name)))
|
| 124 |
+
overall_dict_name = pd.Series(overall_table_name.Player.values, index=overall_table_name.Var).to_dict()
|
| 125 |
+
|
| 126 |
+
del pos_players
|
| 127 |
+
del table_name_raw
|
| 128 |
+
|
| 129 |
+
elif pos == "FLEX":
|
| 130 |
pos_players = pos_players.sort_values(by='Value', ascending=False)
|
| 131 |
table_name_raw = pos_players.reset_index(drop=True)
|
| 132 |
overall_table_name = table_name_raw.head(round(len(table_name_raw)))
|
|
|
|
| 135 |
|
| 136 |
del pos_players
|
| 137 |
del table_name_raw
|
| 138 |
+
|
| 139 |
elif pos != "FLEX":
|
| 140 |
table_name_raw = pos_players[pos_players['Position'].str.contains(pos)].reset_index(drop=True)
|
| 141 |
overall_table_name = table_name_raw.head(round(len(table_name_raw)))
|
|
|
|
| 150 |
|
| 151 |
def get_overall_merged_df():
|
| 152 |
ref_dict = {
|
| 153 |
+
'pos':['RB', 'WR', 'FLEX', 'S_FLEX'],
|
| 154 |
+
'pos_dfs':['RB_Table', 'WR_Table', 'FLEX_Table', 'S_FLEX_Table'],
|
| 155 |
+
'pos_dicts':['rb_dict', 'wr_dict', 'flex_dict', 's_flex_dict']
|
| 156 |
}
|
| 157 |
|
| 158 |
+
for i in range(0,4):
|
| 159 |
ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i] =\
|
| 160 |
+
create_overall_dfs(s_pos_players, pos_players, ref_dict['pos_dfs'][i], ref_dict['pos_dicts'][i], ref_dict['pos'][i])
|
| 161 |
|
| 162 |
df_out = pd.concat(ref_dict['pos_dfs'], ignore_index=True)
|
| 163 |
|
|
|
|
| 178 |
ranges_dict = {}
|
| 179 |
|
| 180 |
# Calculate ranges
|
| 181 |
+
for df, dict_val, min_val, key in zip(ref_dict['pos_dfs'], ref_dict['pos_dicts'], [10, 20, 30, 30], ['RB', 'WR', 'FLEX', 'S_FLEX']):
|
| 182 |
+
count = create_overall_dfs(s_pos_players, pos_players, df, dict_val, key)
|
| 183 |
ranges_dict[f"{key.lower()}_range"] = calculate_range_var(count, min_val, FieldStrength, field_growth_rounded)
|
| 184 |
if max_var <= 10:
|
| 185 |
ranges_dict['qb_range'] = round(max_var)
|
|
|
|
| 186 |
elif max_var > 10 and max_var <= 16:
|
| 187 |
ranges_dict['qb_range'] = round(max_var / 1.5)
|
|
|
|
| 188 |
elif max_var > 16:
|
| 189 |
ranges_dict['qb_range'] = round(max_var / 2)
|
|
|
|
| 190 |
# Generate unique ranges
|
| 191 |
# for key, value in ranges_dict.items():
|
| 192 |
# ranges_dict[f"{key}_Uniques"] = list(range(0, value, 1))
|
| 193 |
|
| 194 |
# Generate random portfolios
|
| 195 |
rng = np.random.default_rng()
|
| 196 |
+
total_elements = [1, 2, 3, 1, 1]
|
| 197 |
+
keys = ['qb', 'rb', 'wr', 'flex', 's_flex']
|
| 198 |
|
| 199 |
all_choices = [rng.choice(ranges_dict[f"{key}_range"], size=(Total_Sample_Size, elem)) for key, elem in zip(keys, total_elements)]
|
| 200 |
+
RandomPortfolio = pd.DataFrame(np.hstack(all_choices), columns=['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX'])
|
| 201 |
RandomPortfolio['User/Field'] = 0
|
| 202 |
|
| 203 |
del O_merge
|
|
|
|
| 214 |
|
| 215 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 216 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 217 |
+
RandomPortfolio['RB2'] = pd.Series(list(RandomPortfolio['RB2'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 218 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['QB'].map(stacking_dict)), dtype="string[pyarrow]")
|
| 219 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 220 |
+
RandomPortfolio['WR3'] = pd.Series(list(RandomPortfolio['WR3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 221 |
+
RandomPortfolio['FLEX'] = pd.Series(list(RandomPortfolio['FLEX'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
| 222 |
+
RandomPortfolio['S_FLEX'] = pd.Series(list(RandomPortfolio['S_FLEX'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
| 223 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 224 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 225 |
+
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 9].drop(columns=['plyr_list','plyr_count']).\
|
| 226 |
reset_index(drop=True)
|
| 227 |
|
| 228 |
del sizesplit
|
|
|
|
| 233 |
|
| 234 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 235 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 236 |
+
RandomPortfolio['RB2s'] = RandomPortfolio['RB2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 237 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 238 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 239 |
+
RandomPortfolio['WR3s'] = RandomPortfolio['WR3'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 240 |
+
RandomPortfolio['FLEXs'] = RandomPortfolio['FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 241 |
+
RandomPortfolio['S_FLEXs'] = RandomPortfolio['S_FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 242 |
|
| 243 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 244 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 245 |
+
RandomPortfolio['RB2p'] = RandomPortfolio['RB2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 246 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 247 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 248 |
+
RandomPortfolio['WR3p'] = RandomPortfolio['WR3'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 249 |
+
RandomPortfolio['FLEXp'] = RandomPortfolio['FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 250 |
+
RandomPortfolio['S_FLEXp'] = RandomPortfolio['S_FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 251 |
|
| 252 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 253 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 254 |
+
RandomPortfolio['RB2o'] = RandomPortfolio['RB2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 255 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 256 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 257 |
+
RandomPortfolio['WR3o'] = RandomPortfolio['WR3'].map(maps_dict['Own_map']).astype(np.float16)
|
| 258 |
+
RandomPortfolio['FLEXo'] = RandomPortfolio['FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 259 |
+
RandomPortfolio['S_FLEXo'] = RandomPortfolio['S_FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 260 |
|
| 261 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 262 |
del RandomPortfolio
|
| 263 |
|
| 264 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,9:17].astype(int))]
|
| 265 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,17:25].astype(np.double))]
|
| 266 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,25:33].astype(np.double))]
|
| 267 |
# st.write(RandomPortArray[:,:100])
|
| 268 |
+
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[9:33], axis=1)
|
| 269 |
# st.write(RandomPortArrayOut[:,:100])
|
| 270 |
+
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'User/Field', 'Salary', 'Projection', 'Own'])
|
| 271 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 272 |
del RandomPortArray
|
| 273 |
del RandomPortArrayOut
|
|
|
|
| 275 |
if insert_port == 1:
|
| 276 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 277 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
| 278 |
+
CleanPortfolio['RB2'].map(maps_dict['Salary_map']),
|
| 279 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 280 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 281 |
+
CleanPortfolio['WR3'].map(maps_dict['Salary_map']),
|
| 282 |
+
CleanPortfolio['FLEX'].map(maps_dict['Salary_map']),
|
| 283 |
+
CleanPortfolio['S_FLEX'].map(maps_dict['Salary_map'])
|
| 284 |
]).astype(np.int16)
|
| 285 |
if insert_port == 1:
|
| 286 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 287 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
| 288 |
+
CleanPortfolio['RB2'].map(up_dict['Projection_map']),
|
| 289 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 290 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 291 |
+
CleanPortfolio['WR3'].map(up_dict['Projection_map']),
|
| 292 |
+
CleanPortfolio['FLEX'].map(up_dict['Projection_map']),
|
| 293 |
+
CleanPortfolio['S_FLEX'].map(up_dict['Projection_map'])
|
| 294 |
]).astype(np.float16)
|
| 295 |
if insert_port == 1:
|
| 296 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 297 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
| 298 |
+
CleanPortfolio['RB2'].map(maps_dict['Own_map']),
|
| 299 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 300 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 301 |
+
CleanPortfolio['WR3'].map(maps_dict['Own_map']),
|
| 302 |
+
CleanPortfolio['FLEX'].map(maps_dict['Own_map']),
|
| 303 |
+
CleanPortfolio['S_FLEX'].map(maps_dict['Own_map'])
|
| 304 |
]).astype(np.float16)
|
| 305 |
|
| 306 |
if site_var1 == 'Draftkings':
|
|
|
|
| 309 |
|
| 310 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 311 |
|
| 312 |
+
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'User/Field', 'Salary', 'Projection', 'Own']]
|
| 313 |
|
| 314 |
return RandomPortfolio, maps_dict
|
| 315 |
|
|
|
|
| 321 |
|
| 322 |
RandomPortfolio['QB'] = pd.Series(list(RandomPortfolio['QB'].map(qb_dict)), dtype="string[pyarrow]")
|
| 323 |
RandomPortfolio['RB1'] = pd.Series(list(RandomPortfolio['RB1'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 324 |
+
RandomPortfolio['RB2'] = pd.Series(list(RandomPortfolio['RB2'].map(full_pos_player_dict['pos_dicts'][0])), dtype="string[pyarrow]")
|
| 325 |
RandomPortfolio['WR1'] = pd.Series(list(RandomPortfolio['WR1'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 326 |
RandomPortfolio['WR2'] = pd.Series(list(RandomPortfolio['WR2'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 327 |
+
RandomPortfolio['WR3'] = pd.Series(list(RandomPortfolio['WR3'].map(full_pos_player_dict['pos_dicts'][1])), dtype="string[pyarrow]")
|
| 328 |
+
RandomPortfolio['FLEX'] = pd.Series(list(RandomPortfolio['FLEX'].map(full_pos_player_dict['pos_dicts'][2])), dtype="string[pyarrow]")
|
| 329 |
+
RandomPortfolio['S_FLEX'] = pd.Series(list(RandomPortfolio['S_FLEX'].map(full_pos_player_dict['pos_dicts'][3])), dtype="string[pyarrow]")
|
| 330 |
RandomPortfolio['plyr_list'] = RandomPortfolio[RandomPortfolio.columns.values.tolist()].values.tolist()
|
| 331 |
RandomPortfolio['plyr_count'] = RandomPortfolio['plyr_list'].apply(lambda x: len(set(x)))
|
| 332 |
+
RandomPortfolio = RandomPortfolio[RandomPortfolio['plyr_count'] == 9].drop(columns=['plyr_list','plyr_count']).\
|
| 333 |
reset_index(drop=True)
|
| 334 |
|
| 335 |
del sizesplit
|
| 336 |
del full_pos_player_dict
|
| 337 |
+
del ranges_dict
|
| 338 |
|
| 339 |
RandomPortfolio['QBs'] = RandomPortfolio['QB'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 340 |
RandomPortfolio['RB1s'] = RandomPortfolio['RB1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 341 |
+
RandomPortfolio['RB2s'] = RandomPortfolio['RB2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 342 |
RandomPortfolio['WR1s'] = RandomPortfolio['WR1'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 343 |
RandomPortfolio['WR2s'] = RandomPortfolio['WR2'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 344 |
+
RandomPortfolio['WR3s'] = RandomPortfolio['WR3'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 345 |
+
RandomPortfolio['FLEXs'] = RandomPortfolio['FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 346 |
+
RandomPortfolio['S_FLEXs'] = RandomPortfolio['S_FLEX'].map(maps_dict['Salary_map']).astype(np.int32)
|
| 347 |
|
| 348 |
RandomPortfolio['QBp'] = RandomPortfolio['QB'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 349 |
RandomPortfolio['RB1p'] = RandomPortfolio['RB1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 350 |
+
RandomPortfolio['RB2p'] = RandomPortfolio['RB2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 351 |
RandomPortfolio['WR1p'] = RandomPortfolio['WR1'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 352 |
RandomPortfolio['WR2p'] = RandomPortfolio['WR2'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 353 |
+
RandomPortfolio['WR3p'] = RandomPortfolio['WR3'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 354 |
+
RandomPortfolio['FLEXp'] = RandomPortfolio['FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 355 |
+
RandomPortfolio['S_FLEXp'] = RandomPortfolio['S_FLEX'].map(maps_dict['Projection_map']).astype(np.float16)
|
| 356 |
|
| 357 |
RandomPortfolio['QBo'] = RandomPortfolio['QB'].map(maps_dict['Own_map']).astype(np.float16)
|
| 358 |
RandomPortfolio['RB1o'] = RandomPortfolio['RB1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 359 |
+
RandomPortfolio['RB2o'] = RandomPortfolio['RB2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 360 |
RandomPortfolio['WR1o'] = RandomPortfolio['WR1'].map(maps_dict['Own_map']).astype(np.float16)
|
| 361 |
RandomPortfolio['WR2o'] = RandomPortfolio['WR2'].map(maps_dict['Own_map']).astype(np.float16)
|
| 362 |
+
RandomPortfolio['WR3o'] = RandomPortfolio['WR3'].map(maps_dict['Own_map']).astype(np.float16)
|
| 363 |
+
RandomPortfolio['FLEXo'] = RandomPortfolio['FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 364 |
+
RandomPortfolio['S_FLEXo'] = RandomPortfolio['S_FLEX'].map(maps_dict['Own_map']).astype(np.float16)
|
| 365 |
|
| 366 |
RandomPortArray = RandomPortfolio.to_numpy()
|
| 367 |
del RandomPortfolio
|
| 368 |
|
| 369 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,9:17].astype(int))]
|
| 370 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,17:25].astype(np.double))]
|
| 371 |
+
RandomPortArray = np.c_[RandomPortArray, np.einsum('ij->i',RandomPortArray[:,25:33].astype(np.double))]
|
| 372 |
# st.write(RandomPortArray[:,:100])
|
| 373 |
+
RandomPortArrayOut = np.delete(RandomPortArray, np.s_[9:33], axis=1)
|
| 374 |
# st.write(RandomPortArrayOut[:,:100])
|
| 375 |
+
RandomPortfolioDF = pd.DataFrame(RandomPortArrayOut, columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'User/Field', 'Salary', 'Projection', 'Own'])
|
| 376 |
RandomPortfolioDF = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 377 |
del RandomPortArray
|
| 378 |
del RandomPortArrayOut
|
|
|
|
| 380 |
if insert_port == 1:
|
| 381 |
CleanPortfolio['Salary'] = sum([CleanPortfolio['QB'].map(maps_dict['Salary_map']),
|
| 382 |
CleanPortfolio['RB1'].map(maps_dict['Salary_map']),
|
| 383 |
+
CleanPortfolio['RB2'].map(maps_dict['Salary_map']),
|
| 384 |
CleanPortfolio['WR1'].map(maps_dict['Salary_map']),
|
| 385 |
CleanPortfolio['WR2'].map(maps_dict['Salary_map']),
|
| 386 |
+
CleanPortfolio['WR3'].map(maps_dict['Salary_map']),
|
| 387 |
+
CleanPortfolio['FLEX'].map(maps_dict['Salary_map']),
|
| 388 |
+
CleanPortfolio['S_FLEX'].map(maps_dict['Salary_map'])
|
| 389 |
]).astype(np.int16)
|
| 390 |
if insert_port == 1:
|
| 391 |
CleanPortfolio['Projection'] = sum([CleanPortfolio['QB'].map(up_dict['Projection_map']),
|
| 392 |
CleanPortfolio['RB1'].map(up_dict['Projection_map']),
|
| 393 |
+
CleanPortfolio['RB2'].map(up_dict['Projection_map']),
|
| 394 |
CleanPortfolio['WR1'].map(up_dict['Projection_map']),
|
| 395 |
CleanPortfolio['WR2'].map(up_dict['Projection_map']),
|
| 396 |
+
CleanPortfolio['WR3'].map(up_dict['Projection_map']),
|
| 397 |
+
CleanPortfolio['FLEX'].map(up_dict['Projection_map']),
|
| 398 |
+
CleanPortfolio['S_FLEX'].map(up_dict['Projection_map'])
|
| 399 |
]).astype(np.float16)
|
| 400 |
if insert_port == 1:
|
| 401 |
CleanPortfolio['Own'] = sum([CleanPortfolio['QB'].map(maps_dict['Own_map']),
|
| 402 |
CleanPortfolio['RB1'].map(maps_dict['Own_map']),
|
| 403 |
+
CleanPortfolio['RB2'].map(maps_dict['Own_map']),
|
| 404 |
CleanPortfolio['WR1'].map(maps_dict['Own_map']),
|
| 405 |
CleanPortfolio['WR2'].map(maps_dict['Own_map']),
|
| 406 |
+
CleanPortfolio['WR3'].map(maps_dict['Own_map']),
|
| 407 |
+
CleanPortfolio['FLEX'].map(maps_dict['Own_map']),
|
| 408 |
+
CleanPortfolio['S_FLEX'].map(maps_dict['Own_map'])
|
| 409 |
]).astype(np.float16)
|
| 410 |
|
| 411 |
if site_var1 == 'Draftkings':
|
|
|
|
| 414 |
|
| 415 |
RandomPortfolio = RandomPortfolioDF.sort_values(by=Sim_function, ascending=False)
|
| 416 |
|
| 417 |
+
RandomPortfolio = RandomPortfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'User/Field', 'Salary', 'Projection', 'Own']]
|
| 418 |
|
| 419 |
return RandomPortfolio, maps_dict
|
| 420 |
|
|
|
|
| 456 |
player_team_dict = dict(zip(proj_dataframe.Player, proj_dataframe.Team))
|
| 457 |
|
| 458 |
with col2:
|
| 459 |
+
st.info("The Portfolio file must contain only columns in order and explicitly named: 'QB', 'RB1', RB2, 'WR1', 'WR2', 'WR3', 'FLEX', and 'S_FLEX'. Upload your projections first to avoid an error message.")
|
| 460 |
portfolio_file = st.file_uploader("Upload Portfolio File", key = 'portfolio_uploader')
|
| 461 |
|
| 462 |
if portfolio_file is not None:
|
|
|
|
| 468 |
|
| 469 |
try:
|
| 470 |
try:
|
| 471 |
+
portfolio_dataframe.columns=["QB", "RB1", "RB2", "WR1", "WR2", "WR3", "FLEX", "S_FLEX"]
|
| 472 |
split_portfolio = portfolio_dataframe
|
| 473 |
split_portfolio[['QB', 'QB_ID']] = split_portfolio.QB.str.split("(", n=1, expand = True)
|
| 474 |
split_portfolio[['RB1', 'RB1_ID']] = split_portfolio.RB1.str.split("(", n=1, expand = True)
|
| 475 |
+
split_portfolio[['RB2', 'RB2_ID']] = split_portfolio.RB2.str.split("(", n=1, expand = True)
|
| 476 |
split_portfolio[['WR1', 'WR1_ID']] = split_portfolio.WR1.str.split("(", n=1, expand = True)
|
| 477 |
split_portfolio[['WR2', 'WR2_ID']] = split_portfolio.WR2.str.split("(", n=1, expand = True)
|
| 478 |
+
split_portfolio[['WR3', 'WR3_ID']] = split_portfolio.WR3.str.split("(", n=1, expand = True)
|
| 479 |
+
split_portfolio[['FLEX', 'FLEX_ID']] = split_portfolio.FLEX.str.split("(", n=1, expand = True)
|
| 480 |
+
split_portfolio[['S_FLEX', 'S_FLEX_ID']] = split_portfolio.S_FLEX.str.split("(", n=1, expand = True)
|
| 481 |
|
| 482 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 483 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
| 484 |
+
split_portfolio['RB2'] = split_portfolio['RB2'].str.strip()
|
| 485 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 486 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 487 |
+
split_portfolio['WR3'] = split_portfolio['WR3'].str.strip()
|
| 488 |
+
split_portfolio['FLEX'] = split_portfolio['FLEX'].str.strip()
|
| 489 |
+
split_portfolio['S_FLEX'] = split_portfolio['S_FLEX'].str.strip()
|
| 490 |
|
| 491 |
st.table(split_portfolio.head(10))
|
| 492 |
|
| 493 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 494 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 495 |
+
split_portfolio['RB2'].map(player_salary_dict),
|
| 496 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 497 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 498 |
+
split_portfolio['WR3'].map(player_salary_dict),
|
| 499 |
+
split_portfolio['FLEX'].map(player_salary_dict),
|
| 500 |
+
split_portfolio['S_FLEX'].map(player_salary_dict)])
|
| 501 |
|
| 502 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 503 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 504 |
+
split_portfolio['RB2'].map(player_proj_dict),
|
| 505 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 506 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 507 |
+
split_portfolio['WR3'].map(player_proj_dict),
|
| 508 |
+
split_portfolio['FLEX'].map(player_proj_dict),
|
| 509 |
+
split_portfolio['S_FLEX'].map(player_proj_dict)])
|
| 510 |
|
| 511 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 512 |
split_portfolio['RB1'].map(player_own_dict),
|
| 513 |
+
split_portfolio['RB2'].map(player_own_dict),
|
| 514 |
split_portfolio['WR1'].map(player_own_dict),
|
| 515 |
split_portfolio['WR2'].map(player_own_dict),
|
| 516 |
+
split_portfolio['WR3'].map(player_own_dict),
|
| 517 |
+
split_portfolio['FLEX'].map(player_own_dict),
|
| 518 |
+
split_portfolio['S_FLEX'].map(player_own_dict)])
|
| 519 |
|
| 520 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 521 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 522 |
+
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 523 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 524 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 525 |
+
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 526 |
+
split_portfolio['FLEX_team'] = split_portfolio['FLEX'].map(player_team_dict)
|
| 527 |
+
split_portfolio['S_FLEX_team'] = split_portfolio['S_FLEX'].map(player_team_dict)
|
| 528 |
|
| 529 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 530 |
+
'RB1_team', 'RB2_team', 'WR1_team', 'WR2_team', 'W32_team', 'FLEX_team', 'S_FLEX_team']]
|
| 531 |
|
| 532 |
|
| 533 |
except:
|
| 534 |
+
portfolio_dataframe.columns=["QB", "RB1", "RB2", "WR1", "WR2", "WR3", "FLEX", "S_FLEX"]
|
| 535 |
|
| 536 |
split_portfolio = portfolio_dataframe
|
| 537 |
split_portfolio[['QB_ID', 'QB']] = split_portfolio.QB.str.split(":", n=1, expand = True)
|
| 538 |
split_portfolio[['RB1_ID', 'RB1']] = split_portfolio.RB1.str.split(":", n=1, expand = True)
|
| 539 |
+
split_portfolio[['RB2_ID', 'RB2']] = split_portfolio.RB2.str.split(":", n=1, expand = True)
|
| 540 |
split_portfolio[['WR1_ID', 'WR1']] = split_portfolio.WR1.str.split(":", n=1, expand = True)
|
| 541 |
split_portfolio[['WR2_ID', 'WR2']] = split_portfolio.WR2.str.split(":", n=1, expand = True)
|
| 542 |
+
split_portfolio[['WR3_ID', 'WR3']] = split_portfolio.WR3.str.split(":", n=1, expand = True)
|
| 543 |
+
split_portfolio[['FLEX_ID', 'FLEX']] = split_portfolio.FLEX.str.split(":", n=1, expand = True)
|
| 544 |
+
split_portfolio[['S_FLEX_ID', 'S_FLEX']] = split_portfolio.S_FLEX.str.split(":", n=1, expand = True)
|
| 545 |
|
| 546 |
split_portfolio['QB'] = split_portfolio['QB'].str.strip()
|
| 547 |
split_portfolio['RB1'] = split_portfolio['RB1'].str.strip()
|
| 548 |
+
split_portfolio['RB2'] = split_portfolio['RB2'].str.strip()
|
| 549 |
split_portfolio['WR1'] = split_portfolio['WR1'].str.strip()
|
| 550 |
split_portfolio['WR2'] = split_portfolio['WR2'].str.strip()
|
| 551 |
+
split_portfolio['WR3'] = split_portfolio['WR3'].str.strip()
|
| 552 |
+
split_portfolio['FLEX'] = split_portfolio['FLEX'].str.strip()
|
| 553 |
+
split_portfolio['S_FLEX'] = split_portfolio['S_FLEX'].str.strip()
|
| 554 |
|
| 555 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 556 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 557 |
+
split_portfolio['RB2'].map(player_salary_dict),
|
| 558 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 559 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 560 |
+
split_portfolio['WR3'].map(player_salary_dict),
|
| 561 |
+
split_portfolio['FLEX'].map(player_salary_dict),
|
| 562 |
+
split_portfolio['S_FLEX'].map(player_salary_dict)])
|
| 563 |
|
| 564 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 565 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 566 |
+
split_portfolio['RB2'].map(player_proj_dict),
|
| 567 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 568 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 569 |
+
split_portfolio['WR3'].map(player_proj_dict),
|
| 570 |
+
split_portfolio['FLEX'].map(player_proj_dict),
|
| 571 |
+
split_portfolio['S_FLEX'].map(player_proj_dict)])
|
| 572 |
|
| 573 |
st.table(split_portfolio.head(10))
|
| 574 |
split_portfolio['Ownership'] = sum([split_portfolio['QB'].map(player_own_dict),
|
| 575 |
split_portfolio['RB1'].map(player_own_dict),
|
| 576 |
+
split_portfolio['RB2'].map(player_own_dict),
|
| 577 |
split_portfolio['WR1'].map(player_own_dict),
|
| 578 |
split_portfolio['WR2'].map(player_own_dict),
|
| 579 |
+
split_portfolio['WR3'].map(player_own_dict),
|
| 580 |
+
split_portfolio['FLEX'].map(player_own_dict),
|
| 581 |
+
split_portfolio['S_FLEX'].map(player_own_dict)])
|
| 582 |
|
| 583 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 584 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 585 |
+
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 586 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 587 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 588 |
+
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 589 |
+
split_portfolio['FLEX_team'] = split_portfolio['FLEX'].map(player_team_dict)
|
| 590 |
+
split_portfolio['S_FLEX_team'] = split_portfolio['S_FLEX'].map(player_team_dict)
|
| 591 |
|
| 592 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 593 |
+
'RB1_team', 'RB2_team', 'WR1_team', 'WR2_team', 'WR3_team', 'FLEX_team', 'S_FLEX_team']]
|
| 594 |
|
| 595 |
except:
|
| 596 |
split_portfolio = portfolio_dataframe
|
| 597 |
|
| 598 |
split_portfolio['Salary'] = sum([split_portfolio['QB'].map(player_salary_dict),
|
| 599 |
split_portfolio['RB1'].map(player_salary_dict),
|
| 600 |
+
split_portfolio['RB2'].map(player_salary_dict),
|
| 601 |
split_portfolio['WR1'].map(player_salary_dict),
|
| 602 |
split_portfolio['WR2'].map(player_salary_dict),
|
| 603 |
+
split_portfolio['WR3'].map(player_salary_dict),
|
| 604 |
+
split_portfolio['FLEX'].map(player_salary_dict),
|
| 605 |
+
split_portfolio['S_FLEX'].map(player_salary_dict)])
|
| 606 |
|
| 607 |
split_portfolio['Projection'] = sum([split_portfolio['QB'].map(player_proj_dict),
|
| 608 |
split_portfolio['RB1'].map(player_proj_dict),
|
| 609 |
+
split_portfolio['RB2'].map(player_proj_dict),
|
| 610 |
split_portfolio['WR1'].map(player_proj_dict),
|
| 611 |
split_portfolio['WR2'].map(player_proj_dict),
|
| 612 |
+
split_portfolio['WR3'].map(player_proj_dict),
|
| 613 |
+
split_portfolio['FLEX'].map(player_proj_dict),
|
| 614 |
+
split_portfolio['S_FLEX'].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['WR3'].map(player_own_dict),
|
| 622 |
+
split_portfolio['FLEX'].map(player_own_dict),
|
| 623 |
+
split_portfolio['S_FLEX'].map(player_own_dict)])
|
| 624 |
|
| 625 |
split_portfolio['QB_team'] = split_portfolio['QB'].map(player_team_dict)
|
| 626 |
split_portfolio['RB1_team'] = split_portfolio['RB1'].map(player_team_dict)
|
| 627 |
+
split_portfolio['RB2_team'] = split_portfolio['RB2'].map(player_team_dict)
|
| 628 |
split_portfolio['WR1_team'] = split_portfolio['WR1'].map(player_team_dict)
|
| 629 |
split_portfolio['WR2_team'] = split_portfolio['WR2'].map(player_team_dict)
|
| 630 |
split_portfolio['WR3_team'] = split_portfolio['WR3'].map(player_team_dict)
|
| 631 |
+
split_portfolio['FLEX_team'] = split_portfolio['FLEX'].map(player_team_dict)
|
| 632 |
+
split_portfolio['S_FLEX_team'] = split_portfolio['S_FLEX'].map(player_team_dict)
|
|
|
|
| 633 |
|
| 634 |
+
split_portfolio = split_portfolio[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'Salary', 'Projection', 'Ownership', 'QB_team',
|
| 635 |
+
'RB1_team', 'RB2_team', 'WR1_team', 'WR2_team', 'WR3_team', 'FLEX_team', 'S_FLEX_team']]
|
| 636 |
|
| 637 |
+
for player_cols in split_portfolio.iloc[:, :8]:
|
| 638 |
static_col_raw = split_portfolio[player_cols].value_counts()
|
| 639 |
static_col = static_col_raw.to_frame()
|
| 640 |
static_col.reset_index(inplace=True)
|
|
|
|
| 655 |
if portfolio_file is not None:
|
| 656 |
split_portfolio = split_portfolio
|
| 657 |
|
| 658 |
+
for player_cols in split_portfolio.iloc[:, :8]:
|
| 659 |
exposure_col_raw = split_portfolio[player_cols].value_counts()
|
| 660 |
exposure_col = exposure_col_raw.to_frame()
|
| 661 |
exposure_col.reset_index(inplace=True)
|
|
|
|
| 682 |
st.header('Portfolio View')
|
| 683 |
split_portfolio = split_portfolio.reset_index()
|
| 684 |
split_portfolio['Lineup'] = split_portfolio['index'] + 1
|
| 685 |
+
display_portfolio = split_portfolio[['Lineup', 'QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX', 'Salary', 'Projection', 'Ownership']]
|
| 686 |
display_portfolio = display_portfolio.set_index('Lineup')
|
| 687 |
st.dataframe(display_portfolio.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Ownership']).format(precision=2))
|
| 688 |
del split_portfolio
|
|
|
|
| 767 |
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'])
|
| 768 |
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%'])
|
| 769 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 770 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (800 / OwnFrame['Own%'].sum())
|
| 771 |
if contest_var1 == 'Medium':
|
| 772 |
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'])
|
| 773 |
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%'])
|
| 774 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 775 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (800 / OwnFrame['Own%'].sum())
|
| 776 |
if contest_var1 == 'Large':
|
| 777 |
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'])
|
| 778 |
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%'])
|
| 779 |
OwnFrame['Own%'] = np.where(OwnFrame['Own%'] > 75, 75, OwnFrame['Own%'])
|
| 780 |
+
OwnFrame['Own'] = OwnFrame['Own%'] * (800 / OwnFrame['Own%'].sum())
|
| 781 |
Overall_Proj = OwnFrame[['Player', 'Team', 'Position', 'Median', 'Own', 'Salary']]
|
| 782 |
|
| 783 |
del OwnFrame
|
| 784 |
|
| 785 |
if insert_port == 1:
|
| 786 |
+
UserPortfolio = portfolio_dataframe[['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX']]
|
| 787 |
elif insert_port == 0:
|
| 788 |
+
UserPortfolio = pd.DataFrame(columns = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX'])
|
| 789 |
|
| 790 |
Overall_Proj.replace('', np.nan, inplace=True)
|
| 791 |
Overall_Proj = Overall_Proj.dropna(subset=['Median'])
|
|
|
|
| 855 |
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
| 856 |
pos_players = pos_players.reset_index(drop=True)
|
| 857 |
|
| 858 |
+
s_pos_players = pd.concat([qbs_raw, rbs_raw, wrs_raw])
|
| 859 |
+
pos_players.dropna(subset=['Median']).reset_index(drop=True)
|
| 860 |
+
pos_players = pos_players.reset_index(drop=True)
|
| 861 |
+
|
| 862 |
del qbs_raw
|
| 863 |
del defs_raw
|
| 864 |
del rbs_raw
|
|
|
|
| 870 |
Raw_Portfolio = pd.DataFrame()
|
| 871 |
|
| 872 |
# Loop through each position and split the data accordingly
|
| 873 |
+
positions = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX']
|
| 874 |
for pos in positions:
|
| 875 |
temp_df = UserPortfolio[pos].str.split("(", n=1, expand=True)
|
| 876 |
temp_df.columns = [pos, 'Drop']
|
|
|
|
| 887 |
|
| 888 |
# Create frequency table for players
|
| 889 |
cleaport_players = pd.DataFrame(
|
| 890 |
+
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:8].values, return_counts=True)),
|
| 891 |
columns=['Player', 'Freq']
|
| 892 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 893 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
|
|
| 908 |
|
| 909 |
# Create frequency table for players
|
| 910 |
cleaport_players = pd.DataFrame(
|
| 911 |
+
np.column_stack(np.unique(CleanPortfolio.iloc[:, 0:8].values, return_counts=True)),
|
| 912 |
columns=['Player', 'Freq']
|
| 913 |
).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 914 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
|
|
|
| 920 |
|
| 921 |
elif insert_port == 0:
|
| 922 |
CleanPortfolio = UserPortfolio
|
| 923 |
+
cleaport_players = pd.DataFrame(np.column_stack(np.unique(CleanPortfolio.iloc[:,0:8].values, return_counts=True)),
|
| 924 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 925 |
cleaport_players['Freq'] = cleaport_players['Freq'].astype(int)
|
| 926 |
nerf_frame = Overall_Proj
|
| 927 |
|
| 928 |
ref_dict = {
|
| 929 |
+
'pos':['RB', 'WR', 'FLEX', 'S_FLEX'],
|
| 930 |
+
'pos_dfs':['RB_Table', 'WR_Table', 'FLEX_Table', 'S_FLEX_Table'],
|
| 931 |
+
'pos_dicts':['rb_dict', 'wr_dict', 'flex_dict', 's_flex_table']
|
| 932 |
}
|
| 933 |
|
| 934 |
maps_dict = {
|
|
|
|
| 1006 |
else:
|
| 1007 |
sample_arrays = sample_arrays1
|
| 1008 |
|
| 1009 |
+
final_array = sample_arrays[sample_arrays[:, 9].argsort()[::-1]]
|
| 1010 |
best_lineup = final_array[final_array[:, -1].argsort(kind='stable')[::-1][:1]]
|
| 1011 |
Sim_Winners.append(best_lineup)
|
| 1012 |
SimVar += 1
|
|
|
|
| 1033 |
Sim_Winner_Export = Sim_Winner_Frame.copy()
|
| 1034 |
|
| 1035 |
# Conditional Replacement
|
| 1036 |
+
columns_to_replace = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'WR3', 'FLEX', 'S_FLEX']
|
| 1037 |
|
| 1038 |
+
player_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,0:8].values, return_counts=True)),
|
| 1039 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1040 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 1041 |
player_freq['Position'] = player_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1063 |
|
| 1064 |
qb_freq = qb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1065 |
|
| 1066 |
+
rb_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,1:3].values, return_counts=True)),
|
| 1067 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1068 |
rb_freq['Freq'] = rb_freq['Freq'].astype(int)
|
| 1069 |
rb_freq['Position'] = rb_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1077 |
|
| 1078 |
rb_freq = rb_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1079 |
|
| 1080 |
+
wr_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,[3, 4, 5]].values, return_counts=True)),
|
| 1081 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1082 |
wr_freq['Freq'] = wr_freq['Freq'].astype(int)
|
| 1083 |
wr_freq['Position'] = wr_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1091 |
|
| 1092 |
wr_freq = wr_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1093 |
|
| 1094 |
+
flex_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,5:6].values, return_counts=True)),
|
| 1095 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1096 |
flex_freq['Freq'] = flex_freq['Freq'].astype(int)
|
| 1097 |
flex_freq['Position'] = flex_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1105 |
|
| 1106 |
flex_freq = flex_freq[['Player', 'Team', 'Position', 'Salary', 'Proj Own', 'Exposure', 'Edge']]
|
| 1107 |
|
| 1108 |
+
dst_freq = pd.DataFrame(np.column_stack(np.unique(Sim_Winner_Frame.iloc[:,6:7].values, return_counts=True)),
|
| 1109 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 1110 |
dst_freq['Freq'] = dst_freq['Freq'].astype(int)
|
| 1111 |
dst_freq['Position'] = dst_freq['Player'].map(maps_dict['Pos_map'])
|
|
|
|
| 1132 |
|
| 1133 |
with st.container():
|
| 1134 |
freq_container = st.empty()
|
| 1135 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(['Overall Exposures', 'QB Exposures', 'RB Exposures', 'WR Exposures', 'FLEX Exposures', 'S_FLEX Exposures'])
|
| 1136 |
with tab1:
|
| 1137 |
st.dataframe(player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(freq_format, precision=2), use_container_width = True)
|
| 1138 |
st.download_button(
|
|
|
|
| 1178 |
st.download_button(
|
| 1179 |
label="Export Exposures",
|
| 1180 |
data=convert_df_to_csv(dst_freq),
|
| 1181 |
+
file_name='s_flex_freq_export.csv',
|
| 1182 |
mime='text/csv',
|
| 1183 |
)
|