Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
66b0ac2
1
Parent(s):
96799c9
Refactor tab2 layout with expanded display options and improved data management
Browse files
app.py
CHANGED
|
@@ -416,250 +416,252 @@ with tab1:
|
|
| 416 |
)
|
| 417 |
|
| 418 |
with tab2:
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
-
|
|
|
|
|
|
|
| 444 |
if player_var1 == 'Specific Players':
|
| 445 |
-
|
| 446 |
elif player_var1 == 'Full Slate':
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
elif
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
id_dict = dict(zip(ROO_slice.Player, ROO_slice.player_ID))
|
| 453 |
-
min_own = np.min(fd_lineups[:,15])
|
| 454 |
-
max_own = np.max(fd_lineups[:,15])
|
| 455 |
-
column_names = fd_columns
|
| 456 |
-
|
| 457 |
-
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1')
|
| 458 |
if player_var1 == 'Specific Players':
|
| 459 |
-
|
| 460 |
elif player_var1 == 'Full Slate':
|
| 461 |
-
player_var2 = fd_raw.Player.values.tolist()
|
| 462 |
-
|
| 463 |
-
if st.button("Prepare data export", key='data_export'):
|
| 464 |
-
data_export = st.session_state.working_seed.copy()
|
| 465 |
-
if site_var1 == 'Draftkings':
|
| 466 |
-
for col_idx in range(8):
|
| 467 |
-
data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
| 468 |
-
elif site_var1 == 'Fanduel':
|
| 469 |
-
for col_idx in range(9):
|
| 470 |
-
data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
| 471 |
-
st.download_button(
|
| 472 |
-
label="Export optimals set",
|
| 473 |
-
data=convert_df(data_export),
|
| 474 |
-
file_name='NBA_optimals_export.csv',
|
| 475 |
-
mime='text/csv',
|
| 476 |
-
)
|
| 477 |
-
with col2:
|
| 478 |
-
|
| 479 |
-
if site_var1 == 'Draftkings':
|
| 480 |
-
if 'working_seed' in st.session_state:
|
| 481 |
-
st.session_state.working_seed = st.session_state.working_seed
|
| 482 |
-
if player_var1 == 'Specific Players':
|
| 483 |
-
st.session_state.working_seed = st.session_state.working_seed[np.equal.outer(st.session_state.working_seed, player_var2).any(axis=1).all(axis=1)]
|
| 484 |
-
elif player_var1 == 'Full Slate':
|
| 485 |
-
st.session_state.working_seed = dk_lineups.copy()
|
| 486 |
-
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 487 |
-
elif 'working_seed' not in st.session_state:
|
| 488 |
st.session_state.working_seed = dk_lineups.copy()
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 504 |
-
elif 'working_seed' not in st.session_state:
|
| 505 |
st.session_state.working_seed = fd_lineups.copy()
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
if site_var1 == 'Draftkings':
|
| 526 |
-
st.session_state.
|
| 527 |
elif site_var1 == 'Fanduel':
|
| 528 |
-
st.session_state.
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
if 'working_seed' in st.session_state:
|
| 540 |
-
# Create a new dataframe with summary statistics
|
| 541 |
if site_var1 == 'Draftkings':
|
| 542 |
-
|
| 543 |
-
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
| 544 |
-
'Salary': [
|
| 545 |
-
np.min(st.session_state.working_seed[:,8]),
|
| 546 |
-
np.mean(st.session_state.working_seed[:,8]),
|
| 547 |
-
np.max(st.session_state.working_seed[:,8]),
|
| 548 |
-
np.std(st.session_state.working_seed[:,8])
|
| 549 |
-
],
|
| 550 |
-
'Proj': [
|
| 551 |
-
np.min(st.session_state.working_seed[:,9]),
|
| 552 |
-
np.mean(st.session_state.working_seed[:,9]),
|
| 553 |
-
np.max(st.session_state.working_seed[:,9]),
|
| 554 |
-
np.std(st.session_state.working_seed[:,9])
|
| 555 |
-
],
|
| 556 |
-
'Own': [
|
| 557 |
-
np.min(st.session_state.working_seed[:,14]),
|
| 558 |
-
np.mean(st.session_state.working_seed[:,14]),
|
| 559 |
-
np.max(st.session_state.working_seed[:,14]),
|
| 560 |
-
np.std(st.session_state.working_seed[:,14])
|
| 561 |
-
]
|
| 562 |
-
})
|
| 563 |
elif site_var1 == 'Fanduel':
|
| 564 |
-
|
| 565 |
-
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
| 566 |
-
'Salary': [
|
| 567 |
-
np.min(st.session_state.working_seed[:,9]),
|
| 568 |
-
np.mean(st.session_state.working_seed[:,9]),
|
| 569 |
-
np.max(st.session_state.working_seed[:,9]),
|
| 570 |
-
np.std(st.session_state.working_seed[:,9])
|
| 571 |
-
],
|
| 572 |
-
'Proj': [
|
| 573 |
-
np.min(st.session_state.working_seed[:,10]),
|
| 574 |
-
np.mean(st.session_state.working_seed[:,10]),
|
| 575 |
-
np.max(st.session_state.working_seed[:,10]),
|
| 576 |
-
np.std(st.session_state.working_seed[:,10])
|
| 577 |
-
],
|
| 578 |
-
'Own': [
|
| 579 |
-
np.min(st.session_state.working_seed[:,15]),
|
| 580 |
-
np.mean(st.session_state.working_seed[:,15]),
|
| 581 |
-
np.max(st.session_state.working_seed[:,15]),
|
| 582 |
-
np.std(st.session_state.working_seed[:,15])
|
| 583 |
-
]
|
| 584 |
-
})
|
| 585 |
-
|
| 586 |
-
# Set the index of the summary dataframe as the "Metric" column
|
| 587 |
-
summary_df = summary_df.set_index('Metric')
|
| 588 |
-
|
| 589 |
-
# Display the summary dataframe
|
| 590 |
-
st.subheader("Optimal Statistics")
|
| 591 |
-
st.dataframe(summary_df.style.format({
|
| 592 |
-
'Salary': '{:.2f}',
|
| 593 |
-
'Proj': '{:.2f}',
|
| 594 |
-
'Own': '{:.2f}'
|
| 595 |
-
}).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own']), use_container_width=True)
|
| 596 |
-
|
| 597 |
-
with st.container():
|
| 598 |
-
tab1, tab2 = st.tabs(["Display Frequency", "Seed Frame Frequency"])
|
| 599 |
-
with tab1:
|
| 600 |
-
if 'data_export_display' in st.session_state:
|
| 601 |
-
if site_var1 == 'Draftkings':
|
| 602 |
-
player_columns = st.session_state.data_export_display.iloc[:, :8]
|
| 603 |
-
elif site_var1 == 'Fanduel':
|
| 604 |
-
player_columns = st.session_state.data_export_display.iloc[:, :9]
|
| 605 |
-
|
| 606 |
-
# Flatten the DataFrame and count unique values
|
| 607 |
-
value_counts = player_columns.values.flatten().tolist()
|
| 608 |
-
value_counts = pd.Series(value_counts).value_counts()
|
| 609 |
-
|
| 610 |
-
percentages = (value_counts / lineup_num_var * 100).round(2)
|
| 611 |
-
|
| 612 |
-
# Create a DataFrame with the results
|
| 613 |
-
summary_df = pd.DataFrame({
|
| 614 |
-
'Player': value_counts.index,
|
| 615 |
-
'Salary': [salary_dict.get(player, player) for player in value_counts.index],
|
| 616 |
-
'Frequency': value_counts.values,
|
| 617 |
-
'Percentage': percentages.values
|
| 618 |
-
})
|
| 619 |
-
|
| 620 |
-
# Sort by frequency in descending order
|
| 621 |
-
summary_df = summary_df.sort_values('Frequency', ascending=False)
|
| 622 |
-
|
| 623 |
-
# Display the table
|
| 624 |
-
st.write("Player Frequency Table:")
|
| 625 |
-
st.dataframe(summary_df.style.format({'Percentage': '{:.2f}%'}, precision=2), height=500, use_container_width=True)
|
| 626 |
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
file_name='NBA_player_frequency.csv',
|
| 631 |
-
mime='text/csv',
|
| 632 |
-
)
|
| 633 |
-
with tab2:
|
| 634 |
-
if 'working_seed' in st.session_state:
|
| 635 |
-
if site_var1 == 'Draftkings':
|
| 636 |
-
player_columns = st.session_state.working_seed[:, :8]
|
| 637 |
-
elif site_var1 == 'Fanduel':
|
| 638 |
-
player_columns = st.session_state.working_seed[:, :9]
|
| 639 |
-
|
| 640 |
-
# Flatten the DataFrame and count unique values
|
| 641 |
-
value_counts = player_columns.flatten().tolist()
|
| 642 |
-
value_counts = pd.Series(value_counts).value_counts()
|
| 643 |
-
|
| 644 |
-
percentages = (value_counts / len(st.session_state.working_seed) * 100).round(2)
|
| 645 |
-
# Create a DataFrame with the results
|
| 646 |
-
summary_df = pd.DataFrame({
|
| 647 |
-
'Player': value_counts.index,
|
| 648 |
-
'Salary': [salary_dict.get(player, player) for player in value_counts.index],
|
| 649 |
-
'Frequency': value_counts.values,
|
| 650 |
-
'Percentage': percentages.values
|
| 651 |
-
})
|
| 652 |
-
|
| 653 |
-
# Sort by frequency in descending order
|
| 654 |
-
summary_df = summary_df.sort_values('Frequency', ascending=False)
|
| 655 |
-
|
| 656 |
-
# Display the table
|
| 657 |
-
st.write("Seed Frame Frequency Table:")
|
| 658 |
-
st.dataframe(summary_df.style.format({'Percentage': '{:.2f}%'}, precision=2), height=500, use_container_width=True)
|
| 659 |
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
)
|
| 417 |
|
| 418 |
with tab2:
|
| 419 |
+
if st.button("Load/Reset Data", key='reset2'):
|
| 420 |
+
st.cache_data.clear()
|
| 421 |
+
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, timestamp, roo_backlog = load_overall_stats()
|
| 422 |
+
dk_lineups = init_DK_lineups()
|
| 423 |
+
fd_lineups = init_FD_lineups()
|
| 424 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
| 425 |
+
for key in st.session_state.keys():
|
| 426 |
+
del st.session_state[key]
|
| 427 |
+
|
| 428 |
+
with st.expander("Display Options"):
|
| 429 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 430 |
+
with col1:
|
| 431 |
+
slate_var1 = st.radio("Which data are you loading?", ('Main Slate', 'Just the Main Slate'))
|
| 432 |
+
with col2:
|
| 433 |
+
site_var1 = st.radio("What site are you working with?", ('Draftkings', 'Fanduel'))
|
| 434 |
+
with col3:
|
| 435 |
+
lineup_num_var = st.number_input("How many lineups do you want to display?", min_value=1, max_value=1000, value=150, step=1)
|
| 436 |
+
with col4:
|
| 437 |
+
if site_var1 == 'Draftkings':
|
| 438 |
+
raw_baselines = dk_raw
|
| 439 |
+
ROO_slice = roo_raw[roo_raw['site'] == 'Draftkings']
|
| 440 |
+
id_dict = dict(zip(ROO_slice.Player, ROO_slice.player_ID))
|
| 441 |
+
# Get the minimum and maximum ownership values from dk_lineups
|
| 442 |
+
min_own = np.min(dk_lineups[:,14])
|
| 443 |
+
max_own = np.max(dk_lineups[:,14])
|
| 444 |
+
column_names = dk_columns
|
| 445 |
+
|
| 446 |
+
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1')
|
| 447 |
+
if player_var1 == 'Specific Players':
|
| 448 |
+
player_var2 = st.multiselect('Which players do you want?', options = dk_raw['Player'].unique())
|
| 449 |
+
elif player_var1 == 'Full Slate':
|
| 450 |
+
player_var2 = dk_raw.Player.values.tolist()
|
| 451 |
+
|
| 452 |
+
elif site_var1 == 'Fanduel':
|
| 453 |
+
raw_baselines = fd_raw
|
| 454 |
+
ROO_slice = roo_raw[roo_raw['site'] == 'Fanduel']
|
| 455 |
+
id_dict = dict(zip(ROO_slice.Player, ROO_slice.player_ID))
|
| 456 |
+
min_own = np.min(fd_lineups[:,15])
|
| 457 |
+
max_own = np.max(fd_lineups[:,15])
|
| 458 |
+
column_names = fd_columns
|
| 459 |
+
|
| 460 |
+
player_var1 = st.radio("Do you want a frame with specific Players?", ('Full Slate', 'Specific Players'), key='player_var1')
|
| 461 |
+
if player_var1 == 'Specific Players':
|
| 462 |
+
player_var2 = st.multiselect('Which players do you want?', options = fd_raw['Player'].unique())
|
| 463 |
+
elif player_var1 == 'Full Slate':
|
| 464 |
+
player_var2 = fd_raw.Player.values.tolist()
|
| 465 |
+
with col5:
|
| 466 |
+
if st.button("Prepare data export", key='data_export'):
|
| 467 |
+
data_export = st.session_state.working_seed.copy()
|
| 468 |
+
if site_var1 == 'Draftkings':
|
| 469 |
+
for col_idx in range(8):
|
| 470 |
+
data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
| 471 |
+
elif site_var1 == 'Fanduel':
|
| 472 |
+
for col_idx in range(9):
|
| 473 |
+
data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
|
| 474 |
+
st.download_button(
|
| 475 |
+
label="Export optimals set",
|
| 476 |
+
data=convert_df(data_export),
|
| 477 |
+
file_name='NBA_optimals_export.csv',
|
| 478 |
+
mime='text/csv',
|
| 479 |
+
)
|
| 480 |
|
| 481 |
+
if site_var1 == 'Draftkings':
|
| 482 |
+
if 'working_seed' in st.session_state:
|
| 483 |
+
st.session_state.working_seed = st.session_state.working_seed
|
| 484 |
if player_var1 == 'Specific Players':
|
| 485 |
+
st.session_state.working_seed = st.session_state.working_seed[np.equal.outer(st.session_state.working_seed, player_var2).any(axis=1).all(axis=1)]
|
| 486 |
elif player_var1 == 'Full Slate':
|
| 487 |
+
st.session_state.working_seed = dk_lineups.copy()
|
| 488 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 489 |
+
elif 'working_seed' not in st.session_state:
|
| 490 |
+
st.session_state.working_seed = dk_lineups.copy()
|
| 491 |
+
st.session_state.working_seed = st.session_state.working_seed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
if player_var1 == 'Specific Players':
|
| 493 |
+
st.session_state.working_seed = st.session_state.working_seed[np.equal.outer(st.session_state.working_seed, player_var2).any(axis=1).all(axis=1)]
|
| 494 |
elif player_var1 == 'Full Slate':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
st.session_state.working_seed = dk_lineups.copy()
|
| 496 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 497 |
+
|
| 498 |
+
elif site_var1 == 'Fanduel':
|
| 499 |
+
if 'working_seed' in st.session_state:
|
| 500 |
+
st.session_state.working_seed = st.session_state.working_seed
|
| 501 |
+
if player_var1 == 'Specific Players':
|
| 502 |
+
st.session_state.working_seed = st.session_state.working_seed[np.equal.outer(st.session_state.working_seed, player_var2).any(axis=1).all(axis=1)]
|
| 503 |
+
elif player_var1 == 'Full Slate':
|
| 504 |
+
st.session_state.working_seed = fd_lineups.copy()
|
| 505 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 506 |
+
elif 'working_seed' not in st.session_state:
|
| 507 |
+
st.session_state.working_seed = fd_lineups.copy()
|
| 508 |
+
st.session_state.working_seed = st.session_state.working_seed
|
| 509 |
+
if player_var1 == 'Specific Players':
|
| 510 |
+
st.session_state.working_seed = st.session_state.working_seed[np.equal.outer(st.session_state.working_seed, player_var2).any(axis=1).all(axis=1)]
|
| 511 |
+
elif player_var1 == 'Full Slate':
|
| 512 |
+
st.session_state.working_seed = fd_lineups.copy()
|
| 513 |
+
st.session_state.data_export_display = pd.DataFrame(st.session_state.working_seed[0:lineup_num_var], columns=column_names)
|
| 514 |
+
|
| 515 |
+
export_file = st.session_state.data_export_display.copy()
|
| 516 |
+
if site_var1 == 'Draftkings':
|
| 517 |
+
for col_idx in range(8):
|
| 518 |
+
export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
| 519 |
+
elif site_var1 == 'Fanduel':
|
| 520 |
+
for col_idx in range(9):
|
| 521 |
+
export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(id_dict)
|
| 522 |
|
| 523 |
+
with st.container():
|
| 524 |
+
if st.button("Reset Optimals", key='reset3'):
|
| 525 |
+
for key in st.session_state.keys():
|
| 526 |
+
del st.session_state[key]
|
| 527 |
+
if site_var1 == 'Draftkings':
|
| 528 |
+
st.session_state.working_seed = dk_lineups.copy()
|
| 529 |
+
elif site_var1 == 'Fanduel':
|
|
|
|
|
|
|
| 530 |
st.session_state.working_seed = fd_lineups.copy()
|
| 531 |
+
if 'data_export_display' in st.session_state:
|
| 532 |
+
st.dataframe(st.session_state.data_export_display.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height=500, use_container_width = True)
|
| 533 |
+
st.download_button(
|
| 534 |
+
label="Export display optimals",
|
| 535 |
+
data=convert_df(export_file),
|
| 536 |
+
file_name='NBA_display_optimals.csv',
|
| 537 |
+
mime='text/csv',
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
with st.container():
|
| 541 |
+
if 'working_seed' in st.session_state:
|
| 542 |
+
# Create a new dataframe with summary statistics
|
| 543 |
+
if site_var1 == 'Draftkings':
|
| 544 |
+
summary_df = pd.DataFrame({
|
| 545 |
+
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
| 546 |
+
'Salary': [
|
| 547 |
+
np.min(st.session_state.working_seed[:,8]),
|
| 548 |
+
np.mean(st.session_state.working_seed[:,8]),
|
| 549 |
+
np.max(st.session_state.working_seed[:,8]),
|
| 550 |
+
np.std(st.session_state.working_seed[:,8])
|
| 551 |
+
],
|
| 552 |
+
'Proj': [
|
| 553 |
+
np.min(st.session_state.working_seed[:,9]),
|
| 554 |
+
np.mean(st.session_state.working_seed[:,9]),
|
| 555 |
+
np.max(st.session_state.working_seed[:,9]),
|
| 556 |
+
np.std(st.session_state.working_seed[:,9])
|
| 557 |
+
],
|
| 558 |
+
'Own': [
|
| 559 |
+
np.min(st.session_state.working_seed[:,14]),
|
| 560 |
+
np.mean(st.session_state.working_seed[:,14]),
|
| 561 |
+
np.max(st.session_state.working_seed[:,14]),
|
| 562 |
+
np.std(st.session_state.working_seed[:,14])
|
| 563 |
+
]
|
| 564 |
+
})
|
| 565 |
+
elif site_var1 == 'Fanduel':
|
| 566 |
+
summary_df = pd.DataFrame({
|
| 567 |
+
'Metric': ['Min', 'Average', 'Max', 'STDdev'],
|
| 568 |
+
'Salary': [
|
| 569 |
+
np.min(st.session_state.working_seed[:,9]),
|
| 570 |
+
np.mean(st.session_state.working_seed[:,9]),
|
| 571 |
+
np.max(st.session_state.working_seed[:,9]),
|
| 572 |
+
np.std(st.session_state.working_seed[:,9])
|
| 573 |
+
],
|
| 574 |
+
'Proj': [
|
| 575 |
+
np.min(st.session_state.working_seed[:,10]),
|
| 576 |
+
np.mean(st.session_state.working_seed[:,10]),
|
| 577 |
+
np.max(st.session_state.working_seed[:,10]),
|
| 578 |
+
np.std(st.session_state.working_seed[:,10])
|
| 579 |
+
],
|
| 580 |
+
'Own': [
|
| 581 |
+
np.min(st.session_state.working_seed[:,15]),
|
| 582 |
+
np.mean(st.session_state.working_seed[:,15]),
|
| 583 |
+
np.max(st.session_state.working_seed[:,15]),
|
| 584 |
+
np.std(st.session_state.working_seed[:,15])
|
| 585 |
+
]
|
| 586 |
+
})
|
| 587 |
+
|
| 588 |
+
# Set the index of the summary dataframe as the "Metric" column
|
| 589 |
+
summary_df = summary_df.set_index('Metric')
|
| 590 |
+
|
| 591 |
+
# Display the summary dataframe
|
| 592 |
+
st.subheader("Optimal Statistics")
|
| 593 |
+
st.dataframe(summary_df.style.format({
|
| 594 |
+
'Salary': '{:.2f}',
|
| 595 |
+
'Proj': '{:.2f}',
|
| 596 |
+
'Own': '{:.2f}'
|
| 597 |
+
}).background_gradient(cmap='RdYlGn', axis=0, subset=['Salary', 'Proj', 'Own']), use_container_width=True)
|
| 598 |
+
|
| 599 |
+
with st.container():
|
| 600 |
+
tab1, tab2 = st.tabs(["Display Frequency", "Seed Frame Frequency"])
|
| 601 |
+
with tab1:
|
| 602 |
+
if 'data_export_display' in st.session_state:
|
| 603 |
if site_var1 == 'Draftkings':
|
| 604 |
+
player_columns = st.session_state.data_export_display.iloc[:, :8]
|
| 605 |
elif site_var1 == 'Fanduel':
|
| 606 |
+
player_columns = st.session_state.data_export_display.iloc[:, :9]
|
| 607 |
+
|
| 608 |
+
# Flatten the DataFrame and count unique values
|
| 609 |
+
value_counts = player_columns.values.flatten().tolist()
|
| 610 |
+
value_counts = pd.Series(value_counts).value_counts()
|
| 611 |
+
|
| 612 |
+
percentages = (value_counts / lineup_num_var * 100).round(2)
|
| 613 |
+
|
| 614 |
+
# Create a DataFrame with the results
|
| 615 |
+
summary_df = pd.DataFrame({
|
| 616 |
+
'Player': value_counts.index,
|
| 617 |
+
'Salary': [salary_dict.get(player, player) for player in value_counts.index],
|
| 618 |
+
'Frequency': value_counts.values,
|
| 619 |
+
'Percentage': percentages.values
|
| 620 |
+
})
|
| 621 |
+
|
| 622 |
+
# Sort by frequency in descending order
|
| 623 |
+
summary_df = summary_df.sort_values('Frequency', ascending=False)
|
| 624 |
+
|
| 625 |
+
# Display the table
|
| 626 |
+
st.write("Player Frequency Table:")
|
| 627 |
+
st.dataframe(summary_df.style.format({'Percentage': '{:.2f}%'}, precision=2), height=500, use_container_width=True)
|
| 628 |
+
|
| 629 |
+
st.download_button(
|
| 630 |
+
label="Export player frequency",
|
| 631 |
+
data=convert_df_to_csv(summary_df),
|
| 632 |
+
file_name='NBA_player_frequency.csv',
|
| 633 |
+
mime='text/csv',
|
| 634 |
+
)
|
| 635 |
+
with tab2:
|
| 636 |
if 'working_seed' in st.session_state:
|
|
|
|
| 637 |
if site_var1 == 'Draftkings':
|
| 638 |
+
player_columns = st.session_state.working_seed[:, :8]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
elif site_var1 == 'Fanduel':
|
| 640 |
+
player_columns = st.session_state.working_seed[:, :9]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
|
| 642 |
+
# Flatten the DataFrame and count unique values
|
| 643 |
+
value_counts = player_columns.flatten().tolist()
|
| 644 |
+
value_counts = pd.Series(value_counts).value_counts()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
|
| 646 |
+
percentages = (value_counts / len(st.session_state.working_seed) * 100).round(2)
|
| 647 |
+
# Create a DataFrame with the results
|
| 648 |
+
summary_df = pd.DataFrame({
|
| 649 |
+
'Player': value_counts.index,
|
| 650 |
+
'Salary': [salary_dict.get(player, player) for player in value_counts.index],
|
| 651 |
+
'Frequency': value_counts.values,
|
| 652 |
+
'Percentage': percentages.values
|
| 653 |
+
})
|
| 654 |
+
|
| 655 |
+
# Sort by frequency in descending order
|
| 656 |
+
summary_df = summary_df.sort_values('Frequency', ascending=False)
|
| 657 |
+
|
| 658 |
+
# Display the table
|
| 659 |
+
st.write("Seed Frame Frequency Table:")
|
| 660 |
+
st.dataframe(summary_df.style.format({'Percentage': '{:.2f}%'}, precision=2), height=500, use_container_width=True)
|
| 661 |
+
|
| 662 |
+
st.download_button(
|
| 663 |
+
label="Export seed frame frequency",
|
| 664 |
+
data=convert_df_to_csv(summary_df),
|
| 665 |
+
file_name='NBA_seed_frame_frequency.csv',
|
| 666 |
+
mime='text/csv',
|
| 667 |
+
)
|