Spaces:
Running
Running
James McCool
commited on
Commit
·
81a398d
1
Parent(s):
b0517d0
Add new data export functionality in app.py: introduce a separate function for exporting data in Portfolio Manager format, enhance the full data export process with additional filtering options, and streamline the download buttons for both optimals and filtered exports, improving user experience and data accessibility.
Browse files
app.py
CHANGED
@@ -340,6 +340,11 @@ def convert_df(array):
|
|
340 |
array = pd.DataFrame(array, columns=column_names)
|
341 |
return array.to_csv().encode('utf-8')
|
342 |
|
|
|
|
|
|
|
|
|
|
|
343 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, sd_raw, dk_sd_raw, fd_sd_raw, timestamp = load_overall_stats('NBA')
|
344 |
salary_dict = dict(zip(roo_raw.Player, roo_raw.Salary))
|
345 |
id_dict = dict(zip(roo_raw.Player, roo_raw.player_ID))
|
@@ -569,43 +574,170 @@ with tab2:
|
|
569 |
elif site_var2 == 'Fanduel':
|
570 |
salary_min_var = st.number_input("Minimum salary used", min_value = 0, max_value = 40000, value = 39000, step = 100, key = 'salary_min_var')
|
571 |
salary_max_var = st.number_input("Maximum salary used", min_value = 0, max_value = 40000, value = 40000, step = 100, key = 'salary_max_var')
|
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 |
|
611 |
if site_var2 == 'Draftkings':
|
|
|
340 |
array = pd.DataFrame(array, columns=column_names)
|
341 |
return array.to_csv().encode('utf-8')
|
342 |
|
343 |
+
@st.cache_data
|
344 |
+
def convert_pm_df(array):
|
345 |
+
array = pd.DataFrame(array)
|
346 |
+
return array.to_csv().encode('utf-8')
|
347 |
+
|
348 |
dk_raw, fd_raw, dk_raw_sec, fd_raw_sec, roo_raw, sd_raw, dk_sd_raw, fd_sd_raw, timestamp = load_overall_stats('NBA')
|
349 |
salary_dict = dict(zip(roo_raw.Player, roo_raw.Salary))
|
350 |
id_dict = dict(zip(roo_raw.Player, roo_raw.player_ID))
|
|
|
574 |
elif site_var2 == 'Fanduel':
|
575 |
salary_min_var = st.number_input("Minimum salary used", min_value = 0, max_value = 40000, value = 39000, step = 100, key = 'salary_min_var')
|
576 |
salary_max_var = st.number_input("Maximum salary used", min_value = 0, max_value = 40000, value = 40000, step = 100, key = 'salary_max_var')
|
577 |
+
|
578 |
+
reg_dl_col, filtered_dl_col, blank_dl_col = st.columns([2, 2, 6])
|
579 |
+
with reg_dl_col:
|
580 |
+
if st.button("Prepare full data export", key='data_export'):
|
581 |
+
name_export = pd.DataFrame(st.session_state.working_seed.copy(), columns=column_names)
|
582 |
+
data_export = pd.DataFrame(st.session_state.working_seed.copy(), columns=column_names)
|
583 |
+
if site_var2 == 'Draftkings':
|
584 |
+
if slate_type_var1 == 'Regular':
|
585 |
+
if league_var == 'NBA':
|
586 |
+
map_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
587 |
+
elif league_var == 'WNBA':
|
588 |
+
map_columns = ['G1', 'G2', 'F1', 'F2', 'F3', 'UTIL']
|
589 |
+
elif slate_type_var1 == 'Showdown':
|
590 |
+
map_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
591 |
+
for col_idx in map_columns:
|
592 |
+
if slate_type_var1 == 'Regular':
|
593 |
+
data_export[col_idx] = data_export[col_idx].map(id_dict)
|
594 |
+
elif slate_type_var1 == 'Showdown':
|
595 |
+
data_export[col_idx] = data_export[col_idx].map(dk_id_dict_sd)
|
596 |
+
elif site_var2 == 'Fanduel':
|
597 |
+
if slate_type_var1 == 'Regular':
|
598 |
+
if league_var == 'NBA':
|
599 |
+
map_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C1', 'C2', 'UTIL']
|
600 |
+
elif league_var == 'WNBA':
|
601 |
+
map_columns = ['G1', 'G2', 'G3', 'F1', 'F2', 'F3', 'F4']
|
602 |
+
elif slate_type_var1 == 'Showdown':
|
603 |
+
map_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4']
|
604 |
+
for col_idx in map_columns:
|
605 |
+
if slate_type_var1 == 'Regular':
|
606 |
+
data_export[col_idx] = data_export[col_idx].map(id_dict)
|
607 |
+
elif slate_type_var1 == 'Showdown':
|
608 |
+
data_export[col_idx] = data_export[col_idx].map(fd_id_dict_sd)
|
609 |
+
reg_opt_col, pm_opt_col = st.columns(2)
|
610 |
+
with reg_opt_col:
|
611 |
+
st.download_button(
|
612 |
+
label="Export optimals set (IDs)",
|
613 |
+
data=convert_df(data_export),
|
614 |
+
file_name='NBA_optimals_export.csv',
|
615 |
+
mime='text/csv',
|
616 |
+
)
|
617 |
+
st.download_button(
|
618 |
+
label="Export optimals set (Names)",
|
619 |
+
data=convert_df(name_export),
|
620 |
+
file_name='NBA_optimals_export.csv',
|
621 |
+
mime='text/csv',
|
622 |
+
)
|
623 |
+
with pm_opt_col:
|
624 |
+
if site_var2 == 'Draftkings':
|
625 |
+
if slate_type_var1 == 'Regular':
|
626 |
+
data_export = data_export.set_index('SP1').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
627 |
+
elif slate_type_var1 == 'Showdown':
|
628 |
+
data_export = data_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
629 |
+
elif site_var2 == 'Fanduel':
|
630 |
+
if slate_type_var1 == 'Regular':
|
631 |
+
data_export = data_export.set_index('P').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
632 |
+
elif slate_type_var1 == 'Showdown':
|
633 |
+
data_export = data_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
634 |
+
st.download_button(
|
635 |
+
label="Portfolio Manager Export (IDs)",
|
636 |
+
data=convert_pm_df(data_export),
|
637 |
+
file_name='NBA_optimals_export.csv',
|
638 |
+
mime='text/csv',
|
639 |
+
)
|
640 |
+
|
641 |
+
if site_var2 == 'Draftkings':
|
642 |
+
if slate_type_var1 == 'Regular':
|
643 |
+
name_export = name_export.set_index('SP1').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
644 |
+
elif slate_type_var1 == 'Showdown':
|
645 |
+
name_export = name_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
646 |
+
elif site_var2 == 'Fanduel':
|
647 |
+
if slate_type_var1 == 'Regular':
|
648 |
+
name_export = name_export.set_index('P').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
649 |
+
elif slate_type_var1 == 'Showdown':
|
650 |
+
name_export = name_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
651 |
+
st.download_button(
|
652 |
+
label="Portfolio Manager Export (Names)",
|
653 |
+
data=convert_pm_df(name_export),
|
654 |
+
file_name='NBA_optimals_export.csv',
|
655 |
+
mime='text/csv',
|
656 |
+
)
|
657 |
+
with filtered_dl_col:
|
658 |
+
if st.button("Prepare full data export (Filtered)", key='data_export_filtered'):
|
659 |
+
name_export = pd.DataFrame(st.session_state.working_seed.copy(), columns=column_names)
|
660 |
+
data_export = pd.DataFrame(st.session_state.working_seed.copy(), columns=column_names)
|
661 |
+
if site_var2 == 'Draftkings':
|
662 |
+
if slate_type_var1 == 'Regular':
|
663 |
+
if league_var == 'NBA':
|
664 |
+
map_columns = ['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'FLEX']
|
665 |
+
elif league_var == 'WNBA':
|
666 |
+
map_columns = ['G1', 'G2', 'F1', 'F2', 'F3', 'UTIL']
|
667 |
+
elif slate_type_var1 == 'Showdown':
|
668 |
+
map_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4', 'FLEX5']
|
669 |
+
for col_idx in map_columns:
|
670 |
+
if slate_type_var1 == 'Regular':
|
671 |
+
data_export[col_idx] = data_export[col_idx].map(id_dict)
|
672 |
+
elif slate_type_var1 == 'Showdown':
|
673 |
+
data_export[col_idx] = data_export[col_idx].map(dk_id_dict_sd)
|
674 |
+
elif site_var2 == 'Fanduel':
|
675 |
+
if slate_type_var1 == 'Regular':
|
676 |
+
if league_var == 'NBA':
|
677 |
+
map_columns = ['PG1', 'PG2', 'SG1', 'SG2', 'SF1', 'SF2', 'PF1', 'PF2', 'C1', 'C2', 'UTIL']
|
678 |
+
elif league_var == 'WNBA':
|
679 |
+
map_columns = ['G1', 'G2', 'G3', 'F1', 'F2', 'F3', 'F4']
|
680 |
+
elif slate_type_var1 == 'Showdown':
|
681 |
+
map_columns = ['CPT', 'FLEX1', 'FLEX2', 'FLEX3', 'FLEX4']
|
682 |
+
for col_idx in map_columns:
|
683 |
+
if slate_type_var1 == 'Regular':
|
684 |
+
data_export[col_idx] = data_export[col_idx].map(id_dict)
|
685 |
+
elif slate_type_var1 == 'Showdown':
|
686 |
+
data_export[col_idx] = data_export[col_idx].map(fd_id_dict_sd)
|
687 |
+
data_export = data_export[data_export['salary'] >= salary_min_var]
|
688 |
+
data_export = data_export[data_export['salary'] <= salary_max_var]
|
689 |
+
|
690 |
+
name_export = name_export[name_export['salary'] >= salary_min_var]
|
691 |
+
name_export = name_export[name_export['salary'] <= salary_max_var]
|
692 |
|
693 |
+
reg_opt_col, pm_opt_col = st.columns(2)
|
694 |
+
with reg_opt_col:
|
695 |
+
st.download_button(
|
696 |
+
label="Export optimals set (IDs)",
|
697 |
+
data=convert_df(data_export),
|
698 |
+
file_name='NBA_optimals_export.csv',
|
699 |
+
mime='text/csv',
|
700 |
+
)
|
701 |
+
st.download_button(
|
702 |
+
label="Export optimals set (Names)",
|
703 |
+
data=convert_df(name_export),
|
704 |
+
file_name='NBA_optimals_export.csv',
|
705 |
+
mime='text/csv',
|
706 |
+
)
|
707 |
+
with pm_opt_col:
|
708 |
+
if site_var2 == 'Draftkings':
|
709 |
+
if slate_type_var1 == 'Regular':
|
710 |
+
data_export = data_export.set_index('SP1').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
711 |
+
elif slate_type_var1 == 'Showdown':
|
712 |
+
data_export = data_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
713 |
+
elif site_var2 == 'Fanduel':
|
714 |
+
if slate_type_var1 == 'Regular':
|
715 |
+
data_export = data_export.set_index('P').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
716 |
+
elif slate_type_var1 == 'Showdown':
|
717 |
+
data_export = data_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
718 |
+
st.download_button(
|
719 |
+
label="Portfolio Manager Export (IDs)",
|
720 |
+
data=convert_pm_df(data_export),
|
721 |
+
file_name='NBA_optimals_export.csv',
|
722 |
+
mime='text/csv',
|
723 |
+
)
|
724 |
+
|
725 |
+
if site_var2 == 'Draftkings':
|
726 |
+
if slate_type_var1 == 'Regular':
|
727 |
+
name_export = name_export.set_index('SP1').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
728 |
+
elif slate_type_var1 == 'Showdown':
|
729 |
+
name_export = name_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
730 |
+
elif site_var2 == 'Fanduel':
|
731 |
+
if slate_type_var1 == 'Regular':
|
732 |
+
name_export = name_export.set_index('P').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
733 |
+
elif slate_type_var1 == 'Showdown':
|
734 |
+
name_export = name_export.set_index('CPT').drop(columns=['salary', 'proj', 'Team', 'Team_count', 'Secondary', 'Secondary_count', 'Own'], axis=1)
|
735 |
+
st.download_button(
|
736 |
+
label="Portfolio Manager Export (Names)",
|
737 |
+
data=convert_pm_df(name_export),
|
738 |
+
file_name='NBA_optimals_export.csv',
|
739 |
+
mime='text/csv',
|
740 |
+
)
|
741 |
|
742 |
|
743 |
if site_var2 == 'Draftkings':
|