James McCool commited on
Commit
ad7b76c
·
1 Parent(s): 87ed105

Refactor projections management to use 'portfolio_inc_proj' for editing and optimize lineup filtering by excluding locked players. Cleaned up player pool logic to prevent duplicates.

Browse files
Files changed (2) hide show
  1. app.py +6 -8
  2. global_func/optimize_lineup.py +6 -10
app.py CHANGED
@@ -1761,11 +1761,11 @@ if selected_tab == 'Data Load':
1761
 
1762
 
1763
  if selected_tab == 'Projections Management':
1764
- if 'projections_df' in st.session_state and st.session_state['projections_df'] is not None:
1765
  st.subheader("Edit Player Projections")
1766
  st.caption("Modify median, ownership, or captain ownership values directly in the table below. Changes will update both the projections and all related mappings.")
1767
 
1768
- projections_editor_df = st.session_state['projections_df'].copy()
1769
 
1770
  if 'origin_portfolio' in st.session_state and 'map_dict' in st.session_state:
1771
  portfolio_df = pd.read_parquet(io.BytesIO(st.session_state['origin_portfolio']))
@@ -2862,9 +2862,7 @@ if selected_tab == 'Manage Portfolio':
2862
  st.session_state['settings_base'] = False
2863
  parsed_frame = st.session_state['export_base'].copy()
2864
 
2865
- # Check if we have both replace and containing players selected
2866
  if replace_player and containing_player and replace_player != containing_player:
2867
- # Find rows that contain the containing_player in the specified slot
2868
  containing_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
2869
 
2870
  if type_var == 'Showdown':
@@ -2888,11 +2886,11 @@ if selected_tab == 'Manage Portfolio':
2888
  modified_rows = exposure_spread(
2889
  target_rows_prepared,
2890
  replace_player,
2891
- 0, # exposure_target = 0 means remove all instances
2892
  comp_salary_below_combo,
2893
  comp_salary_above_combo,
2894
- [], # ignore_stacks
2895
- [], # remove_teams_exposure
2896
  specific_replacements_combo,
2897
  specific_exclusions_combo,
2898
  st.session_state['player_columns'] if replace_slot == 'Overall' else
@@ -3014,7 +3012,7 @@ if selected_tab == 'Manage Portfolio':
3014
  optimize_by = st.selectbox("Optimize By", options=['median', 'ownership'], key='optimize_by')
3015
  lock_teams_optimize = st.multiselect(
3016
  "Locked Teams",
3017
- options=sorted(list(set(st.session_state['projections_df']['team'].unique()))),
3018
  default=[],
3019
  key='lock_teams_optimize'
3020
  )
 
1761
 
1762
 
1763
  if selected_tab == 'Projections Management':
1764
+ if 'portfolio_inc_proj' in st.session_state and st.session_state['portfolio_inc_proj'] is not None:
1765
  st.subheader("Edit Player Projections")
1766
  st.caption("Modify median, ownership, or captain ownership values directly in the table below. Changes will update both the projections and all related mappings.")
1767
 
1768
+ projections_editor_df = st.session_state['portfolio_inc_proj'].copy()
1769
 
1770
  if 'origin_portfolio' in st.session_state and 'map_dict' in st.session_state:
1771
  portfolio_df = pd.read_parquet(io.BytesIO(st.session_state['origin_portfolio']))
 
2862
  st.session_state['settings_base'] = False
2863
  parsed_frame = st.session_state['export_base'].copy()
2864
 
 
2865
  if replace_player and containing_player and replace_player != containing_player:
 
2866
  containing_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
2867
 
2868
  if type_var == 'Showdown':
 
2886
  modified_rows = exposure_spread(
2887
  target_rows_prepared,
2888
  replace_player,
2889
+ 0,
2890
  comp_salary_below_combo,
2891
  comp_salary_above_combo,
2892
+ [],
2893
+ [],
2894
  specific_replacements_combo,
2895
  specific_exclusions_combo,
2896
  st.session_state['player_columns'] if replace_slot == 'Overall' else
 
3012
  optimize_by = st.selectbox("Optimize By", options=['median', 'ownership'], key='optimize_by')
3013
  lock_teams_optimize = st.multiselect(
3014
  "Locked Teams",
3015
+ options=sorted(list(set(st.session_state['portfolio_inc_proj']['team'].unique()))),
3016
  default=[],
3017
  key='lock_teams_optimize'
3018
  )
global_func/optimize_lineup.py CHANGED
@@ -72,20 +72,16 @@ def optimize_single_lineup(
72
 
73
  # Calculate remaining salary budget
74
  remaining_salary = salary_max - locked_salary
75
-
76
- # Get all players currently in this row (both locked and unlocked positions)
77
- current_players_in_row = set()
78
- for col in player_columns:
79
- player_name = row[col]
80
- if pd.notna(player_name) and player_name: # Check for valid player names
81
- current_players_in_row.add(player_name)
82
-
83
- # Filter player pool: exclude locked teams AND players already in this specific row
84
  available_players = player_pool[
85
  (~player_pool['team'].isin(lock_teams)) &
86
- (~player_pool['player_names'].isin(current_players_in_row)) # ✅ Exclude ALL current players
87
  ].copy()
88
 
 
 
 
89
  if available_players.empty:
90
  return optimized_row
91
 
 
72
 
73
  # Calculate remaining salary budget
74
  remaining_salary = salary_max - locked_salary
75
+
76
+ # Filter player pool: exclude locked teams and already-locked players
 
 
 
 
 
 
 
77
  available_players = player_pool[
78
  (~player_pool['team'].isin(lock_teams)) &
79
+ (~player_pool['player_names'].isin(locked_player_names))
80
  ].copy()
81
 
82
+ # CRITICAL: Remove duplicate players from available pool
83
+ available_players = available_players.drop_duplicates(subset=['player_names'], keep='first')
84
+
85
  if available_players.empty:
86
  return optimized_row
87