James McCool
commited on
Commit
·
74f9c17
1
Parent(s):
a7ad1b5
Refactor filter options in app.py: streamline the organization of macro and micro filter inputs into expandable sections, enhance player locking and removal functionalities, and ensure consistent handling of trimming parameters for improved user experience during portfolio management.
Browse files
app.py
CHANGED
@@ -881,93 +881,92 @@ with tab2:
|
|
881 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
882 |
axis=1
|
883 |
)
|
884 |
-
|
885 |
-
|
886 |
-
with
|
887 |
-
with st.
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
with st.
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own'], key='trim_var')
|
919 |
|
920 |
-
|
921 |
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
935 |
|
936 |
-
|
937 |
-
|
938 |
-
st.
|
939 |
-
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
940 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
941 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
942 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
943 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Finish_percentile'] <= max_finish_percentile]
|
944 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Lineup Edge'] >= min_lineup_edge]
|
945 |
-
if stack_dict is not None:
|
946 |
-
if stack_toggle == 'All Stacks':
|
947 |
-
st.session_state['portfolio'] = st.session_state['portfolio']
|
948 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][~st.session_state['portfolio']['Stack'].isin(stack_remove)]
|
949 |
-
else:
|
950 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Stack'].isin(stack_selections)]
|
951 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][~st.session_state['portfolio']['Stack'].isin(stack_remove)]
|
952 |
-
if player_remove:
|
953 |
-
# Create mask for lineups that contain any of the removed players
|
954 |
-
player_columns = [col for col in st.session_state['portfolio'].columns if col not in excluded_cols]
|
955 |
-
remove_mask = st.session_state['portfolio'][player_columns].apply(
|
956 |
-
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
957 |
-
)
|
958 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][remove_mask]
|
959 |
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
|
968 |
-
|
969 |
-
st.session_state['portfolio'] = trim_portfolio(st.session_state['portfolio'], trim_slack_var, performance_type, own_type, performance_threshold_high, performance_threshold_low, own_threshold_high, own_threshold_low)
|
970 |
-
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
971 |
|
972 |
with col2:
|
973 |
st.write('initiated')
|
|
|
881 |
sum(map_dict['own_map'].get(player, 0) for player in row.iloc[1:]),
|
882 |
axis=1
|
883 |
)
|
884 |
+
col1, col2 = st.columns([2, 8])
|
885 |
+
with col1:
|
886 |
+
with st.expander('Macro Filter Options'):
|
887 |
+
with st.form(key='macro_filter_form'):
|
888 |
+
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
889 |
+
min_salary = st.number_input("Min acceptable salary?", value=1000, min_value=1000, step=100)
|
890 |
+
max_salary = st.number_input("Max acceptable salary?", value=100000, min_value=1000, step=100)
|
891 |
+
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
892 |
+
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1.00, step=.001)
|
893 |
+
if stack_dict is not None:
|
894 |
+
stack_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
|
895 |
+
stack_selections = st.multiselect("If Specific Stacks, Which to include?", options=sorted(list(set(stack_dict.values()))), default=[])
|
896 |
+
stack_remove = st.multiselect("If Specific Stacks, Which to remove?", options=sorted(list(set(stack_dict.values()))), default=[])
|
897 |
+
|
898 |
+
submitted = st.form_submit_button("Submit")
|
899 |
+
with st.expander('Micro Filter Options'):
|
900 |
+
with st.form(key='micro_filter_form'):
|
901 |
+
player_names = set()
|
902 |
+
for col in st.session_state['portfolio'].columns:
|
903 |
+
if col not in excluded_cols:
|
904 |
+
player_names.update(st.session_state['portfolio'][col].unique())
|
905 |
+
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
906 |
+
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
907 |
+
|
908 |
+
submitted = st.form_submit_button("Submit")
|
909 |
+
with st.expander('Trimming Options'):
|
910 |
+
st.info("Make sure you filter before trimming if you want to filter, trimming before a filter will reset your portfolio")
|
911 |
+
with st.form(key='trim_form'):
|
912 |
+
st.write("Sorting and trimming variables:")
|
913 |
+
perf_var, own_var = st.columns(2)
|
914 |
+
with perf_var:
|
915 |
+
performance_type = st.selectbox("Sorting variable", ['median', 'Finish_percentile'], key='sort_var')
|
916 |
+
with own_var:
|
917 |
+
own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own'], key='trim_var')
|
|
|
918 |
|
919 |
+
trim_slack_var = st.number_input("Trim slack (percentile addition to trimming variable ceiling)", value=0.0, min_value=0.0, max_value=1.0, step=0.1, key='trim_slack')
|
920 |
|
921 |
+
st.write("Sorting threshold range:")
|
922 |
+
min_sort, max_sort = st.columns(2)
|
923 |
+
with min_sort:
|
924 |
+
performance_threshold_low = st.number_input("Min", value=0.0, min_value=0.0, step=1.0, key='min_sort')
|
925 |
+
with max_sort:
|
926 |
+
performance_threshold_high = st.number_input("Max", value=st.session_state['portfolio'][performance_type].max(), min_value=0.0, step=1.0, key='max_sort')
|
927 |
+
|
928 |
+
st.write("Trimming threshold range:")
|
929 |
+
min_trim, max_trim = st.columns(2)
|
930 |
+
with min_trim:
|
931 |
+
own_threshold_low = st.number_input("Min", value=0.0, min_value=0.0, step=1.0, key='min_trim')
|
932 |
+
with max_trim:
|
933 |
+
own_threshold_high = st.number_input("Max", value=st.session_state['portfolio'][own_type].max(), min_value=0.0, step=1.0, key='max_trim')
|
934 |
+
|
935 |
+
submitted = st.form_submit_button("Trim")
|
936 |
+
if submitted:
|
937 |
+
st.write('initiated')
|
938 |
+
st.session_state['portfolio'] = predict_dupes(st.session_state['portfolio'], map_dict, site_var, type_var, Contest_Size, strength_var, sport_var)
|
939 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Dupes'] <= max_dupes]
|
940 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] >= min_salary]
|
941 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['salary'] <= max_salary]
|
942 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Finish_percentile'] <= max_finish_percentile]
|
943 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Lineup Edge'] >= min_lineup_edge]
|
944 |
+
if stack_dict is not None:
|
945 |
+
if stack_toggle == 'All Stacks':
|
946 |
+
st.session_state['portfolio'] = st.session_state['portfolio']
|
947 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][~st.session_state['portfolio']['Stack'].isin(stack_remove)]
|
948 |
+
else:
|
949 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][st.session_state['portfolio']['Stack'].isin(stack_selections)]
|
950 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][~st.session_state['portfolio']['Stack'].isin(stack_remove)]
|
951 |
+
if player_remove:
|
952 |
+
# Create mask for lineups that contain any of the removed players
|
953 |
+
player_columns = [col for col in st.session_state['portfolio'].columns if col not in excluded_cols]
|
954 |
+
remove_mask = st.session_state['portfolio'][player_columns].apply(
|
955 |
+
lambda row: not any(player in list(row) for player in player_remove), axis=1
|
956 |
+
)
|
957 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][remove_mask]
|
958 |
|
959 |
+
if player_lock:
|
960 |
+
# Create mask for lineups that contain all locked players
|
961 |
+
player_columns = [col for col in st.session_state['portfolio'].columns if col not in excluded_cols]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
962 |
|
963 |
+
lock_mask = st.session_state['portfolio'][player_columns].apply(
|
964 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
965 |
+
)
|
966 |
+
st.session_state['portfolio'] = st.session_state['portfolio'][lock_mask]
|
967 |
+
|
968 |
+
st.session_state['portfolio'] = trim_portfolio(st.session_state['portfolio'], trim_slack_var, performance_type, own_type, performance_threshold_high, performance_threshold_low, own_threshold_high, own_threshold_low)
|
969 |
+
st.session_state['portfolio'] = st.session_state['portfolio'].sort_values(by='median', ascending=False)
|
|
|
|
|
|
|
|
|
970 |
|
971 |
with col2:
|
972 |
st.write('initiated')
|