Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
fdea99f
1
Parent(s):
38825d8
Update portfolio management to include player names from projections; fix lineup optimization constraint to use correct player column count.
Browse files- app.py +4 -6
- global_func/optimize_lineup.py +2 -1
app.py
CHANGED
|
@@ -1748,7 +1748,7 @@ if selected_tab == 'Data Load':
|
|
| 1748 |
st.session_state['origin_portfolio'] = buffer.getvalue()
|
| 1749 |
|
| 1750 |
portfolio_inc_proj = pd.DataFrame()
|
| 1751 |
-
portfolio_inc_proj['player_names'] = get_portfolio_names(st.session_state['portfolio'])
|
| 1752 |
portfolio_inc_proj['position'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['pos_map'].get(x, 'FLEX'))
|
| 1753 |
portfolio_inc_proj['team'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['team_map'].get(x, 'Unknown'))
|
| 1754 |
portfolio_inc_proj['salary'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['salary_map'].get(x, 0))
|
|
@@ -2926,7 +2926,7 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2926 |
|
| 2927 |
with st.expander('Exposure Management'):
|
| 2928 |
with st.form(key='Exposures'):
|
| 2929 |
-
exposure_player = st.selectbox("Player", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame'])))), key='exposure_player')
|
| 2930 |
exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
|
| 2931 |
comp_salary_below = st.number_input("Comp Salary Below", value=-5000, min_value=-5000, max_value=0, step=100)
|
| 2932 |
comp_salary_above = st.number_input("Comp Salary Above", value=5000, min_value=0, max_value=5000, step=100)
|
|
@@ -2935,8 +2935,8 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2935 |
else:
|
| 2936 |
ignore_stacks = []
|
| 2937 |
remove_teams_exposure = st.multiselect("Removed/Locked teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
| 2938 |
-
specific_replacements = st.multiselect("Specific Replacements?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame'])))), default=[])
|
| 2939 |
-
specific_exclusions = st.multiselect("Specific exclusions?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame'])))), default=[])
|
| 2940 |
specific_columns = st.multiselect("Specific Positions?", options=sorted(list(st.session_state['player_columns'])), default=[])
|
| 2941 |
submitted_col, export_col = st.columns(2)
|
| 2942 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|
|
@@ -2946,7 +2946,6 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2946 |
exp_submitted = st.form_submit_button("Export")
|
| 2947 |
if reg_submitted:
|
| 2948 |
st.session_state['settings_base'] = False
|
| 2949 |
-
# Prepare DataFrame for exposure_spread to avoid categorical issues
|
| 2950 |
working_frame_prepared = prepare_dataframe_for_exposure_spread(st.session_state['working_frame'], st.session_state['player_columns'])
|
| 2951 |
parsed_frame = exposure_spread(working_frame_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_exclusions, specific_columns, st.session_state['portfolio_inc_proj'], sport_var, type_var, salary_max, stacking_sports)
|
| 2952 |
|
|
@@ -2985,7 +2984,6 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2985 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 2986 |
elif exp_submitted:
|
| 2987 |
st.session_state['settings_base'] = False
|
| 2988 |
-
# Prepare DataFrame for exposure_spread to avoid categorical issues
|
| 2989 |
export_base_prepared = prepare_dataframe_for_exposure_spread(st.session_state['export_base'], st.session_state['player_columns'])
|
| 2990 |
parsed_frame = exposure_spread(export_base_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_exclusions, specific_columns, st.session_state['portfolio_inc_proj'], sport_var, type_var, salary_max, stacking_sports)
|
| 2991 |
|
|
|
|
| 1748 |
st.session_state['origin_portfolio'] = buffer.getvalue()
|
| 1749 |
|
| 1750 |
portfolio_inc_proj = pd.DataFrame()
|
| 1751 |
+
portfolio_inc_proj['player_names'] = get_portfolio_names(st.session_state['portfolio']) + st.session_state['projections_df']['player_names'].tolist()
|
| 1752 |
portfolio_inc_proj['position'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['pos_map'].get(x, 'FLEX'))
|
| 1753 |
portfolio_inc_proj['team'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['team_map'].get(x, 'Unknown'))
|
| 1754 |
portfolio_inc_proj['salary'] = portfolio_inc_proj['player_names'].map(lambda x: st.session_state['map_dict']['salary_map'].get(x, 0))
|
|
|
|
| 2926 |
|
| 2927 |
with st.expander('Exposure Management'):
|
| 2928 |
with st.form(key='Exposures'):
|
| 2929 |
+
exposure_player = st.selectbox("Player", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['projections_df']['player_names'].tolist()))), key='exposure_player')
|
| 2930 |
exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
|
| 2931 |
comp_salary_below = st.number_input("Comp Salary Below", value=-5000, min_value=-5000, max_value=0, step=100)
|
| 2932 |
comp_salary_above = st.number_input("Comp Salary Above", value=5000, min_value=0, max_value=5000, step=100)
|
|
|
|
| 2935 |
else:
|
| 2936 |
ignore_stacks = []
|
| 2937 |
remove_teams_exposure = st.multiselect("Removed/Locked teams?", options=sorted(list(set(st.session_state['projections_df']['team'].unique()))), default=[])
|
| 2938 |
+
specific_replacements = st.multiselect("Specific Replacements?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['projections_df']['player_names'].tolist()))), default=[])
|
| 2939 |
+
specific_exclusions = st.multiselect("Specific exclusions?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['projections_df']['player_names'].tolist()))), default=[])
|
| 2940 |
specific_columns = st.multiselect("Specific Positions?", options=sorted(list(st.session_state['player_columns'])), default=[])
|
| 2941 |
submitted_col, export_col = st.columns(2)
|
| 2942 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|
|
|
|
| 2946 |
exp_submitted = st.form_submit_button("Export")
|
| 2947 |
if reg_submitted:
|
| 2948 |
st.session_state['settings_base'] = False
|
|
|
|
| 2949 |
working_frame_prepared = prepare_dataframe_for_exposure_spread(st.session_state['working_frame'], st.session_state['player_columns'])
|
| 2950 |
parsed_frame = exposure_spread(working_frame_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_exclusions, specific_columns, st.session_state['portfolio_inc_proj'], sport_var, type_var, salary_max, stacking_sports)
|
| 2951 |
|
|
|
|
| 2984 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 2985 |
elif exp_submitted:
|
| 2986 |
st.session_state['settings_base'] = False
|
|
|
|
| 2987 |
export_base_prepared = prepare_dataframe_for_exposure_spread(st.session_state['export_base'], st.session_state['player_columns'])
|
| 2988 |
parsed_frame = exposure_spread(export_base_prepared, st.session_state['exposure_player'], exposure_target, comp_salary_below, comp_salary_above, ignore_stacks, remove_teams_exposure, specific_replacements, specific_exclusions, specific_columns, st.session_state['portfolio_inc_proj'], sport_var, type_var, salary_max, stacking_sports)
|
| 2989 |
|
global_func/optimize_lineup.py
CHANGED
|
@@ -92,6 +92,7 @@ def optimize_single_lineup(
|
|
| 92 |
player_list = available_players.to_dict('records')
|
| 93 |
num_players = len(player_list)
|
| 94 |
num_open_cols = len(open_columns)
|
|
|
|
| 95 |
|
| 96 |
# x[i][j] = 1 if player i is assigned to open column j
|
| 97 |
x = {}
|
|
@@ -105,7 +106,7 @@ def optimize_single_lineup(
|
|
| 105 |
|
| 106 |
# Constraint 2: Each player can only be used once across all open columns
|
| 107 |
for i in range(num_players):
|
| 108 |
-
solver.Add(sum(x[i, j] for j in range(
|
| 109 |
|
| 110 |
# Constraint 3: Position eligibility
|
| 111 |
for i, player in enumerate(player_list):
|
|
|
|
| 92 |
player_list = available_players.to_dict('records')
|
| 93 |
num_players = len(player_list)
|
| 94 |
num_open_cols = len(open_columns)
|
| 95 |
+
num_player_columns = len(player_columns)
|
| 96 |
|
| 97 |
# x[i][j] = 1 if player i is assigned to open column j
|
| 98 |
x = {}
|
|
|
|
| 106 |
|
| 107 |
# Constraint 2: Each player can only be used once across all open columns
|
| 108 |
for i in range(num_players):
|
| 109 |
+
solver.Add(sum(x[i, j] for j in range(num_player_columns)) <= 1)
|
| 110 |
|
| 111 |
# Constraint 3: Position eligibility
|
| 112 |
for i, player in enumerate(player_list):
|