James McCool
commited on
Commit
·
fdf735a
1
Parent(s):
7a8cb18
Refactor map_dict handling in app.py: replace local map_dict variable with session state reference for improved consistency and clarity in data processing across various operations.
Browse files
app.py
CHANGED
@@ -786,7 +786,7 @@ with tab2:
|
|
786 |
if site_var == 'Draftkings':
|
787 |
if type_var == 'Classic':
|
788 |
if sport_var == 'CS2':
|
789 |
-
map_dict = {
|
790 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
791 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
792 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
@@ -798,7 +798,7 @@ with tab2:
|
|
798 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
799 |
}
|
800 |
elif sport_var != 'CS2':
|
801 |
-
map_dict = {
|
802 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
803 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
804 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
@@ -810,7 +810,7 @@ with tab2:
|
|
810 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
811 |
}
|
812 |
elif type_var == 'Showdown':
|
813 |
-
map_dict = {
|
814 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
815 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
816 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
@@ -822,7 +822,7 @@ with tab2:
|
|
822 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
823 |
}
|
824 |
elif site_var == 'Fanduel':
|
825 |
-
map_dict = {
|
826 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
827 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
828 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
@@ -837,53 +837,53 @@ with tab2:
|
|
837 |
if sport_var == 'CS2':
|
838 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
839 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
840 |
-
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
841 |
-
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
842 |
axis=1
|
843 |
)
|
844 |
|
845 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
846 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(
|
847 |
-
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
848 |
-
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
849 |
axis=1
|
850 |
)
|
851 |
|
852 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
853 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(
|
854 |
-
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
855 |
-
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
856 |
axis=1
|
857 |
)
|
858 |
|
859 |
elif sport_var != 'CS2':
|
860 |
-
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
861 |
-
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
862 |
-
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
863 |
if stack_dict is not None:
|
864 |
st.session_state['working_frame']['Stack'] = st.session_state['working_frame'].index.map(stack_dict)
|
865 |
elif type_var == 'Showdown':
|
866 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
867 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
868 |
-
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
869 |
-
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
870 |
axis=1
|
871 |
)
|
872 |
|
873 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
874 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(
|
875 |
-
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
876 |
-
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
877 |
axis=1
|
878 |
)
|
879 |
|
880 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
881 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(
|
882 |
-
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
883 |
-
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
884 |
axis=1
|
885 |
)
|
886 |
-
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
887 |
if 'trimming_dict_maxes' not in st.session_state:
|
888 |
st.session_state['trimming_dict_maxes'] = {
|
889 |
'Own': st.session_state['working_frame']['Own'].max(),
|
@@ -917,7 +917,7 @@ with tab2:
|
|
917 |
|
918 |
submitted = st.form_submit_button("Submit")
|
919 |
if submitted:
|
920 |
-
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
921 |
if 'trimming_dict_maxes' not in st.session_state:
|
922 |
st.session_state['trimming_dict_maxes'] = {
|
923 |
'Own': st.session_state['working_frame']['Own'].max(),
|
@@ -952,7 +952,7 @@ with tab2:
|
|
952 |
|
953 |
submitted = st.form_submit_button("Submit")
|
954 |
if submitted:
|
955 |
-
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
956 |
if 'trimming_dict_maxes' not in st.session_state:
|
957 |
st.session_state['trimming_dict_maxes'] = {
|
958 |
'Own': st.session_state['working_frame']['Own'].max(),
|
|
|
786 |
if site_var == 'Draftkings':
|
787 |
if type_var == 'Classic':
|
788 |
if sport_var == 'CS2':
|
789 |
+
st.session_state['map_dict'] = {
|
790 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
791 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
792 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
|
|
798 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
799 |
}
|
800 |
elif sport_var != 'CS2':
|
801 |
+
st.session_state['map_dict'] = {
|
802 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
803 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
804 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
|
|
810 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
811 |
}
|
812 |
elif type_var == 'Showdown':
|
813 |
+
st.session_state['map_dict'] = {
|
814 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
815 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
816 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
|
|
822 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
823 |
}
|
824 |
elif site_var == 'Fanduel':
|
825 |
+
st.session_state['map_dict'] = {
|
826 |
'pos_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['position'])),
|
827 |
'team_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['team'])),
|
828 |
'salary_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['salary'])),
|
|
|
837 |
if sport_var == 'CS2':
|
838 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
839 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
840 |
+
lambda row: st.session_state['map_dict']['cpt_salary_map'].get(row.iloc[0], 0) +
|
841 |
+
sum(st.session_state['map_dict']['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
842 |
axis=1
|
843 |
)
|
844 |
|
845 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
846 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(
|
847 |
+
lambda row: st.session_state['map_dict']['cpt_proj_map'].get(row.iloc[0], 0) +
|
848 |
+
sum(st.session_state['map_dict']['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
849 |
axis=1
|
850 |
)
|
851 |
|
852 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
853 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(
|
854 |
+
lambda row: st.session_state['map_dict']['cpt_own_map'].get(row.iloc[0], 0) +
|
855 |
+
sum(st.session_state['map_dict']['own_map'].get(player, 0) for player in row.iloc[1:]),
|
856 |
axis=1
|
857 |
)
|
858 |
|
859 |
elif sport_var != 'CS2':
|
860 |
+
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['salary_map'].get(player, 0) for player in row), axis=1)
|
861 |
+
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['proj_map'].get(player, 0) for player in row), axis=1)
|
862 |
+
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(lambda row: sum(st.session_state['map_dict']['own_map'].get(player, 0) for player in row), axis=1)
|
863 |
if stack_dict is not None:
|
864 |
st.session_state['working_frame']['Stack'] = st.session_state['working_frame'].index.map(stack_dict)
|
865 |
elif type_var == 'Showdown':
|
866 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
867 |
st.session_state['working_frame']['salary'] = st.session_state['working_frame'].apply(
|
868 |
+
lambda row: st.session_state['map_dict']['cpt_salary_map'].get(row.iloc[0], 0) +
|
869 |
+
sum(st.session_state['map_dict']['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
870 |
axis=1
|
871 |
)
|
872 |
|
873 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
874 |
st.session_state['working_frame']['median'] = st.session_state['working_frame'].apply(
|
875 |
+
lambda row: st.session_state['map_dict']['cpt_proj_map'].get(row.iloc[0], 0) +
|
876 |
+
sum(st.session_state['map_dict']['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
877 |
axis=1
|
878 |
)
|
879 |
|
880 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
881 |
st.session_state['working_frame']['Own'] = st.session_state['working_frame'].apply(
|
882 |
+
lambda row: st.session_state['map_dict']['cpt_own_map'].get(row.iloc[0], 0) +
|
883 |
+
sum(st.session_state['map_dict']['own_map'].get(player, 0) for player in row.iloc[1:]),
|
884 |
axis=1
|
885 |
)
|
886 |
+
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var)
|
887 |
if 'trimming_dict_maxes' not in st.session_state:
|
888 |
st.session_state['trimming_dict_maxes'] = {
|
889 |
'Own': st.session_state['working_frame']['Own'].max(),
|
|
|
917 |
|
918 |
submitted = st.form_submit_button("Submit")
|
919 |
if submitted:
|
920 |
+
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var)
|
921 |
if 'trimming_dict_maxes' not in st.session_state:
|
922 |
st.session_state['trimming_dict_maxes'] = {
|
923 |
'Own': st.session_state['working_frame']['Own'].max(),
|
|
|
952 |
|
953 |
submitted = st.form_submit_button("Submit")
|
954 |
if submitted:
|
955 |
+
st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var)
|
956 |
if 'trimming_dict_maxes' not in st.session_state:
|
957 |
st.session_state['trimming_dict_maxes'] = {
|
958 |
'Own': st.session_state['working_frame']['Own'].max(),
|