James McCool commited on
Commit
26efe66
·
1 Parent(s): e43f97d

Update player summary management in app.py to ensure accurate session state handling. On portfolio reset, copy player exposures to maintain consistency. Refactor player summary assignment logic to streamline data flow and enhance user experience.

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -812,6 +812,7 @@ with tab2:
812
  with col1:
813
  if st.button('Reset Portfolio', key='reset_port'):
814
  st.session_state['working_frame'] = st.session_state['base_frame'].copy()
 
815
 
816
  with col2:
817
  with st.form(key='contest_size_form'):
@@ -1242,9 +1243,7 @@ with tab2:
1242
  player_stats = []
1243
  player_columns = [col for col in display_frame.columns if col not in excluded_cols]
1244
 
1245
- if 'origin_player_exposures' in st.session_state and display_frame_source == 'Portfolio':
1246
- player_summary = st.session_state['origin_player_exposures']
1247
- else:
1248
  if type_var == 'Showdown':
1249
  for player in player_names:
1250
  # Create mask for lineups where this player is Captain (first column)
@@ -1334,13 +1333,12 @@ with tab2:
1334
 
1335
  player_summary = pd.DataFrame(player_stats)
1336
  player_summary = player_summary.sort_values('Lineup Count', ascending=False)
1337
- if display_frame_source == 'Portfolio':
1338
- if 'origin_player_exposures' not in st.session_state:
1339
- st.session_state['origin_player_exposures'] = player_summary.copy()
1340
 
1341
  st.subheader("Player Summary")
1342
  st.dataframe(
1343
- player_summary.style
1344
  .background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Avg Finish %', 'Avg Own', 'Avg Dupes'])
1345
  .format({
1346
  'Avg Median': '{:.2f}',
 
812
  with col1:
813
  if st.button('Reset Portfolio', key='reset_port'):
814
  st.session_state['working_frame'] = st.session_state['base_frame'].copy()
815
+ st.session_state['player_summary'] = st.session_state['origin_player_exposures'].copy()
816
 
817
  with col2:
818
  with st.form(key='contest_size_form'):
 
1243
  player_stats = []
1244
  player_columns = [col for col in display_frame.columns if col not in excluded_cols]
1245
 
1246
+ if 'origin_player_exposures' not in st.session_state:
 
 
1247
  if type_var == 'Showdown':
1248
  for player in player_names:
1249
  # Create mask for lineups where this player is Captain (first column)
 
1333
 
1334
  player_summary = pd.DataFrame(player_stats)
1335
  player_summary = player_summary.sort_values('Lineup Count', ascending=False)
1336
+ st.session_state['player_summary'] = player_summary.copy()
1337
+ st.session_state['origin_player_exposures'] = player_summary.copy()
 
1338
 
1339
  st.subheader("Player Summary")
1340
  st.dataframe(
1341
+ st.session_state['player_summary'].style
1342
  .background_gradient(axis=0).background_gradient(cmap='RdYlGn').background_gradient(cmap='RdYlGn_r', subset=['Avg Finish %', 'Avg Own', 'Avg Dupes'])
1343
  .format({
1344
  'Avg Median': '{:.2f}',