James McCool
commited on
Commit
·
2c44968
1
Parent(s):
2df0c40
Update app.py to switch from portfolio to Contest state for data calculations
Browse files- Changed references from 'portfolio' to 'Contest' in session state to align with the new data structure.
- Updated calculations for salary, median, and ownership metrics based on the selected game type (Classic or Showdown).
- Adjusted the display logic to reflect the changes in data handling, ensuring accurate representation of contest data.
app.py
CHANGED
@@ -82,7 +82,7 @@ with tab1:
|
|
82 |
with tab2:
|
83 |
if st.button('Clear data', key='reset3'):
|
84 |
st.session_state.clear()
|
85 |
-
if '
|
86 |
col1, col2 = st.columns([1, 8])
|
87 |
excluded_cols = ['BaseName', 'EntryCount']
|
88 |
with col1:
|
@@ -109,26 +109,26 @@ with tab2:
|
|
109 |
}
|
110 |
|
111 |
if type_var == 'Classic':
|
112 |
-
st.session_state['
|
113 |
-
st.session_state['
|
114 |
-
st.session_state['
|
115 |
elif type_var == 'Showdown':
|
116 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
117 |
-
st.session_state['
|
118 |
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
119 |
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
120 |
axis=1
|
121 |
)
|
122 |
|
123 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
124 |
-
st.session_state['
|
125 |
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
126 |
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
127 |
axis=1
|
128 |
)
|
129 |
|
130 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
131 |
-
st.session_state['
|
132 |
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
133 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
134 |
axis=1
|
@@ -137,7 +137,7 @@ with tab2:
|
|
137 |
with col2:
|
138 |
# Display the paginated dataframe first
|
139 |
st.dataframe(
|
140 |
-
st.session_state['
|
141 |
.background_gradient(axis=0)
|
142 |
.background_gradient(cmap='RdYlGn')
|
143 |
.background_gradient(cmap='RdYlGn_r', subset=['Finish_percentile', 'Own', 'Dupes'])
|
|
|
82 |
with tab2:
|
83 |
if st.button('Clear data', key='reset3'):
|
84 |
st.session_state.clear()
|
85 |
+
if 'Contest' in st.session_state and 'projections_df' in st.session_state:
|
86 |
col1, col2 = st.columns([1, 8])
|
87 |
excluded_cols = ['BaseName', 'EntryCount']
|
88 |
with col1:
|
|
|
109 |
}
|
110 |
|
111 |
if type_var == 'Classic':
|
112 |
+
st.session_state['Contest']['salary'] = st.session_state['Contest'].apply(lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row), axis=1)
|
113 |
+
st.session_state['Contest']['median'] = st.session_state['Contest'].apply(lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row), axis=1)
|
114 |
+
st.session_state['Contest']['Own'] = st.session_state['Contest'].apply(lambda row: sum(map_dict['own_map'].get(player, 0) for player in row), axis=1)
|
115 |
elif type_var == 'Showdown':
|
116 |
# Calculate salary (CPT uses cpt_salary_map, others use salary_map)
|
117 |
+
st.session_state['Contest']['salary'] = st.session_state['Contest'].apply(
|
118 |
lambda row: map_dict['cpt_salary_map'].get(row.iloc[0], 0) +
|
119 |
sum(map_dict['salary_map'].get(player, 0) for player in row.iloc[1:]),
|
120 |
axis=1
|
121 |
)
|
122 |
|
123 |
# Calculate median (CPT uses cpt_proj_map, others use proj_map)
|
124 |
+
st.session_state['Contest']['median'] = st.session_state['Contest'].apply(
|
125 |
lambda row: map_dict['cpt_proj_map'].get(row.iloc[0], 0) +
|
126 |
sum(map_dict['proj_map'].get(player, 0) for player in row.iloc[1:]),
|
127 |
axis=1
|
128 |
)
|
129 |
|
130 |
# Calculate ownership (CPT uses cpt_own_map, others use own_map)
|
131 |
+
st.session_state['Contest']['Own'] = st.session_state['Contest'].apply(
|
132 |
lambda row: map_dict['cpt_own_map'].get(row.iloc[0], 0) +
|
133 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
134 |
axis=1
|
|
|
137 |
with col2:
|
138 |
# Display the paginated dataframe first
|
139 |
st.dataframe(
|
140 |
+
st.session_state['Contest'].style
|
141 |
.background_gradient(axis=0)
|
142 |
.background_gradient(cmap='RdYlGn')
|
143 |
.background_gradient(cmap='RdYlGn_r', subset=['Finish_percentile', 'Own', 'Dupes'])
|