James McCool
commited on
Commit
·
cdb988b
1
Parent(s):
34bb742
Refactor Sim_Winner_Frame processing in Streamlit app to drop 'unique_id' and 'win_count' columns, and enhance frequency calculations for player data, improving data handling and clarity.
Browse files- src/streamlit_app.py +44 -43
src/streamlit_app.py
CHANGED
|
@@ -624,7 +624,7 @@ if selected_tab == "Showdown Contest Sims":
|
|
| 624 |
|
| 625 |
# Sorting
|
| 626 |
st.session_state.Sim_Winner_Frame = Sim_Winner_Frame.sort_values(by=['win_count', 'GPP_Proj'], ascending= [False, False]).copy().drop_duplicates(subset='unique_id').head(100)
|
| 627 |
-
st.session_state.Sim_Winner_Frame.drop(columns='unique_id',
|
| 628 |
|
| 629 |
# Data Copying
|
| 630 |
st.session_state.Sim_Winner_Export = Sim_Winner_Frame.copy()
|
|
@@ -663,58 +663,59 @@ if selected_tab == "Showdown Contest Sims":
|
|
| 663 |
|
| 664 |
# Sorting
|
| 665 |
st.session_state.Sim_Winner_Frame = Sim_Winner_Frame.sort_values(by=['win_count', 'GPP_Proj'], ascending= [False, False]).copy().drop_duplicates(subset='unique_id').head(100)
|
| 666 |
-
st.session_state.Sim_Winner_Frame.drop(columns='unique_id',
|
| 667 |
|
| 668 |
# Data Copying
|
| 669 |
st.session_state.Sim_Winner_Export = Sim_Winner_Frame.copy()
|
|
|
|
| 670 |
|
| 671 |
# Data Copying
|
| 672 |
st.session_state.Sim_Winner_Display = Sim_Winner_Frame.copy()
|
| 673 |
freq_copy = st.session_state.Sim_Winner_Display
|
| 674 |
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
|
| 719 |
with st.container():
|
| 720 |
if st.button("Reset Sim", key='reset_sim'):
|
|
|
|
| 624 |
|
| 625 |
# Sorting
|
| 626 |
st.session_state.Sim_Winner_Frame = Sim_Winner_Frame.sort_values(by=['win_count', 'GPP_Proj'], ascending= [False, False]).copy().drop_duplicates(subset='unique_id').head(100)
|
| 627 |
+
st.session_state.Sim_Winner_Frame = st.session_state.Sim_Winner_Frame.drop(columns=['unique_id', 'win_count'])
|
| 628 |
|
| 629 |
# Data Copying
|
| 630 |
st.session_state.Sim_Winner_Export = Sim_Winner_Frame.copy()
|
|
|
|
| 663 |
|
| 664 |
# Sorting
|
| 665 |
st.session_state.Sim_Winner_Frame = Sim_Winner_Frame.sort_values(by=['win_count', 'GPP_Proj'], ascending= [False, False]).copy().drop_duplicates(subset='unique_id').head(100)
|
| 666 |
+
st.session_state.Sim_Winner_Frame = st.session_state.Sim_Winner_Frame.drop(columns=['unique_id', 'win_count'])
|
| 667 |
|
| 668 |
# Data Copying
|
| 669 |
st.session_state.Sim_Winner_Export = Sim_Winner_Frame.copy()
|
| 670 |
+
st.session_state.Sim_Winner_Export.iloc[:, 0:6] = st.session_state.Sim_Winner_Export.iloc[:, 0:6].apply(lambda x: x.map(export_id_dict))
|
| 671 |
|
| 672 |
# Data Copying
|
| 673 |
st.session_state.Sim_Winner_Display = Sim_Winner_Frame.copy()
|
| 674 |
freq_copy = st.session_state.Sim_Winner_Display
|
| 675 |
|
| 676 |
+
if sim_site_var2 == 'Draftkings':
|
| 677 |
+
freq_working = pd.DataFrame(np.column_stack(np.unique(freq_copy.iloc[:,0:6].values, return_counts=True)),
|
| 678 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 679 |
+
elif sim_site_var2 == 'Fanduel':
|
| 680 |
+
freq_working = pd.DataFrame(np.column_stack(np.unique(freq_copy.iloc[:,0:5].values, return_counts=True)),
|
| 681 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 682 |
+
freq_working['Freq'] = freq_working['Freq'].astype(int)
|
| 683 |
+
freq_working['Position'] = freq_working['Player'].map(maps_dict['Pos_map'])
|
| 684 |
+
freq_working['Salary'] = freq_working['Player'].map(maps_dict['Salary_map']) / 1.5
|
| 685 |
+
freq_working['Proj Own'] = freq_working['Player'].map(maps_dict['Own_map']) / 100
|
| 686 |
+
freq_working['Exposure'] = freq_working['Freq']/(1000)
|
| 687 |
+
freq_working['Edge'] = freq_working['Exposure'] - freq_working['Proj Own']
|
| 688 |
+
freq_working['Team'] = freq_working['Player'].map(maps_dict['Team_map'])
|
| 689 |
+
st.session_state.player_freq = freq_working.copy()
|
| 690 |
|
| 691 |
+
cpt_working = pd.DataFrame(np.column_stack(np.unique(freq_copy.iloc[:,0:1].values, return_counts=True)),
|
| 692 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 693 |
+
cpt_working['Freq'] = cpt_working['Freq'].astype(int)
|
| 694 |
+
cpt_working['Position'] = cpt_working['Player'].map(maps_dict['Pos_map'])
|
| 695 |
+
cpt_working['Salary'] = cpt_working['Player'].map(maps_dict['Salary_map'])
|
| 696 |
+
cpt_working['Proj Own'] = cpt_working['Player'].map(maps_dict['cpt_Own_map']) / 100
|
| 697 |
+
cpt_working['Exposure'] = cpt_working['Freq']/(1000)
|
| 698 |
+
cpt_working['Edge'] = cpt_working['Exposure'] - cpt_working['Proj Own']
|
| 699 |
+
cpt_working['Team'] = cpt_working['Player'].map(maps_dict['Team_map'])
|
| 700 |
+
st.session_state.sp_freq = cpt_working.copy()
|
| 701 |
+
|
| 702 |
+
flex_working = pd.DataFrame(np.column_stack(np.unique(freq_copy.iloc[:,1:6].values, return_counts=True)),
|
| 703 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 704 |
+
cpt_own_div = 600
|
| 705 |
+
flex_working['Freq'] = flex_working['Freq'].astype(int)
|
| 706 |
+
flex_working['Position'] = flex_working['Player'].map(maps_dict['Pos_map'])
|
| 707 |
+
flex_working['Salary'] = flex_working['Player'].map(maps_dict['Salary_map']) / 1.5
|
| 708 |
+
flex_working['Proj Own'] = (flex_working['Player'].map(maps_dict['Own_map']) / 100) - (flex_working['Player'].map(maps_dict['cpt_Own_map']) / 100)
|
| 709 |
+
flex_working['Exposure'] = flex_working['Freq']/(1000)
|
| 710 |
+
flex_working['Edge'] = flex_working['Exposure'] - flex_working['Proj Own']
|
| 711 |
+
flex_working['Team'] = flex_working['Player'].map(maps_dict['Team_map'])
|
| 712 |
+
st.session_state.flex_freq = flex_working.copy()
|
| 713 |
|
| 714 |
+
team_working = pd.DataFrame(np.column_stack(np.unique(freq_copy.iloc[:,8:9].values, return_counts=True)),
|
| 715 |
+
columns=['Player','Freq']).sort_values('Freq', ascending=False).reset_index(drop=True)
|
| 716 |
+
team_working['Freq'] = team_working['Freq'].astype(int)
|
| 717 |
+
team_working['Exposure'] = team_working['Freq']/(1000)
|
| 718 |
+
st.session_state.team_freq = team_working.copy()
|
| 719 |
|
| 720 |
with st.container():
|
| 721 |
if st.button("Reset Sim", key='reset_sim'):
|