James McCool
commited on
Commit
·
e16cb76
1
Parent(s):
2a79e13
Refactor portfolio calculation logic in app.py: streamline salary, median, and ownership computations for Classic and Showdown types, ensuring accurate data handling and improved clarity in the code structure.
Browse files
app.py
CHANGED
|
@@ -830,37 +830,8 @@ with tab2:
|
|
| 830 |
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
| 831 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
| 832 |
}
|
| 833 |
-
if '
|
| 834 |
-
if
|
| 835 |
-
if sport_var == 'CS2':
|
| 836 |
-
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
| 837 |
-
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 838 |
-
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
| 839 |
-
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
| 840 |
-
axis=1
|
| 841 |
-
)
|
| 842 |
-
|
| 843 |
-
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
| 844 |
-
st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(
|
| 845 |
-
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
| 846 |
-
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
| 847 |
-
axis=1
|
| 848 |
-
)
|
| 849 |
-
|
| 850 |
-
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
| 851 |
-
st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(
|
| 852 |
-
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
| 853 |
-
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
| 854 |
-
axis=1
|
| 855 |
-
)
|
| 856 |
-
|
| 857 |
-
elif sport_var != 'CS2':
|
| 858 |
-
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
| 859 |
-
st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
| 860 |
-
st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
| 861 |
-
if stack_dict is not None:
|
| 862 |
-
st.session_state['portfolio']['Stack'] = st.session_state['portfolio'].index.map(stack_dict)
|
| 863 |
-
elif type_var == 'Showdown':
|
| 864 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
| 865 |
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 866 |
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
|
@@ -881,6 +852,34 @@ with tab2:
|
|
| 881 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
| 882 |
axis=1
|
| 883 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
col1, col2 = st.columns([2, 8])
|
| 885 |
with col1:
|
| 886 |
if 'trimming_dict_maxes' not in st.session_state:
|
|
|
|
| 830 |
'cpt_proj_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['median'] * 1.5)),
|
| 831 |
'cpt_own_map':dict(zip(st.session_state['projections_df']['player_names'], st.session_state['projections_df']['captain ownership']))
|
| 832 |
}
|
| 833 |
+
if type_var == 'Classic':
|
| 834 |
+
if sport_var == 'CS2':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 835 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
| 836 |
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 837 |
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
|
|
|
| 852 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
| 853 |
axis=1
|
| 854 |
)
|
| 855 |
+
|
| 856 |
+
elif sport_var != 'CS2':
|
| 857 |
+
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
| 858 |
+
st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
| 859 |
+
st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
| 860 |
+
if stack_dict is not None:
|
| 861 |
+
st.session_state['portfolio']['Stack'] = st.session_state['portfolio'].index.map(stack_dict)
|
| 862 |
+
elif type_var == 'Showdown':
|
| 863 |
+
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
| 864 |
+
st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 865 |
+
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
| 866 |
+
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
| 867 |
+
axis=1
|
| 868 |
+
)
|
| 869 |
+
|
| 870 |
+
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
| 871 |
+
st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(
|
| 872 |
+
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
| 873 |
+
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
| 874 |
+
axis=1
|
| 875 |
+
)
|
| 876 |
+
|
| 877 |
+
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
| 878 |
+
st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(
|
| 879 |
+
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
| 880 |
+
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
| 881 |
+
axis=1
|
| 882 |
+
)
|
| 883 |
col1, col2 = st.columns([2, 8])
|
| 884 |
with col1:
|
| 885 |
if 'trimming_dict_maxes' not in st.session_state:
|