Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
9c21d34
1
Parent(s):
ac34a80
Enhance position filtering functionality by separating filter keys for positions and teams, and updating input prompts for clarity. This improves user experience in managing portfolio filters.
Browse files
app.py
CHANGED
|
@@ -1033,7 +1033,7 @@ def create_position_export_dict(column_name, csv_file, site_var, type_var, sport
|
|
| 1033 |
st.error(f"Error creating position export dict for {column_name}: {str(e)}")
|
| 1034 |
return {}
|
| 1035 |
|
| 1036 |
-
def parse_portfolio_on_mapped(portfolio, map_dict, map_key,
|
| 1037 |
mapping_port = portfolio[column_choices]
|
| 1038 |
mapping_port = mapping_port.map(map_dict[map_key])
|
| 1039 |
|
|
@@ -1044,7 +1044,7 @@ def parse_portfolio_on_mapped(portfolio, map_dict, map_key, filter_keys, low_thr
|
|
| 1044 |
mask = low_mask & high_mask
|
| 1045 |
else:
|
| 1046 |
# String mapping - filter by inclusion in filter_keys
|
| 1047 |
-
mask = mapping_port.isin(
|
| 1048 |
|
| 1049 |
return portfolio[mask]
|
| 1050 |
|
|
@@ -2140,34 +2140,10 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2140 |
with st.form(key='position_filtering_form'):
|
| 2141 |
position_choice = st.selectbox("Position to filter", options=[col for col in st.session_state['working_frame'].columns if col not in excluded_cols], index=0)
|
| 2142 |
position_filter = st.selectbox("Filter on:", options=pos_parse_options)
|
| 2143 |
-
if
|
| 2144 |
-
|
| 2145 |
-
|
| 2146 |
-
|
| 2147 |
-
elif position_filter == 'Ownership':
|
| 2148 |
-
position_low_threshold = st.number_input("Low Threshold", value=0.0, min_value=0.0, step=1.0)
|
| 2149 |
-
position_high_threshold = st.number_input("High Threshold", value=100.0, min_value=0.0, step=1.0)
|
| 2150 |
-
filter_keys = None
|
| 2151 |
-
elif position_filter == 'Salary':
|
| 2152 |
-
position_low_threshold = st.number_input("Low Threshold", value=0.0, min_value=0.0, step=1000.0)
|
| 2153 |
-
position_high_threshold = st.number_input("High Threshold", value=20000.0, min_value=0.0, step=1000.0)
|
| 2154 |
-
filter_keys = None
|
| 2155 |
-
elif position_filter == 'Position':
|
| 2156 |
-
filter_keys_choice = st.selectbox("Filter choice:", options=['Position', 'Team'])
|
| 2157 |
-
if filter_keys_choice == 'Position':
|
| 2158 |
-
filter_keys = st.multiselect("Position(s) to keep", options=[col for col in st.session_state['working_frame'].columns if col not in excluded_cols], default=[])
|
| 2159 |
-
else:
|
| 2160 |
-
filter_keys = st.multiselect("Team(s) to keep", options=st.session_state['map_dict']['team_map'].keys(), default=[])
|
| 2161 |
-
position_low_threshold = None
|
| 2162 |
-
position_high_threshold = None
|
| 2163 |
-
else:
|
| 2164 |
-
filter_keys_choice = st.selectbox("Filter choice:", options=['Position', 'Team'])
|
| 2165 |
-
if filter_keys_choice == 'Position':
|
| 2166 |
-
filter_keys = st.multiselect("Position(s) to keep", options=[col for col in st.session_state['working_frame'].columns if col not in excluded_cols], default=[])
|
| 2167 |
-
else:
|
| 2168 |
-
filter_keys = st.multiselect("Team(s) to keep", options=st.session_state['map_dict']['team_map'].keys(), default=[])
|
| 2169 |
-
position_low_threshold = None
|
| 2170 |
-
position_high_threshold = None
|
| 2171 |
submitted_col, export_col = st.columns(2)
|
| 2172 |
with submitted_col:
|
| 2173 |
reg_submitted = st.form_submit_button("Portfolio")
|
|
@@ -2176,13 +2152,13 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2176 |
if reg_submitted:
|
| 2177 |
st.session_state['settings_base'] = False
|
| 2178 |
parsed_frame = st.session_state['working_frame'].copy()
|
| 2179 |
-
parsed_frame = parse_portfolio_on_mapped(parsed_frame, st.session_state['map_dict'], pos_parse_mapping[position_filter],
|
| 2180 |
st.session_state['working_frame'] = parsed_frame.sort_values(by='median', ascending=False)
|
| 2181 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 2182 |
elif exp_submitted:
|
| 2183 |
st.session_state['settings_base'] = False
|
| 2184 |
parsed_frame = st.session_state['export_base'].copy()
|
| 2185 |
-
parsed_frame = parse_portfolio_on_mapped(parsed_frame, st.session_state['map_dict'], pos_parse_mapping[position_filter],
|
| 2186 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False)
|
| 2187 |
st.session_state['export_merge'] = st.session_state['export_base'].copy()
|
| 2188 |
with st.expander('Trimming Options'):
|
|
|
|
| 1033 |
st.error(f"Error creating position export dict for {column_name}: {str(e)}")
|
| 1034 |
return {}
|
| 1035 |
|
| 1036 |
+
def parse_portfolio_on_mapped(portfolio, map_dict, map_key, filter_keys_pos, filter_keys_team, low_threshold, high_threshold, column_choices):
|
| 1037 |
mapping_port = portfolio[column_choices]
|
| 1038 |
mapping_port = mapping_port.map(map_dict[map_key])
|
| 1039 |
|
|
|
|
| 1044 |
mask = low_mask & high_mask
|
| 1045 |
else:
|
| 1046 |
# String mapping - filter by inclusion in filter_keys
|
| 1047 |
+
mask = mapping_port.isin(filter_keys_pos) | mapping_port.isin(filter_keys_team)
|
| 1048 |
|
| 1049 |
return portfolio[mask]
|
| 1050 |
|
|
|
|
| 2140 |
with st.form(key='position_filtering_form'):
|
| 2141 |
position_choice = st.selectbox("Position to filter", options=[col for col in st.session_state['working_frame'].columns if col not in excluded_cols], index=0)
|
| 2142 |
position_filter = st.selectbox("Filter on:", options=pos_parse_options)
|
| 2143 |
+
position_low_threshold = st.number_input("if filtering on Projection/Ownership/Salary, Low Threshold", value=0.0, min_value=0.0, step=1.0)
|
| 2144 |
+
position_high_threshold = st.number_input("if filtering on Projection/Ownership/Salary, High Threshold", value=20000.0, min_value=0.0, step=1.0)
|
| 2145 |
+
filter_keys_pos = st.multiselect("if filtering on Position, Position(s) to keep", options=[col for col in st.session_state['working_frame'].columns if col not in excluded_cols], default=[])
|
| 2146 |
+
filter_keys_team = st.multiselect("if filtering on Team, Team(s) to keep", options=st.session_state['map_dict']['team_map'].keys(), default=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2147 |
submitted_col, export_col = st.columns(2)
|
| 2148 |
with submitted_col:
|
| 2149 |
reg_submitted = st.form_submit_button("Portfolio")
|
|
|
|
| 2152 |
if reg_submitted:
|
| 2153 |
st.session_state['settings_base'] = False
|
| 2154 |
parsed_frame = st.session_state['working_frame'].copy()
|
| 2155 |
+
parsed_frame = parse_portfolio_on_mapped(parsed_frame, st.session_state['map_dict'], pos_parse_mapping[position_filter], filter_keys_pos, filter_keys_team, position_low_threshold, position_high_threshold, position_choice)
|
| 2156 |
st.session_state['working_frame'] = parsed_frame.sort_values(by='median', ascending=False)
|
| 2157 |
st.session_state['export_merge'] = st.session_state['working_frame'].copy()
|
| 2158 |
elif exp_submitted:
|
| 2159 |
st.session_state['settings_base'] = False
|
| 2160 |
parsed_frame = st.session_state['export_base'].copy()
|
| 2161 |
+
parsed_frame = parse_portfolio_on_mapped(parsed_frame, st.session_state['map_dict'], pos_parse_mapping[position_filter], filter_keys_pos, filter_keys_team, position_low_threshold, position_high_threshold, position_choice)
|
| 2162 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False)
|
| 2163 |
st.session_state['export_merge'] = st.session_state['export_base'].copy()
|
| 2164 |
with st.expander('Trimming Options'):
|