James McCool
commited on
Commit
·
e706ae9
1
Parent(s):
ad7b76c
using the portfolio management projections instead of the projections_df
Browse files
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']) + 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))
|
|
@@ -1880,16 +1880,16 @@ if selected_tab == 'Projections Management':
|
|
| 1880 |
player_name = row['player_names']
|
| 1881 |
|
| 1882 |
# Find and update the original projections_df
|
| 1883 |
-
orig_idx = st.session_state['
|
| 1884 |
if len(orig_idx) > 0:
|
| 1885 |
-
# Player exists in
|
| 1886 |
-
st.session_state['
|
| 1887 |
-
st.session_state['
|
| 1888 |
-
st.session_state['
|
| 1889 |
-
st.session_state['
|
| 1890 |
-
st.session_state['
|
| 1891 |
-
st.session_state['
|
| 1892 |
-
st.session_state['
|
| 1893 |
else:
|
| 1894 |
# Player is new (from portfolio but not in projections) - add new row
|
| 1895 |
new_row = pd.DataFrame([{
|
|
@@ -1901,7 +1901,7 @@ if selected_tab == 'Projections Management':
|
|
| 1901 |
'ownership': row['ownership'],
|
| 1902 |
'captain ownership': row['captain ownership']
|
| 1903 |
}])
|
| 1904 |
-
st.session_state['
|
| 1905 |
|
| 1906 |
# Update map_dict entries
|
| 1907 |
if 'map_dict' in st.session_state:
|
|
@@ -1945,7 +1945,7 @@ if selected_tab == 'Projections Management':
|
|
| 1945 |
if selected_tab == 'Manage Portfolio':
|
| 1946 |
if 'base_frame_names' not in st.session_state:
|
| 1947 |
st.session_state['base_frame_names'] = {}
|
| 1948 |
-
if 'origin_portfolio' in st.session_state and '
|
| 1949 |
with st.container():
|
| 1950 |
reset_port_col, recalc_stacks_col, recalc_div_col, set_base_col, blank_reset_col, contest_size_col = st.columns([.15, .10, .10, .10, .30, .25])
|
| 1951 |
with reset_port_col:
|
|
@@ -2009,7 +2009,7 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2009 |
st.session_state['map_dict'],
|
| 2010 |
type_var,
|
| 2011 |
sport_var,
|
| 2012 |
-
st.session_state['
|
| 2013 |
)
|
| 2014 |
processed_frame = processed_frame[processed_frame['salary'] <= salary_max]
|
| 2015 |
|
|
@@ -2151,8 +2151,8 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2151 |
cpt_flex_focus = st.selectbox("Focus on Overall, CPT, or FLEX?", options=['Overall', 'CPT', 'FLEX'], index=0)
|
| 2152 |
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
| 2153 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
| 2154 |
-
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['
|
| 2155 |
-
team_remove = st.multiselect("Remove teams?", options=sorted(list(set(st.session_state['
|
| 2156 |
if sport_var in stacking_sports:
|
| 2157 |
size_include = st.multiselect("Include sizes?", options=sorted(list(set(st.session_state['working_frame']['Size'].unique()))), default=[])
|
| 2158 |
else:
|
|
@@ -2918,17 +2918,17 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2918 |
|
| 2919 |
with st.expander('Exposure Management'):
|
| 2920 |
with st.form(key='Exposures'):
|
| 2921 |
-
exposure_player = st.selectbox("Player", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['
|
| 2922 |
exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
|
| 2923 |
comp_salary_below = st.number_input("Comp Salary Below", value=-5000, min_value=-5000, max_value=0, step=100)
|
| 2924 |
comp_salary_above = st.number_input("Comp Salary Above", value=5000, min_value=0, max_value=5000, step=100)
|
| 2925 |
if 'Stack' in st.session_state['working_frame'].columns:
|
| 2926 |
-
ignore_stacks = st.multiselect("Ignore Specific Stacks?", options=sorted(list(set(st.session_state['
|
| 2927 |
else:
|
| 2928 |
ignore_stacks = []
|
| 2929 |
-
remove_teams_exposure = st.multiselect("Removed/Locked teams?", options=sorted(list(set(st.session_state['
|
| 2930 |
-
specific_replacements = st.multiselect("Specific Replacements?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['
|
| 2931 |
-
specific_exclusions = st.multiselect("Specific exclusions?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['
|
| 2932 |
specific_columns = st.multiselect("Specific Positions?", options=sorted(list(st.session_state['player_columns'])), default=[])
|
| 2933 |
submitted_col, export_col = st.columns(2)
|
| 2934 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|
|
|
|
| 1748 |
st.session_state['origin_portfolio'] = buffer.getvalue()
|
| 1749 |
|
| 1750 |
portfolio_inc_proj = pd.DataFrame()
|
| 1751 |
+
portfolio_inc_proj['player_names'] = set(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))
|
|
|
|
| 1880 |
player_name = row['player_names']
|
| 1881 |
|
| 1882 |
# Find and update the original projections_df
|
| 1883 |
+
orig_idx = st.session_state['portfolio_inc_proj'][st.session_state['portfolio_inc_proj']['player_names'] == player_name].index
|
| 1884 |
if len(orig_idx) > 0:
|
| 1885 |
+
# Player exists in portfolio_inc_proj - update existing row
|
| 1886 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'player_names'] = row['player_names']
|
| 1887 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'position'] = row['position']
|
| 1888 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'team'] = row['team']
|
| 1889 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'salary'] = row['salary']
|
| 1890 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'median'] = row['median']
|
| 1891 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'ownership'] = row['ownership']
|
| 1892 |
+
st.session_state['portfolio_inc_proj'].loc[orig_idx[0], 'captain ownership'] = row['captain ownership']
|
| 1893 |
else:
|
| 1894 |
# Player is new (from portfolio but not in projections) - add new row
|
| 1895 |
new_row = pd.DataFrame([{
|
|
|
|
| 1901 |
'ownership': row['ownership'],
|
| 1902 |
'captain ownership': row['captain ownership']
|
| 1903 |
}])
|
| 1904 |
+
st.session_state['portfolio_inc_proj'] = pd.concat([st.session_state['portfolio_inc_proj'], new_row], ignore_index=True)
|
| 1905 |
|
| 1906 |
# Update map_dict entries
|
| 1907 |
if 'map_dict' in st.session_state:
|
|
|
|
| 1945 |
if selected_tab == 'Manage Portfolio':
|
| 1946 |
if 'base_frame_names' not in st.session_state:
|
| 1947 |
st.session_state['base_frame_names'] = {}
|
| 1948 |
+
if 'origin_portfolio' in st.session_state and 'portfolio_inc_proj' in st.session_state:
|
| 1949 |
with st.container():
|
| 1950 |
reset_port_col, recalc_stacks_col, recalc_div_col, set_base_col, blank_reset_col, contest_size_col = st.columns([.15, .10, .10, .10, .30, .25])
|
| 1951 |
with reset_port_col:
|
|
|
|
| 2009 |
st.session_state['map_dict'],
|
| 2010 |
type_var,
|
| 2011 |
sport_var,
|
| 2012 |
+
st.session_state['portfolio_inc_proj'] if 'stack_dict' in st.session_state else None
|
| 2013 |
)
|
| 2014 |
processed_frame = processed_frame[processed_frame['salary'] <= salary_max]
|
| 2015 |
|
|
|
|
| 2151 |
cpt_flex_focus = st.selectbox("Focus on Overall, CPT, or FLEX?", options=['Overall', 'CPT', 'FLEX'], index=0)
|
| 2152 |
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
| 2153 |
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
| 2154 |
+
team_include = st.multiselect("Include teams?", options=sorted(list(set(st.session_state['portfolio_inc_proj']['team'].unique()))), default=[])
|
| 2155 |
+
team_remove = st.multiselect("Remove teams?", options=sorted(list(set(st.session_state['portfolio_inc_proj']['team'].unique()))), default=[])
|
| 2156 |
if sport_var in stacking_sports:
|
| 2157 |
size_include = st.multiselect("Include sizes?", options=sorted(list(set(st.session_state['working_frame']['Size'].unique()))), default=[])
|
| 2158 |
else:
|
|
|
|
| 2918 |
|
| 2919 |
with st.expander('Exposure Management'):
|
| 2920 |
with st.form(key='Exposures'):
|
| 2921 |
+
exposure_player = st.selectbox("Player", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['portfolio_inc_proj']['player_names'].tolist()))), key='exposure_player')
|
| 2922 |
exposure_target = st.number_input("Target Exposure", value=.50, min_value=0.0, max_value=1.0, step=0.01)
|
| 2923 |
comp_salary_below = st.number_input("Comp Salary Below", value=-5000, min_value=-5000, max_value=0, step=100)
|
| 2924 |
comp_salary_above = st.number_input("Comp Salary Above", value=5000, min_value=0, max_value=5000, step=100)
|
| 2925 |
if 'Stack' in st.session_state['working_frame'].columns:
|
| 2926 |
+
ignore_stacks = st.multiselect("Ignore Specific Stacks?", options=sorted(list(set(st.session_state['portfolio_inc_proj']['team'].unique()))), default=[])
|
| 2927 |
else:
|
| 2928 |
ignore_stacks = []
|
| 2929 |
+
remove_teams_exposure = st.multiselect("Removed/Locked teams?", options=sorted(list(set(st.session_state['portfolio_inc_proj']['team'].unique()))), default=[])
|
| 2930 |
+
specific_replacements = st.multiselect("Specific Replacements?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['portfolio_inc_proj']['player_names'].tolist()))), default=[])
|
| 2931 |
+
specific_exclusions = st.multiselect("Specific exclusions?", options=sorted(list(set(get_portfolio_names(st.session_state['working_frame']) + st.session_state['portfolio_inc_proj']['player_names'].tolist()))), default=[])
|
| 2932 |
specific_columns = st.multiselect("Specific Positions?", options=sorted(list(st.session_state['player_columns'])), default=[])
|
| 2933 |
submitted_col, export_col = st.columns(2)
|
| 2934 |
st.info("Portfolio Button applies to your overall Portfolio, Export button applies to your Custom Export")
|