Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,6 +62,8 @@ def grab_baseline_stuff():
|
|
62 |
fd_raw_proj['Median'] = fd_raw_proj['Median'].astype(float)
|
63 |
dk_raw_proj['Own'] = dk_raw_proj['Median'].astype(float)
|
64 |
fd_raw_proj['Own'] = fd_raw_proj['Median'].astype(float)
|
|
|
|
|
65 |
dk_raw_proj['Name_ID'] = dk_raw_proj['Player'] + ' (' + dk_raw_proj['player_id'].str[:-2] + ')'
|
66 |
fd_raw_proj['Name_ID'] = fd_raw_proj['player_id'].str[:-2] + ':' + fd_raw_proj['Player']
|
67 |
dk_ids = dict(zip(dk_raw_proj['Player'], dk_raw_proj['Name_ID']))
|
@@ -164,19 +166,16 @@ with tab2:
|
|
164 |
raw_baselines = ownframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Line', 'PP Unit', 'Median', 'Own']]
|
165 |
raw_baselines = raw_baselines.sort_values(by='Median', ascending=False)
|
166 |
raw_baselines['lock'] = np.where(raw_baselines['Player'].isin(lock_var1), 1, 0)
|
167 |
-
st.session_state.
|
168 |
-
st.
|
169 |
-
|
170 |
-
label="Export Projections",
|
171 |
-
data=convert_df_to_csv(raw_baselines),
|
172 |
-
file_name='NFL_proj_export.csv',
|
173 |
-
mime='text/csv',
|
174 |
-
)
|
175 |
if st.button('Optimize'):
|
176 |
max_proj = 1000
|
177 |
max_own = 1000
|
178 |
total_proj = 0
|
179 |
total_own = 0
|
|
|
|
|
180 |
optimize_container = st.empty()
|
181 |
download_container = st.empty()
|
182 |
freq_container = st.empty()
|
@@ -504,6 +503,10 @@ with tab2:
|
|
504 |
portfolio = portfolio.set_index('Lineup')
|
505 |
portfolio = portfolio.drop(columns=['index'])
|
506 |
|
|
|
|
|
|
|
|
|
507 |
if site_var1 == 'Draftkings':
|
508 |
final_outcomes = portfolio[['C1', 'C2', 'W1', 'W2', 'W3', 'D1', 'D2', 'G', 'UTIL', 'Cost', 'Proj', 'Own']]
|
509 |
|
@@ -530,6 +533,8 @@ with tab2:
|
|
530 |
final_outcomes_export['D2'].replace(dkid_dict, inplace=True)
|
531 |
final_outcomes_export['G'].replace(dkid_dict, inplace=True)
|
532 |
final_outcomes_export['UTIL'].replace(dkid_dict, inplace=True)
|
|
|
|
|
533 |
elif site_var1 == 'Fanduel':
|
534 |
final_outcomes = portfolio[['C1', 'C2', 'W1', 'W2', 'D1', 'D2', 'UTIL1', 'UTIL2', 'G', 'Cost', 'Proj', 'Own']]
|
535 |
|
@@ -556,8 +561,10 @@ with tab2:
|
|
556 |
final_outcomes_export['UTIL1'].replace(dkid_dict, inplace=True)
|
557 |
final_outcomes_export['UTIL2'].replace(dkid_dict, inplace=True)
|
558 |
final_outcomes_export['G'].replace(dkid_dict, inplace=True)
|
|
|
|
|
559 |
|
560 |
-
player_freq = pd.DataFrame(np.column_stack(np.unique(portfolio.iloc[:,0:8].values, return_counts=True)),
|
561 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
562 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
563 |
player_freq['Position'] = player_freq['Player'].map(player_pos)
|
@@ -569,17 +576,46 @@ with tab2:
|
|
569 |
player_freq = player_freq[['Player', 'Position', 'Team', 'Salary', 'Proj Own', 'Exposure']]
|
570 |
player_freq = player_freq.set_index('Player')
|
571 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
572 |
with optimize_container:
|
573 |
-
|
574 |
-
|
|
|
|
|
575 |
with download_container:
|
576 |
download_container = st.empty()
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
583 |
with freq_container:
|
584 |
freq_container = st.empty()
|
585 |
-
|
|
|
|
62 |
fd_raw_proj['Median'] = fd_raw_proj['Median'].astype(float)
|
63 |
dk_raw_proj['Own'] = dk_raw_proj['Median'].astype(float)
|
64 |
fd_raw_proj['Own'] = fd_raw_proj['Median'].astype(float)
|
65 |
+
dk_raw_proj['player_id'] = dk_raw_proj['player_id'].astype(str)
|
66 |
+
fd_raw_proj['player_id'] = fd_raw_proj['player_id'].astype(str)
|
67 |
dk_raw_proj['Name_ID'] = dk_raw_proj['Player'] + ' (' + dk_raw_proj['player_id'].str[:-2] + ')'
|
68 |
fd_raw_proj['Name_ID'] = fd_raw_proj['player_id'].str[:-2] + ':' + fd_raw_proj['Player']
|
69 |
dk_ids = dict(zip(dk_raw_proj['Player'], dk_raw_proj['Name_ID']))
|
|
|
166 |
raw_baselines = ownframe[['Player', 'Salary', 'Position', 'Team', 'Opp', 'Line', 'PP Unit', 'Median', 'Own']]
|
167 |
raw_baselines = raw_baselines.sort_values(by='Median', ascending=False)
|
168 |
raw_baselines['lock'] = np.where(raw_baselines['Player'].isin(lock_var1), 1, 0)
|
169 |
+
st.session_state.export_baselines = raw_baselines
|
170 |
+
st.session_state.display_baselines = raw_baselines
|
171 |
+
|
|
|
|
|
|
|
|
|
|
|
172 |
if st.button('Optimize'):
|
173 |
max_proj = 1000
|
174 |
max_own = 1000
|
175 |
total_proj = 0
|
176 |
total_own = 0
|
177 |
+
display_container = st.empty()
|
178 |
+
display_dl_container = st.empty()
|
179 |
optimize_container = st.empty()
|
180 |
download_container = st.empty()
|
181 |
freq_container = st.empty()
|
|
|
503 |
portfolio = portfolio.set_index('Lineup')
|
504 |
portfolio = portfolio.drop(columns=['index'])
|
505 |
|
506 |
+
st.session_state.portfolio = portfolio.drop_duplicates()
|
507 |
+
|
508 |
+
st.session_state.final_outcomes = portfolio
|
509 |
+
|
510 |
if site_var1 == 'Draftkings':
|
511 |
final_outcomes = portfolio[['C1', 'C2', 'W1', 'W2', 'W3', 'D1', 'D2', 'G', 'UTIL', 'Cost', 'Proj', 'Own']]
|
512 |
|
|
|
533 |
final_outcomes_export['D2'].replace(dkid_dict, inplace=True)
|
534 |
final_outcomes_export['G'].replace(dkid_dict, inplace=True)
|
535 |
final_outcomes_export['UTIL'].replace(dkid_dict, inplace=True)
|
536 |
+
|
537 |
+
st.session_state.final_outcomes_export = final_outcomes_export.copy()
|
538 |
elif site_var1 == 'Fanduel':
|
539 |
final_outcomes = portfolio[['C1', 'C2', 'W1', 'W2', 'D1', 'D2', 'UTIL1', 'UTIL2', 'G', 'Cost', 'Proj', 'Own']]
|
540 |
|
|
|
561 |
final_outcomes_export['UTIL1'].replace(dkid_dict, inplace=True)
|
562 |
final_outcomes_export['UTIL2'].replace(dkid_dict, inplace=True)
|
563 |
final_outcomes_export['G'].replace(dkid_dict, inplace=True)
|
564 |
+
|
565 |
+
st.session_state.FD_final_outcomes_export = final_outcomes_export.copy()
|
566 |
|
567 |
+
player_freq = pd.DataFrame(np.column_stack(np.unique(st.session_state.portfolio.iloc[:,0:8].values, return_counts=True)),
|
568 |
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
569 |
player_freq['Freq'] = player_freq['Freq'].astype(int)
|
570 |
player_freq['Position'] = player_freq['Player'].map(player_pos)
|
|
|
576 |
player_freq = player_freq[['Player', 'Position', 'Team', 'Salary', 'Proj Own', 'Exposure']]
|
577 |
player_freq = player_freq.set_index('Player')
|
578 |
|
579 |
+
with display_container:
|
580 |
+
display_container = st.empty()
|
581 |
+
if 'display_baselines' in st.session_state:
|
582 |
+
st.dataframe(st.session_state.display_baselines.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
583 |
+
|
584 |
+
with display_dl_container:
|
585 |
+
display_dl_container = st.empty()
|
586 |
+
if 'export_baselines' in st.session_state:
|
587 |
+
st.download_button(
|
588 |
+
label="Export Projections",
|
589 |
+
data=convert_df_to_csv(st.session_state.export_baselines),
|
590 |
+
file_name='NHL_proj_export.csv',
|
591 |
+
mime='text/csv',
|
592 |
+
)
|
593 |
+
|
594 |
with optimize_container:
|
595 |
+
optimize_container = st.empty()
|
596 |
+
if 'final_outcomes' in st.session_state:
|
597 |
+
st.dataframe(st.session_state.final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
598 |
+
|
599 |
with download_container:
|
600 |
download_container = st.empty()
|
601 |
+
if site_var1 == 'Draftkings':
|
602 |
+
if 'final_outcomes_export' in st.session_state:
|
603 |
+
st.download_button(
|
604 |
+
label="Export Optimals",
|
605 |
+
data=convert_df_to_csv(st.session_state.final_outcomes_export),
|
606 |
+
file_name='NHL_optimals_export.csv',
|
607 |
+
mime='text/csv',
|
608 |
+
)
|
609 |
+
elif site_var1 == 'Fanduel':
|
610 |
+
if 'FD_final_outcomes_export' in st.session_state:
|
611 |
+
st.download_button(
|
612 |
+
label="Export Optimals",
|
613 |
+
data=convert_df_to_csv(st.session_state.FD_final_outcomes_export),
|
614 |
+
file_name='FD_NHL_optimals_export.csv',
|
615 |
+
mime='text/csv',
|
616 |
+
)
|
617 |
+
|
618 |
with freq_container:
|
619 |
freq_container = st.empty()
|
620 |
+
if 'player_freq' in st.session_state:
|
621 |
+
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)
|