Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,8 @@ team_roo_format = {'Top Score%': '{:.2%}','0 Runs': '{:.2%}', '1 Run': '{:.2%}',
|
|
| 43 |
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
| 44 |
'4x%': '{:.2%}','GPP%': '{:.2%}'}
|
| 45 |
|
|
|
|
|
|
|
| 46 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
| 47 |
|
| 48 |
@st.cache_resource(ttl=600)
|
|
@@ -97,10 +99,28 @@ def load_fd_player_projections_2():
|
|
| 97 |
|
| 98 |
return raw_display
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
dk_roo_raw = load_dk_player_projections()
|
| 101 |
dk_roo_raw_2 = load_dk_player_projections_2()
|
| 102 |
fd_roo_raw = load_fd_player_projections()
|
| 103 |
fd_roo_raw_2 = load_fd_player_projections_2()
|
|
|
|
| 104 |
|
| 105 |
@st.cache_data
|
| 106 |
def convert_df_to_csv(df):
|
|
@@ -143,6 +163,7 @@ with tab2:
|
|
| 143 |
dk_roo_raw_2 = load_dk_player_projections_2()
|
| 144 |
fd_roo_raw = load_fd_player_projections()
|
| 145 |
fd_roo_raw_2 = load_fd_player_projections_2()
|
|
|
|
| 146 |
slate_var2 = st.radio("Which data are you loading?", ('Paydirt (Main)', 'Paydirt (Secondary)', 'User'), key='slate_var2')
|
| 147 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 148 |
if slate_var2 == 'User':
|
|
@@ -589,6 +610,53 @@ with tab3:
|
|
| 589 |
portfolio = portfolio.drop_duplicates()
|
| 590 |
|
| 591 |
final_outcomes = portfolio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
|
| 593 |
with optimize_container:
|
| 594 |
optimize_container = st.empty()
|
|
@@ -600,3 +668,7 @@ with tab3:
|
|
| 600 |
file_name='MLB_optimals_export.csv',
|
| 601 |
mime='text/csv',
|
| 602 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
player_roo_format = {'Top_finish': '{:.2%}','Top_5_finish': '{:.2%}', 'Top_10_finish': '{:.2%}', '20+%': '{:.2%}', '2x%': '{:.2%}', '3x%': '{:.2%}',
|
| 44 |
'4x%': '{:.2%}','GPP%': '{:.2%}'}
|
| 45 |
|
| 46 |
+
expose_format = {'Proj Own': '{:.2%}','Exposure': '{:.2%}'}
|
| 47 |
+
|
| 48 |
all_dk_player_projections = 'https://docs.google.com/spreadsheets/d/1I_1Ve3F4tftgfLQQoRKOJ351XfEG48s36OxXUKxmgS8/edit#gid=1391856348'
|
| 49 |
|
| 50 |
@st.cache_resource(ttl=600)
|
|
|
|
| 99 |
|
| 100 |
return raw_display
|
| 101 |
|
| 102 |
+
@st.cache_resource(ttl = 3600)
|
| 103 |
+
def set_export_ids():
|
| 104 |
+
sh = gc.open_by_url(all_dk_player_projections)
|
| 105 |
+
worksheet = sh.worksheet('SD_Projections')
|
| 106 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 107 |
+
load_display.replace('', np.nan, inplace=True)
|
| 108 |
+
raw_display = load_display.dropna(subset=['Median'])
|
| 109 |
+
dk_ids = dict(zip(raw_display['Player'], raw_display['player_id']))
|
| 110 |
+
|
| 111 |
+
worksheet = sh.worksheet('FD_SD_Projections')
|
| 112 |
+
load_display = pd.DataFrame(worksheet.get_all_records())
|
| 113 |
+
load_display.replace('', np.nan, inplace=True)
|
| 114 |
+
raw_display = load_display.dropna(subset=['Median'])
|
| 115 |
+
fd_ids = dict(zip(raw_display['Player'], raw_display['player_id']))
|
| 116 |
+
|
| 117 |
+
return dk_ids, fd_ids
|
| 118 |
+
|
| 119 |
dk_roo_raw = load_dk_player_projections()
|
| 120 |
dk_roo_raw_2 = load_dk_player_projections_2()
|
| 121 |
fd_roo_raw = load_fd_player_projections()
|
| 122 |
fd_roo_raw_2 = load_fd_player_projections_2()
|
| 123 |
+
dkid_dict, fdid_dict = set_export_ids()
|
| 124 |
|
| 125 |
@st.cache_data
|
| 126 |
def convert_df_to_csv(df):
|
|
|
|
| 163 |
dk_roo_raw_2 = load_dk_player_projections_2()
|
| 164 |
fd_roo_raw = load_fd_player_projections()
|
| 165 |
fd_roo_raw_2 = load_fd_player_projections_2()
|
| 166 |
+
dkid_dict, fdid_dict = set_export_ids()
|
| 167 |
slate_var2 = st.radio("Which data are you loading?", ('Paydirt (Main)', 'Paydirt (Secondary)', 'User'), key='slate_var2')
|
| 168 |
site_var2 = st.radio("What table would you like to display?", ('Draftkings', 'Fanduel'), key='site_var2')
|
| 169 |
if slate_var2 == 'User':
|
|
|
|
| 610 |
portfolio = portfolio.drop_duplicates()
|
| 611 |
|
| 612 |
final_outcomes = portfolio
|
| 613 |
+
|
| 614 |
+
player_freq = pd.DataFrame(np.column_stack(np.unique(portfolio.iloc[:,0:8].values, return_counts=True)),
|
| 615 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 616 |
+
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
| 617 |
+
player_freq['Position'] = player_freq['Player'].map(player_pos)
|
| 618 |
+
player_freq['Salary'] = player_freq['Player'].map(player_sal)
|
| 619 |
+
player_freq['Proj Own'] = player_freq['Player'].map(player_own) / 100
|
| 620 |
+
player_freq['Exposure'] = player_freq['Freq']/(linenum_var1)
|
| 621 |
+
player_freq['Team'] = player_freq['Player'].map(player_team)
|
| 622 |
+
|
| 623 |
+
final_outcomes_export = pd.DataFrame()
|
| 624 |
+
|
| 625 |
+
if site_var1 == 'Draftkings':
|
| 626 |
+
final_outcomes_export['CPT'] = final_outcomes['CPT']
|
| 627 |
+
final_outcomes_export['FLEX1'] = final_outcomes['FLEX1']
|
| 628 |
+
final_outcomes_export['FLEX2'] = final_outcomes['FLEX2']
|
| 629 |
+
final_outcomes_export['FLEX3'] = final_outcomes['FLEX3']
|
| 630 |
+
final_outcomes_export['FLEX4'] = final_outcomes['FLEX4']
|
| 631 |
+
final_outcomes_export['FLEX5'] = final_outcomes['FLEX5']
|
| 632 |
+
final_outcomes_export['Salary'] = final_outcomes['Cost']
|
| 633 |
+
final_outcomes_export['Own'] = final_outcomes['Own']
|
| 634 |
+
final_outcomes_export['Proj'] = final_outcomes['Proj']
|
| 635 |
+
|
| 636 |
+
final_outcomes_export['CPT'].replace(dkid_dict, inplace=True)
|
| 637 |
+
final_outcomes_export['FLEX1'].replace(dkid_dict, inplace=True)
|
| 638 |
+
final_outcomes_export['FLEX2'].replace(dkid_dict, inplace=True)
|
| 639 |
+
final_outcomes_export['FLEX3'].replace(dkid_dict, inplace=True)
|
| 640 |
+
final_outcomes_export['FLEX4'].replace(dkid_dict, inplace=True)
|
| 641 |
+
final_outcomes_export['FLEX5'].replace(dkid_dict, inplace=True)
|
| 642 |
+
elif site_var1 == 'Fanduel':
|
| 643 |
+
final_outcomes_export['CPT'] = final_outcomes['CPT']
|
| 644 |
+
final_outcomes_export['FLEX1'] = final_outcomes['FLEX1']
|
| 645 |
+
final_outcomes_export['FLEX2'] = final_outcomes['FLEX2']
|
| 646 |
+
final_outcomes_export['FLEX3'] = final_outcomes['FLEX3']
|
| 647 |
+
final_outcomes_export['FLEX4'] = final_outcomes['FLEX4']
|
| 648 |
+
final_outcomes_export['Salary'] = final_outcomes['Cost']
|
| 649 |
+
final_outcomes_export['Own'] = final_outcomes['Own']
|
| 650 |
+
final_outcomes_export['Proj'] = final_outcomes['Proj']
|
| 651 |
+
|
| 652 |
+
final_outcomes_export['MVP'].replace(fdid_dict, inplace=True)
|
| 653 |
+
final_outcomes_export['FLEX1'].replace(fdid_dict, inplace=True)
|
| 654 |
+
final_outcomes_export['FLEX2'].replace(fdid_dict, inplace=True)
|
| 655 |
+
final_outcomes_export['FLEX3'].replace(fdid_dict, inplace=True)
|
| 656 |
+
final_outcomes_export['FLEX4'].replace(fdid_dict, inplace=True)
|
| 657 |
+
|
| 658 |
+
player_freq = player_freq[['Player', 'Position', 'Team', 'Salary', 'Proj Own', 'Exposure']]
|
| 659 |
+
player_freq = player_freq.set_index('Player')
|
| 660 |
|
| 661 |
with optimize_container:
|
| 662 |
optimize_container = st.empty()
|
|
|
|
| 668 |
file_name='MLB_optimals_export.csv',
|
| 669 |
mime='text/csv',
|
| 670 |
)
|
| 671 |
+
|
| 672 |
+
with st.container():
|
| 673 |
+
freq_container = st.empty()
|
| 674 |
+
st.dataframe(player_freq.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(expose_format, precision=2), use_container_width = True)
|