Spaces:
Runtime error
Runtime error
James McCool
commited on
Commit
·
d1ddee5
1
Parent(s):
e722ab0
Add custom tab styling to improve UI aesthetics and user experience
Browse filesImplement custom CSS styling for Streamlit tabs to:
- Enhance visual appeal with gold color scheme
- Improve tab readability and interaction
- Add smooth transitions and hover effects
- Create a more polished and professional look for the application interface
app.py
CHANGED
|
@@ -38,6 +38,37 @@ expose_format = {'Proj Own': '{:.2%}','Exposure': '{:.2%}'}
|
|
| 38 |
|
| 39 |
all_dk_player_projections = st.secrets["NFL_data"]
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
@st.cache_resource(ttl=60)
|
| 42 |
def init_baselines():
|
| 43 |
collection = nba_db["Player_SD_Range_Of_Outcomes"]
|
|
@@ -115,55 +146,56 @@ def convert_df_to_csv(df):
|
|
| 115 |
tab1, tab2 = st.tabs(['Range of Outcomes', 'Optimizer'])
|
| 116 |
|
| 117 |
with tab1:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
if
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
hold_container = st.empty()
|
| 169 |
|
|
@@ -204,14 +236,13 @@ with tab1:
|
|
| 204 |
)
|
| 205 |
|
| 206 |
with tab2:
|
| 207 |
-
|
| 208 |
-
with col1:
|
| 209 |
if st.button("Load/Reset Data", key='reset1'):
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
sport_var1 = st.radio("What sport are you optimizing?", ('
|
| 215 |
if sport_var1 == 'NBA':
|
| 216 |
dk_roo_raw = nba_dk_sd_raw
|
| 217 |
fd_roo_raw = nba_fd_sd_raw
|
|
@@ -243,7 +274,7 @@ with tab2:
|
|
| 243 |
st.info("Showdown on Fanduel sucks, you should not do that, but I understand degen's gotta degen")
|
| 244 |
raw_baselines = fd_roo_raw
|
| 245 |
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #3']
|
| 246 |
-
|
| 247 |
contest_var1 = st.selectbox("What contest type are you optimizing for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var1')
|
| 248 |
lock_var1 = st.multiselect("Are there any players you want to use in all lineups in the CAPTAIN (Lock Button)?", options = raw_baselines['Player'].unique(), key='lock_var1')
|
| 249 |
lock_var2 = st.multiselect("Are there any players you want to use in all lineups in the FLEX (Lock Button)?", options = raw_baselines['Player'].unique(), key='lock_var2')
|
|
@@ -350,329 +381,328 @@ with tab2:
|
|
| 350 |
flex_proj['Own'] = display_baselines['Own']
|
| 351 |
flex_proj['lock'] = display_baselines['lock']
|
| 352 |
flex_proj['roster'] = 'FLEX'
|
| 353 |
-
|
| 354 |
-
combo_file = pd.concat([cpt_proj, flex_proj], ignore_index=True)
|
| 355 |
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
display_container = st.empty()
|
| 358 |
display_dl_container = st.empty()
|
| 359 |
optimize_container = st.empty()
|
| 360 |
download_container = st.empty()
|
| 361 |
freq_container = st.empty()
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
flex_file.
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
overall_players = flex_file[['Player']]
|
| 399 |
-
overall_players['player_var_add'] = flex_file.index
|
| 400 |
-
overall_players['player_var'] = 'player_vars_' + overall_players['player_var_add'].astype(str)
|
| 401 |
-
|
| 402 |
-
player_vars = pulp.LpVariable.dicts("player_vars", flex_file.index, 0, 1, pulp.LpInteger)
|
| 403 |
-
total_score = pulp.LpProblem("Fantasy_Points_Problem", pulp.LpMaximize)
|
| 404 |
-
player_match = dict(zip(overall_players['player_var'], overall_players['Player']))
|
| 405 |
-
player_index_match = dict(zip(overall_players['player_var'], overall_players['player_var_add']))
|
| 406 |
-
|
| 407 |
-
player_own = dict(zip(flex_file['Player'], flex_file['Proj DK Own%']))
|
| 408 |
-
player_team = dict(zip(flex_file['Player'], flex_file['Team']))
|
| 409 |
-
player_pos = dict(zip(flex_file['Player'], flex_file['Position']))
|
| 410 |
-
player_sal = dict(zip(flex_file['Player'], flex_file['Salary']))
|
| 411 |
-
player_proj = dict(zip(flex_file['Player'], flex_file['Median']))
|
| 412 |
-
|
| 413 |
-
obj_points = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 414 |
-
total_score += sum([player_vars[idx]*obj_points[idx] for idx in flex_file.index])
|
| 415 |
-
|
| 416 |
-
obj_points_max = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 417 |
-
obj_own_max = {idx: (flex_file['Proj DK Own%'][idx]) for idx in flex_file.index}
|
| 418 |
-
|
| 419 |
-
obj_salary = {idx: (flex_file['Salary'][idx]) for idx in flex_file.index}
|
| 420 |
-
total_score += pulp.lpSum([player_vars[idx]*obj_salary[idx] for idx in flex_file.index]) <= max_sal1
|
| 421 |
-
total_score += pulp.lpSum([player_vars[idx]*obj_salary[idx] for idx in flex_file.index]) >= min_sal1
|
| 422 |
-
|
| 423 |
-
if site_var1 == 'Draftkings':
|
| 424 |
-
|
| 425 |
-
for flex in flex_file['lock'].unique():
|
| 426 |
-
sub_idx = flex_file[flex_file['lock'] == 1].index
|
| 427 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == len(lock_var2)
|
| 428 |
-
|
| 429 |
-
for flex in flex_file['roster'].unique():
|
| 430 |
-
sub_idx = flex_file[flex_file['roster'] == "CPT"].index
|
| 431 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 1
|
| 432 |
-
|
| 433 |
-
for flex in flex_file['roster'].unique():
|
| 434 |
-
sub_idx = flex_file[flex_file['roster'] == "FLEX"].index
|
| 435 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 5
|
| 436 |
-
|
| 437 |
-
for playerid in player_ids:
|
| 438 |
-
total_score += pulp.lpSum([player_vars[i] for i in player_ids if
|
| 439 |
-
(flex_file['name_var'][i] == flex_file['name_var'][playerid])]) <= 1
|
| 440 |
-
|
| 441 |
-
elif site_var1 == 'Fanduel':
|
| 442 |
-
|
| 443 |
-
for flex in flex_file['lock'].unique():
|
| 444 |
-
sub_idx = flex_file[flex_file['lock'] == 1].index
|
| 445 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == len(lock_var2)
|
| 446 |
-
|
| 447 |
-
for flex in flex_file['Position'].unique():
|
| 448 |
-
sub_idx = flex_file[flex_file['Position'] != "Var"].index
|
| 449 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 5
|
| 450 |
-
|
| 451 |
-
for flex in flex_file['roster'].unique():
|
| 452 |
-
sub_idx = flex_file[flex_file['roster'] == "CPT"].index
|
| 453 |
-
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 1
|
| 454 |
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
player_trim = []
|
| 461 |
-
lineup_list = []
|
| 462 |
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
total_score +=
|
| 466 |
-
total_score += pulp.lpSum([player_vars[idx]*obj_points[idx] for idx in flex_file.index]) <= max_own - .001
|
| 467 |
-
elif contest_var1 != 'Cash':
|
| 468 |
-
obj_points = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 469 |
-
total_score += sum([player_vars[idx]*obj_points[idx] for idx in flex_file.index])
|
| 470 |
-
total_score += pulp.lpSum([player_vars[idx]*obj_points[idx] for idx in flex_file.index]) <= max_proj - .01
|
| 471 |
-
if trim_var1 == 1:
|
| 472 |
-
total_score += pulp.lpSum([player_vars[idx]*obj_own_max[idx] for idx in flex_file.index]) <= max_own - .001
|
| 473 |
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
lineup_list.append(v.name)
|
| 478 |
-
df = pd.DataFrame(lineup_list)
|
| 479 |
-
df['Names'] = df[0].map(player_match)
|
| 480 |
-
df['Cost'] = df['Names'].map(player_sal)
|
| 481 |
-
df['Proj'] = df['Names'].map(player_proj)
|
| 482 |
-
df['Own'] = df['Names'].map(player_own)
|
| 483 |
-
total_cost = sum(df['Cost'])
|
| 484 |
-
total_own = sum(df['Own'])
|
| 485 |
-
total_proj = sum(df['Proj'])
|
| 486 |
-
lineup_raw = pd.DataFrame(lineup_list)
|
| 487 |
-
lineup_raw['Names'] = lineup_raw[0].map(player_match)
|
| 488 |
-
lineup_raw['value'] = lineup_raw[0].map(player_index_match)
|
| 489 |
-
lineup_final = lineup_raw.sort_values(by=['value'])
|
| 490 |
-
del lineup_final[lineup_final.columns[0]]
|
| 491 |
-
del lineup_final[lineup_final.columns[1]]
|
| 492 |
-
lineup_final['Team'] = lineup_final['Names'].map(player_team)
|
| 493 |
-
lineup_final['Position'] = lineup_final['Names'].map(player_pos)
|
| 494 |
-
lineup_final['Salary'] = lineup_final['Names'].map(player_sal)
|
| 495 |
-
lineup_final['Proj'] = lineup_final['Names'].map(player_proj)
|
| 496 |
-
lineup_final['Own'] = lineup_final['Names'].map(player_own)
|
| 497 |
-
lineup_final.loc['Column_Total'] = lineup_final.sum(numeric_only=True, axis=0)
|
| 498 |
-
lineup_final = lineup_final.reset_index(drop=True)
|
| 499 |
-
|
| 500 |
-
max_proj = total_proj
|
| 501 |
-
max_own = total_own
|
| 502 |
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
if site_var1 == 'Draftkings':
|
| 527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
elif site_var1 == 'Fanduel':
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
st.session_state.portfolio = portfolio.drop_duplicates()
|
| 537 |
|
| 538 |
-
|
| 539 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
-
final_outcomes_export =
|
| 551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
-
if
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
final_outcomes_export['MVP'] = split_portfolio['MVP']
|
| 611 |
-
final_outcomes_export['FLEX1'] = split_portfolio['FLEX1']
|
| 612 |
-
final_outcomes_export['FLEX2'] = split_portfolio['FLEX2']
|
| 613 |
-
final_outcomes_export['FLEX3'] = split_portfolio['FLEX3']
|
| 614 |
-
final_outcomes_export['FLEX4'] = split_portfolio['FLEX4']
|
| 615 |
-
|
| 616 |
-
if sport_var1 == 'NFL':
|
| 617 |
-
final_outcomes_export['MVP'].replace(nfl_fd_id_dict, inplace=True)
|
| 618 |
-
final_outcomes_export['FLEX1'].replace(nfl_fd_id_dict, inplace=True)
|
| 619 |
-
final_outcomes_export['FLEX2'].replace(nfl_fd_id_dict, inplace=True)
|
| 620 |
-
final_outcomes_export['FLEX3'].replace(nfl_fd_id_dict, inplace=True)
|
| 621 |
-
final_outcomes_export['FLEX4'].replace(nfl_fd_id_dict, inplace=True)
|
| 622 |
-
elif sport_var1 == 'NBA':
|
| 623 |
-
final_outcomes_export['MVP'].replace(nba_fd_id_dict, inplace=True)
|
| 624 |
-
final_outcomes_export['FLEX1'].replace(nba_fd_id_dict, inplace=True)
|
| 625 |
-
final_outcomes_export['FLEX2'].replace(nba_fd_id_dict, inplace=True)
|
| 626 |
-
final_outcomes_export['FLEX3'].replace(nba_fd_id_dict, inplace=True)
|
| 627 |
-
final_outcomes_export['FLEX4'].replace(nba_fd_id_dict, inplace=True)
|
| 628 |
-
final_outcomes_export['Salary'] = final_outcomes['Cost']
|
| 629 |
-
final_outcomes_export['Own'] = final_outcomes['Own']
|
| 630 |
-
final_outcomes_export['Proj'] = final_outcomes['Proj']
|
| 631 |
-
|
| 632 |
-
st.session_state.FD_final_outcomes_export = final_outcomes_export.copy()
|
| 633 |
-
|
| 634 |
-
st.session_state.player_freq = player_freq[['Player', 'Position', 'Team', 'Salary', 'Proj Own', 'Exposure']]
|
| 635 |
-
with display_container:
|
| 636 |
-
display_container = st.empty()
|
| 637 |
-
if 'display_baselines' in st.session_state:
|
| 638 |
-
st.dataframe(st.session_state.display_baselines.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 639 |
-
|
| 640 |
-
with display_dl_container:
|
| 641 |
-
display_dl_container = st.empty()
|
| 642 |
-
if 'export_baselines' in st.session_state:
|
| 643 |
-
st.download_button(
|
| 644 |
-
label="Export Projections",
|
| 645 |
-
data=convert_df_to_csv(st.session_state.export_baselines),
|
| 646 |
-
file_name='showdown_proj_export.csv',
|
| 647 |
-
mime='text/csv',
|
| 648 |
-
)
|
| 649 |
-
|
| 650 |
-
with optimize_container:
|
| 651 |
-
optimize_container = st.empty()
|
| 652 |
-
if 'final_outcomes' in st.session_state:
|
| 653 |
-
st.dataframe(st.session_state.final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 654 |
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
if '
|
| 659 |
-
st.
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
)
|
| 665 |
-
elif site_var1 == 'Fanduel':
|
| 666 |
-
if 'FD_final_outcomes_export' in st.session_state:
|
| 667 |
st.download_button(
|
| 668 |
-
label="Export
|
| 669 |
-
data=convert_df_to_csv(st.session_state.
|
| 670 |
-
file_name='
|
| 671 |
mime='text/csv',
|
| 672 |
-
)
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
all_dk_player_projections = st.secrets["NFL_data"]
|
| 40 |
|
| 41 |
+
st.markdown("""
|
| 42 |
+
<style>
|
| 43 |
+
/* Tab styling */
|
| 44 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 45 |
+
gap: 8px;
|
| 46 |
+
padding: 4px;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.stTabs [data-baseweb="tab"] {
|
| 50 |
+
height: 50px;
|
| 51 |
+
white-space: pre-wrap;
|
| 52 |
+
background-color: #FFD700;
|
| 53 |
+
color: white;
|
| 54 |
+
border-radius: 10px;
|
| 55 |
+
gap: 1px;
|
| 56 |
+
padding: 10px 20px;
|
| 57 |
+
font-weight: bold;
|
| 58 |
+
transition: all 0.3s ease;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
.stTabs [aria-selected="true"] {
|
| 62 |
+
background-color: #DAA520;
|
| 63 |
+
color: white;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.stTabs [data-baseweb="tab"]:hover {
|
| 67 |
+
background-color: #DAA520;
|
| 68 |
+
cursor: pointer;
|
| 69 |
+
}
|
| 70 |
+
</style>""", unsafe_allow_html=True)
|
| 71 |
+
|
| 72 |
@st.cache_resource(ttl=60)
|
| 73 |
def init_baselines():
|
| 74 |
collection = nba_db["Player_SD_Range_Of_Outcomes"]
|
|
|
|
| 146 |
tab1, tab2 = st.tabs(['Range of Outcomes', 'Optimizer'])
|
| 147 |
|
| 148 |
with tab1:
|
| 149 |
+
with st.expander('Info and Filters'):
|
| 150 |
+
if st.button("Load/Reset Data", key='reset2'):
|
| 151 |
+
st.cache_data.clear()
|
| 152 |
+
nba_dk_sd_raw, nba_fd_sd_raw, nfl_dk_sd_raw, nfl_fd_sd_raw, nba_timestamp, nfl_dk_timestamp, nba_dk_id_dict, nfl_dk_id_dict, nba_fd_id_dict, nfl_fd_id_dict = init_baselines()
|
| 153 |
+
info_container = st.container()
|
| 154 |
+
with info_container:
|
| 155 |
+
st.info("Simple view is better for mobile and shows just the most valuable stats, Advanced view is better for desktop and shows all stats and thresholds")
|
| 156 |
+
options_container = st.container()
|
| 157 |
+
with options_container:
|
| 158 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 159 |
+
|
| 160 |
+
with col1:
|
| 161 |
+
view_var2 = st.radio("View Type", ("Simple", "Advanced"), key='view_var2')
|
| 162 |
+
|
| 163 |
+
with col2:
|
| 164 |
+
sport_var2 = st.radio("Sport", ('NBA', 'NFL'), key='sport_var2')
|
| 165 |
+
if sport_var2 == 'NBA':
|
| 166 |
+
dk_roo_raw = nba_dk_sd_raw
|
| 167 |
+
fd_roo_raw = nba_fd_sd_raw
|
| 168 |
+
elif sport_var2 == 'NFL':
|
| 169 |
+
dk_roo_raw = nfl_dk_sd_raw
|
| 170 |
+
fd_roo_raw = nfl_fd_sd_raw
|
| 171 |
+
|
| 172 |
+
with col3:
|
| 173 |
+
slate_var2 = st.radio("Slate", ('Paydirt (Main)', 'Paydirt (Secondary)', 'Paydirt (Auxiliary)'), key='slate_var2')
|
| 174 |
+
|
| 175 |
+
with col4:
|
| 176 |
+
site_var2 = st.radio("Site", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 177 |
+
|
| 178 |
+
if site_var2 == 'Draftkings':
|
| 179 |
+
if slate_var2 == 'Paydirt (Main)':
|
| 180 |
+
raw_baselines = dk_roo_raw
|
| 181 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #1']
|
| 182 |
+
elif slate_var2 == 'Paydirt (Secondary)':
|
| 183 |
+
raw_baselines = dk_roo_raw
|
| 184 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #2']
|
| 185 |
+
elif slate_var2 == 'Paydirt (Auxiliary)':
|
| 186 |
+
raw_baselines = dk_roo_raw
|
| 187 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #3']
|
| 188 |
+
|
| 189 |
+
elif site_var2 == 'Fanduel':
|
| 190 |
+
if slate_var2 == 'Paydirt (Main)':
|
| 191 |
+
raw_baselines = fd_roo_raw
|
| 192 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #1']
|
| 193 |
+
elif slate_var2 == 'Paydirt (Secondary)':
|
| 194 |
+
raw_baselines = fd_roo_raw
|
| 195 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #2']
|
| 196 |
+
elif slate_var2 == 'Paydirt (Auxiliary)':
|
| 197 |
+
raw_baselines = fd_roo_raw
|
| 198 |
+
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #3']
|
| 199 |
|
| 200 |
hold_container = st.empty()
|
| 201 |
|
|
|
|
| 236 |
)
|
| 237 |
|
| 238 |
with tab2:
|
| 239 |
+
with st.expander('Info and Filters'):
|
|
|
|
| 240 |
if st.button("Load/Reset Data", key='reset1'):
|
| 241 |
+
st.cache_data.clear()
|
| 242 |
+
nba_dk_sd_raw, nba_fd_sd_raw, nfl_dk_sd_raw, nfl_fd_sd_raw, nba_timestamp, nfl_dk_timestamp, nba_dk_id_dict, nfl_dk_id_dict, nba_fd_id_dict, nfl_fd_id_dict = init_baselines()
|
| 243 |
+
for key in st.session_state.keys():
|
| 244 |
+
del st.session_state[key]
|
| 245 |
+
sport_var1 = st.radio("What sport are you optimizing?", ('NBA', 'NFL'), key='sport_var1')
|
| 246 |
if sport_var1 == 'NBA':
|
| 247 |
dk_roo_raw = nba_dk_sd_raw
|
| 248 |
fd_roo_raw = nba_fd_sd_raw
|
|
|
|
| 274 |
st.info("Showdown on Fanduel sucks, you should not do that, but I understand degen's gotta degen")
|
| 275 |
raw_baselines = fd_roo_raw
|
| 276 |
raw_baselines = raw_baselines[raw_baselines['slate'] == 'Showdown #3']
|
| 277 |
+
|
| 278 |
contest_var1 = st.selectbox("What contest type are you optimizing for?", ('Cash', 'Small Field GPP', 'Large Field GPP'), key='contest_var1')
|
| 279 |
lock_var1 = st.multiselect("Are there any players you want to use in all lineups in the CAPTAIN (Lock Button)?", options = raw_baselines['Player'].unique(), key='lock_var1')
|
| 280 |
lock_var2 = st.multiselect("Are there any players you want to use in all lineups in the FLEX (Lock Button)?", options = raw_baselines['Player'].unique(), key='lock_var2')
|
|
|
|
| 381 |
flex_proj['Own'] = display_baselines['Own']
|
| 382 |
flex_proj['lock'] = display_baselines['lock']
|
| 383 |
flex_proj['roster'] = 'FLEX'
|
|
|
|
|
|
|
| 384 |
|
| 385 |
+
combo_file = pd.concat([cpt_proj, flex_proj], ignore_index=True)
|
| 386 |
+
|
| 387 |
+
display_container = st.empty()
|
| 388 |
+
display_dl_container = st.empty()
|
| 389 |
+
optimize_container = st.empty()
|
| 390 |
+
download_container = st.empty()
|
| 391 |
+
freq_container = st.empty()
|
| 392 |
+
if st.button('Optimize'):
|
| 393 |
+
for key in st.session_state.keys():
|
| 394 |
+
del st.session_state[key]
|
| 395 |
+
max_proj = 1000
|
| 396 |
+
max_own = 1000
|
| 397 |
+
total_proj = 0
|
| 398 |
+
total_own = 0
|
| 399 |
display_container = st.empty()
|
| 400 |
display_dl_container = st.empty()
|
| 401 |
optimize_container = st.empty()
|
| 402 |
download_container = st.empty()
|
| 403 |
freq_container = st.empty()
|
| 404 |
+
lineup_display = []
|
| 405 |
+
check_list = []
|
| 406 |
+
lineups = []
|
| 407 |
+
portfolio = pd.DataFrame()
|
| 408 |
+
x = 1
|
| 409 |
+
|
| 410 |
+
with st.spinner('Wait for it...'):
|
| 411 |
+
with optimize_container:
|
| 412 |
+
|
| 413 |
+
while x <= linenum_var1:
|
| 414 |
+
sorted_lineup = []
|
| 415 |
+
p_used = []
|
| 416 |
+
|
| 417 |
+
raw_proj_file = combo_file
|
| 418 |
+
raw_flex_file = raw_proj_file.dropna(how='all')
|
| 419 |
+
raw_flex_file = raw_flex_file.loc[raw_flex_file['Median'] > 0]
|
| 420 |
+
flex_file = raw_flex_file
|
| 421 |
+
flex_file.rename(columns={"Own": "Proj DK Own%"}, inplace = True)
|
| 422 |
+
flex_file['name_var'] = flex_file['Player']
|
| 423 |
+
flex_file['lock'] = np.where(flex_file['Player'].isin(lock_var2), 1, 0)
|
| 424 |
+
flex_file = flex_file[~flex_file['Player'].isin(avoid_var1)]
|
| 425 |
+
flex_file['Player'] = np.where(flex_file['roster'] == 'CPT', flex_file['Player'] + ' - CPT', flex_file['Player'] + ' - FLEX')
|
| 426 |
+
player_ids = flex_file.index
|
| 427 |
+
|
| 428 |
+
overall_players = flex_file[['Player']]
|
| 429 |
+
overall_players['player_var_add'] = flex_file.index
|
| 430 |
+
overall_players['player_var'] = 'player_vars_' + overall_players['player_var_add'].astype(str)
|
| 431 |
+
|
| 432 |
+
player_vars = pulp.LpVariable.dicts("player_vars", flex_file.index, 0, 1, pulp.LpInteger)
|
| 433 |
+
total_score = pulp.LpProblem("Fantasy_Points_Problem", pulp.LpMaximize)
|
| 434 |
+
player_match = dict(zip(overall_players['player_var'], overall_players['Player']))
|
| 435 |
+
player_index_match = dict(zip(overall_players['player_var'], overall_players['player_var_add']))
|
| 436 |
+
|
| 437 |
+
player_own = dict(zip(flex_file['Player'], flex_file['Proj DK Own%']))
|
| 438 |
+
player_team = dict(zip(flex_file['Player'], flex_file['Team']))
|
| 439 |
+
player_pos = dict(zip(flex_file['Player'], flex_file['Position']))
|
| 440 |
+
player_sal = dict(zip(flex_file['Player'], flex_file['Salary']))
|
| 441 |
+
player_proj = dict(zip(flex_file['Player'], flex_file['Median']))
|
| 442 |
+
|
| 443 |
+
obj_points = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 444 |
+
total_score += sum([player_vars[idx]*obj_points[idx] for idx in flex_file.index])
|
| 445 |
+
|
| 446 |
+
obj_points_max = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 447 |
+
obj_own_max = {idx: (flex_file['Proj DK Own%'][idx]) for idx in flex_file.index}
|
| 448 |
+
|
| 449 |
+
obj_salary = {idx: (flex_file['Salary'][idx]) for idx in flex_file.index}
|
| 450 |
+
total_score += pulp.lpSum([player_vars[idx]*obj_salary[idx] for idx in flex_file.index]) <= max_sal1
|
| 451 |
+
total_score += pulp.lpSum([player_vars[idx]*obj_salary[idx] for idx in flex_file.index]) >= min_sal1
|
| 452 |
+
|
| 453 |
+
if site_var1 == 'Draftkings':
|
| 454 |
|
| 455 |
+
for flex in flex_file['lock'].unique():
|
| 456 |
+
sub_idx = flex_file[flex_file['lock'] == 1].index
|
| 457 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == len(lock_var2)
|
| 458 |
+
|
| 459 |
+
for flex in flex_file['roster'].unique():
|
| 460 |
+
sub_idx = flex_file[flex_file['roster'] == "CPT"].index
|
| 461 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 1
|
| 462 |
+
|
| 463 |
+
for flex in flex_file['roster'].unique():
|
| 464 |
+
sub_idx = flex_file[flex_file['roster'] == "FLEX"].index
|
| 465 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
+
for playerid in player_ids:
|
| 468 |
+
total_score += pulp.lpSum([player_vars[i] for i in player_ids if
|
| 469 |
+
(flex_file['name_var'][i] == flex_file['name_var'][playerid])]) <= 1
|
| 470 |
+
|
| 471 |
+
elif site_var1 == 'Fanduel':
|
|
|
|
|
|
|
| 472 |
|
| 473 |
+
for flex in flex_file['lock'].unique():
|
| 474 |
+
sub_idx = flex_file[flex_file['lock'] == 1].index
|
| 475 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == len(lock_var2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
+
for flex in flex_file['Position'].unique():
|
| 478 |
+
sub_idx = flex_file[flex_file['Position'] != "Var"].index
|
| 479 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
+
for flex in flex_file['roster'].unique():
|
| 482 |
+
sub_idx = flex_file[flex_file['roster'] == "CPT"].index
|
| 483 |
+
total_score += pulp.lpSum([player_vars[idx] for idx in sub_idx]) == 1
|
| 484 |
+
|
| 485 |
+
for playerid in player_ids:
|
| 486 |
+
total_score += pulp.lpSum([player_vars[i] for i in player_ids if
|
| 487 |
+
(flex_file['name_var'][i] == flex_file['name_var'][playerid])]) <= 1
|
| 488 |
+
|
| 489 |
+
player_count = []
|
| 490 |
+
player_trim = []
|
| 491 |
+
lineup_list = []
|
| 492 |
+
|
| 493 |
+
if contest_var1 == 'Cash':
|
| 494 |
+
obj_points = {idx: (flex_file['Proj DK Own%'][idx]) for idx in flex_file.index}
|
| 495 |
+
total_score += sum([player_vars[idx]*obj_points[idx] for idx in flex_file.index])
|
| 496 |
+
total_score += pulp.lpSum([player_vars[idx]*obj_points[idx] for idx in flex_file.index]) <= max_own - .001
|
| 497 |
+
elif contest_var1 != 'Cash':
|
| 498 |
+
obj_points = {idx: (flex_file['Median'][idx]) for idx in flex_file.index}
|
| 499 |
+
total_score += sum([player_vars[idx]*obj_points[idx] for idx in flex_file.index])
|
| 500 |
+
total_score += pulp.lpSum([player_vars[idx]*obj_points[idx] for idx in flex_file.index]) <= max_proj - .01
|
| 501 |
+
if trim_var1 == 1:
|
| 502 |
+
total_score += pulp.lpSum([player_vars[idx]*obj_own_max[idx] for idx in flex_file.index]) <= max_own - .001
|
| 503 |
+
|
| 504 |
+
total_score.solve()
|
| 505 |
+
for v in total_score.variables():
|
| 506 |
+
if v.varValue > 0:
|
| 507 |
+
lineup_list.append(v.name)
|
| 508 |
+
df = pd.DataFrame(lineup_list)
|
| 509 |
+
df['Names'] = df[0].map(player_match)
|
| 510 |
+
df['Cost'] = df['Names'].map(player_sal)
|
| 511 |
+
df['Proj'] = df['Names'].map(player_proj)
|
| 512 |
+
df['Own'] = df['Names'].map(player_own)
|
| 513 |
+
total_cost = sum(df['Cost'])
|
| 514 |
+
total_own = sum(df['Own'])
|
| 515 |
+
total_proj = sum(df['Proj'])
|
| 516 |
+
lineup_raw = pd.DataFrame(lineup_list)
|
| 517 |
+
lineup_raw['Names'] = lineup_raw[0].map(player_match)
|
| 518 |
+
lineup_raw['value'] = lineup_raw[0].map(player_index_match)
|
| 519 |
+
lineup_final = lineup_raw.sort_values(by=['value'])
|
| 520 |
+
del lineup_final[lineup_final.columns[0]]
|
| 521 |
+
del lineup_final[lineup_final.columns[1]]
|
| 522 |
+
lineup_final['Team'] = lineup_final['Names'].map(player_team)
|
| 523 |
+
lineup_final['Position'] = lineup_final['Names'].map(player_pos)
|
| 524 |
+
lineup_final['Salary'] = lineup_final['Names'].map(player_sal)
|
| 525 |
+
lineup_final['Proj'] = lineup_final['Names'].map(player_proj)
|
| 526 |
+
lineup_final['Own'] = lineup_final['Names'].map(player_own)
|
| 527 |
+
lineup_final.loc['Column_Total'] = lineup_final.sum(numeric_only=True, axis=0)
|
| 528 |
+
lineup_final = lineup_final.reset_index(drop=True)
|
| 529 |
+
|
| 530 |
+
max_proj = total_proj
|
| 531 |
+
max_own = total_own
|
| 532 |
+
|
| 533 |
if site_var1 == 'Draftkings':
|
| 534 |
+
if len(lineup_final) == 7:
|
| 535 |
+
port_display = pd.DataFrame(lineup_final['Names'][:-1].values.reshape(1, -1))
|
| 536 |
+
|
| 537 |
+
port_display['Cost'] = total_cost
|
| 538 |
+
port_display['Proj'] = total_proj
|
| 539 |
+
port_display['Own'] = total_own
|
| 540 |
+
st.table(port_display)
|
| 541 |
+
|
| 542 |
+
portfolio = pd.concat([portfolio, port_display], ignore_index = True)
|
| 543 |
elif site_var1 == 'Fanduel':
|
| 544 |
+
if len(lineup_final) == 6:
|
| 545 |
+
port_display = pd.DataFrame(lineup_final['Names'][:-1].values.reshape(1, -1))
|
| 546 |
+
|
| 547 |
+
port_display['Cost'] = total_cost
|
| 548 |
+
port_display['Proj'] = total_proj
|
| 549 |
+
port_display['Own'] = total_own
|
| 550 |
+
st.table(port_display)
|
|
|
|
| 551 |
|
| 552 |
+
portfolio = pd.concat([portfolio, port_display], ignore_index = True)
|
| 553 |
+
|
| 554 |
+
x += 1
|
| 555 |
+
|
| 556 |
+
if site_var1 == 'Draftkings':
|
| 557 |
+
portfolio.rename(columns={0: "CPT", 1: "FLEX1", 2: "FLEX2", 3: "FLEX3", 4: "FLEX4", 5: "FLEX5"}, inplace = True)
|
| 558 |
+
elif site_var1 == 'Fanduel':
|
| 559 |
+
portfolio.rename(columns={0: "MVP", 1: "FLEX1", 2: "FLEX2", 3: "FLEX3", 4: "FLEX4"}, inplace = True)
|
| 560 |
+
portfolio = portfolio.dropna()
|
| 561 |
+
portfolio = portfolio.reset_index()
|
| 562 |
+
portfolio['Lineup_num'] = portfolio['index'] + 1
|
| 563 |
+
portfolio.rename(columns={'Lineup_num': "Lineup"}, inplace = True)
|
| 564 |
+
portfolio = portfolio.set_index('Lineup')
|
| 565 |
+
portfolio = portfolio.drop(columns=['index'])
|
| 566 |
+
st.session_state.portfolio = portfolio.drop_duplicates()
|
| 567 |
+
|
| 568 |
+
final_outcomes = portfolio
|
| 569 |
+
st.session_state.final_outcomes = portfolio
|
| 570 |
+
|
| 571 |
+
player_freq = pd.DataFrame(np.column_stack(np.unique(st.session_state.portfolio.iloc[:,0:6].values, return_counts=True)),
|
| 572 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 573 |
+
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 574 |
+
player_freq['Position'] = player_freq['Player'].map(player_pos)
|
| 575 |
+
player_freq['Salary'] = player_freq['Player'].map(player_sal)
|
| 576 |
+
player_freq['Proj Own'] = player_freq['Player'].map(player_own) / 100
|
| 577 |
+
player_freq['Exposure'] = player_freq['Freq']/(linenum_var1)
|
| 578 |
+
player_freq['Team'] = player_freq['Player'].map(player_team)
|
| 579 |
+
|
| 580 |
+
final_outcomes_export = pd.DataFrame()
|
| 581 |
+
split_portfolio = pd.DataFrame()
|
| 582 |
+
|
| 583 |
+
if site_var1 == 'Draftkings':
|
| 584 |
|
| 585 |
+
split_portfolio[['CPT', 'CPT_ID']] = final_outcomes.CPT.str.split("-", n=1, expand = True)
|
| 586 |
+
split_portfolio[['FLEX1', 'FLEX1_ID']] = final_outcomes.FLEX1.str.split("-", n=1, expand = True)
|
| 587 |
+
split_portfolio[['FLEX2', 'FLEX2_ID']] = final_outcomes.FLEX2.str.split("-", n=1, expand = True)
|
| 588 |
+
split_portfolio[['FLEX3', 'FLEX3_ID']] = final_outcomes.FLEX3.str.split("-", n=1, expand = True)
|
| 589 |
+
split_portfolio[['FLEX4', 'FLEX4_ID']] = final_outcomes.FLEX4.str.split("-", n=1, expand = True)
|
| 590 |
+
split_portfolio[['FLEX5', 'FLEX5_ID']] = final_outcomes.FLEX5.str.split("-", n=1, expand = True)
|
| 591 |
+
|
| 592 |
+
split_portfolio['CPT'] = split_portfolio['CPT'].str.strip()
|
| 593 |
+
split_portfolio['FLEX1'] = split_portfolio['FLEX1'].str.strip()
|
| 594 |
+
split_portfolio['FLEX2'] = split_portfolio['FLEX2'].str.strip()
|
| 595 |
+
split_portfolio['FLEX3'] = split_portfolio['FLEX3'].str.strip()
|
| 596 |
+
split_portfolio['FLEX4'] = split_portfolio['FLEX4'].str.strip()
|
| 597 |
+
split_portfolio['FLEX5'] = split_portfolio['FLEX5'].str.strip()
|
| 598 |
|
| 599 |
+
final_outcomes_export['CPT'] = split_portfolio['CPT']
|
| 600 |
+
final_outcomes_export['FLEX1'] = split_portfolio['FLEX1']
|
| 601 |
+
final_outcomes_export['FLEX2'] = split_portfolio['FLEX2']
|
| 602 |
+
final_outcomes_export['FLEX3'] = split_portfolio['FLEX3']
|
| 603 |
+
final_outcomes_export['FLEX4'] = split_portfolio['FLEX4']
|
| 604 |
+
final_outcomes_export['FLEX5'] = split_portfolio['FLEX5']
|
| 605 |
|
| 606 |
+
if sport_var1 == 'NFL':
|
| 607 |
+
final_outcomes_export['CPT'].replace(nfl_dk_id_dict, inplace=True)
|
| 608 |
+
final_outcomes_export['FLEX1'].replace(nfl_dk_id_dict, inplace=True)
|
| 609 |
+
final_outcomes_export['FLEX2'].replace(nfl_dk_id_dict, inplace=True)
|
| 610 |
+
final_outcomes_export['FLEX3'].replace(nfl_dk_id_dict, inplace=True)
|
| 611 |
+
final_outcomes_export['FLEX4'].replace(nfl_dk_id_dict, inplace=True)
|
| 612 |
+
final_outcomes_export['FLEX5'].replace(nfl_dk_id_dict, inplace=True)
|
| 613 |
+
elif sport_var1 == 'NBA':
|
| 614 |
+
final_outcomes_export['CPT'].replace(nba_dk_id_dict, inplace=True)
|
| 615 |
+
final_outcomes_export['FLEX1'].replace(nba_dk_id_dict, inplace=True)
|
| 616 |
+
final_outcomes_export['FLEX2'].replace(nba_dk_id_dict, inplace=True)
|
| 617 |
+
final_outcomes_export['FLEX3'].replace(nba_dk_id_dict, inplace=True)
|
| 618 |
+
final_outcomes_export['FLEX4'].replace(nba_dk_id_dict, inplace=True)
|
| 619 |
+
final_outcomes_export['FLEX5'].replace(nba_dk_id_dict, inplace=True)
|
| 620 |
+
final_outcomes_export['Salary'] = final_outcomes['Cost']
|
| 621 |
+
final_outcomes_export['Own'] = final_outcomes['Own']
|
| 622 |
+
final_outcomes_export['Proj'] = final_outcomes['Proj']
|
| 623 |
+
|
| 624 |
+
st.session_state.final_outcomes_export = final_outcomes_export.copy()
|
| 625 |
+
|
| 626 |
+
elif site_var1 == 'Fanduel':
|
| 627 |
+
|
| 628 |
+
split_portfolio[['MVP', 'CPT_ID']] = final_outcomes.MVP.str.split("-", n=1, expand = True)
|
| 629 |
+
split_portfolio[['FLEX1', 'FLEX1_ID']] = final_outcomes.FLEX1.str.split("-", n=1, expand = True)
|
| 630 |
+
split_portfolio[['FLEX2', 'FLEX2_ID']] = final_outcomes.FLEX2.str.split("-", n=1, expand = True)
|
| 631 |
+
split_portfolio[['FLEX3', 'FLEX3_ID']] = final_outcomes.FLEX3.str.split("-", n=1, expand = True)
|
| 632 |
+
split_portfolio[['FLEX4', 'FLEX4_ID']] = final_outcomes.FLEX4.str.split("-", n=1, expand = True)
|
| 633 |
+
|
| 634 |
+
split_portfolio['MVP'] = split_portfolio['MVP'].str.strip()
|
| 635 |
+
split_portfolio['FLEX1'] = split_portfolio['FLEX1'].str.strip()
|
| 636 |
+
split_portfolio['FLEX2'] = split_portfolio['FLEX2'].str.strip()
|
| 637 |
+
split_portfolio['FLEX3'] = split_portfolio['FLEX3'].str.strip()
|
| 638 |
+
split_portfolio['FLEX4'] = split_portfolio['FLEX4'].str.strip()
|
| 639 |
+
|
| 640 |
+
final_outcomes_export['MVP'] = split_portfolio['MVP']
|
| 641 |
+
final_outcomes_export['FLEX1'] = split_portfolio['FLEX1']
|
| 642 |
+
final_outcomes_export['FLEX2'] = split_portfolio['FLEX2']
|
| 643 |
+
final_outcomes_export['FLEX3'] = split_portfolio['FLEX3']
|
| 644 |
+
final_outcomes_export['FLEX4'] = split_portfolio['FLEX4']
|
| 645 |
+
|
| 646 |
+
if sport_var1 == 'NFL':
|
| 647 |
+
final_outcomes_export['MVP'].replace(nfl_fd_id_dict, inplace=True)
|
| 648 |
+
final_outcomes_export['FLEX1'].replace(nfl_fd_id_dict, inplace=True)
|
| 649 |
+
final_outcomes_export['FLEX2'].replace(nfl_fd_id_dict, inplace=True)
|
| 650 |
+
final_outcomes_export['FLEX3'].replace(nfl_fd_id_dict, inplace=True)
|
| 651 |
+
final_outcomes_export['FLEX4'].replace(nfl_fd_id_dict, inplace=True)
|
| 652 |
+
elif sport_var1 == 'NBA':
|
| 653 |
+
final_outcomes_export['MVP'].replace(nba_fd_id_dict, inplace=True)
|
| 654 |
+
final_outcomes_export['FLEX1'].replace(nba_fd_id_dict, inplace=True)
|
| 655 |
+
final_outcomes_export['FLEX2'].replace(nba_fd_id_dict, inplace=True)
|
| 656 |
+
final_outcomes_export['FLEX3'].replace(nba_fd_id_dict, inplace=True)
|
| 657 |
+
final_outcomes_export['FLEX4'].replace(nba_fd_id_dict, inplace=True)
|
| 658 |
+
final_outcomes_export['Salary'] = final_outcomes['Cost']
|
| 659 |
+
final_outcomes_export['Own'] = final_outcomes['Own']
|
| 660 |
+
final_outcomes_export['Proj'] = final_outcomes['Proj']
|
| 661 |
+
|
| 662 |
+
st.session_state.FD_final_outcomes_export = final_outcomes_export.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
|
| 664 |
+
st.session_state.player_freq = player_freq[['Player', 'Position', 'Team', 'Salary', 'Proj Own', 'Exposure']]
|
| 665 |
+
with display_container:
|
| 666 |
+
display_container = st.empty()
|
| 667 |
+
if 'display_baselines' in st.session_state:
|
| 668 |
+
st.dataframe(st.session_state.display_baselines.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 669 |
+
|
| 670 |
+
with display_dl_container:
|
| 671 |
+
display_dl_container = st.empty()
|
| 672 |
+
if 'export_baselines' in st.session_state:
|
|
|
|
|
|
|
|
|
|
| 673 |
st.download_button(
|
| 674 |
+
label="Export Projections",
|
| 675 |
+
data=convert_df_to_csv(st.session_state.export_baselines),
|
| 676 |
+
file_name='showdown_proj_export.csv',
|
| 677 |
mime='text/csv',
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
with optimize_container:
|
| 681 |
+
optimize_container = st.empty()
|
| 682 |
+
if 'final_outcomes' in st.session_state:
|
| 683 |
+
st.dataframe(st.session_state.final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
| 684 |
+
|
| 685 |
+
with download_container:
|
| 686 |
+
download_container = st.empty()
|
| 687 |
+
if site_var1 == 'Draftkings':
|
| 688 |
+
if 'final_outcomes_export' in st.session_state:
|
| 689 |
+
st.download_button(
|
| 690 |
+
label="Export Optimals",
|
| 691 |
+
data=convert_df_to_csv(st.session_state.final_outcomes_export),
|
| 692 |
+
file_name='NFL_optimals_export.csv',
|
| 693 |
+
mime='text/csv',
|
| 694 |
+
)
|
| 695 |
+
elif site_var1 == 'Fanduel':
|
| 696 |
+
if 'FD_final_outcomes_export' in st.session_state:
|
| 697 |
+
st.download_button(
|
| 698 |
+
label="Export Optimals",
|
| 699 |
+
data=convert_df_to_csv(st.session_state.FD_final_outcomes_export),
|
| 700 |
+
file_name='FD_NFL_optimals_export.csv',
|
| 701 |
+
mime='text/csv',
|
| 702 |
+
)
|
| 703 |
+
|
| 704 |
+
with freq_container:
|
| 705 |
+
freq_container = st.empty()
|
| 706 |
+
if 'player_freq' in st.session_state:
|
| 707 |
+
st.dataframe(st.session_state.player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(expose_format, precision=2), use_container_width = True)
|
| 708 |
+
|