James McCool
commited on
Commit
·
a7ad1b5
1
Parent(s):
866355a
Refactor filter options in app.py: reorganize macro and micro filter inputs into expandable sections for improved user experience, and ensure consistent handling of player locking and removal functionalities during portfolio management.
Browse files
app.py
CHANGED
|
@@ -881,93 +881,93 @@ 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 col1:
|
| 887 |
-
with st.expander('Macro Filter Options'):
|
| 888 |
-
with st.form(key='macro_filter_form'):
|
| 889 |
-
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
| 890 |
-
min_salary = st.number_input("Min acceptable salary?", value=1000, min_value=1000, step=100)
|
| 891 |
-
max_salary = st.number_input("Max acceptable salary?", value=100000, min_value=1000, step=100)
|
| 892 |
-
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
| 893 |
-
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1.00, step=.001)
|
| 894 |
-
if stack_dict is not None:
|
| 895 |
-
stack_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
|
| 896 |
-
stack_selections = st.multiselect("If Specific Stacks, Which to include?", options=sorted(list(set(stack_dict.values()))), default=[])
|
| 897 |
-
stack_remove = st.multiselect("If Specific Stacks, Which to remove?", options=sorted(list(set(stack_dict.values()))), default=[])
|
| 898 |
-
|
| 899 |
-
submitted = st.form_submit_button("Submit")
|
| 900 |
-
with st.expander('Micro Filter Options'):
|
| 901 |
-
with st.form(key='micro_filter_form'):
|
| 902 |
-
player_names = set()
|
| 903 |
-
for col in st.session_state['portfolio'].columns:
|
| 904 |
-
if col not in excluded_cols:
|
| 905 |
-
player_names.update(st.session_state['portfolio'][col].unique())
|
| 906 |
-
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
| 907 |
-
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
| 908 |
-
|
| 909 |
-
submitted = st.form_submit_button("Submit")
|
| 910 |
-
with st.expander('Trimming Options'):
|
| 911 |
-
st.info("Make sure you filter before trimming if you want to filter, trimming before a filter will reset your portfolio")
|
| 912 |
-
with st.form(key='trim_form'):
|
| 913 |
-
st.write("Sorting and trimming variables:")
|
| 914 |
-
perf_var, own_var = st.columns(2)
|
| 915 |
-
with perf_var:
|
| 916 |
-
performance_type = st.selectbox("Sorting variable", ['median', 'Finish_percentile'], key='sort_var')
|
| 917 |
-
with own_var:
|
| 918 |
-
own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own'], key='trim_var')
|
| 919 |
-
|
| 920 |
-
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')
|
| 921 |
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
st.write("Trimming threshold range:")
|
| 930 |
-
min_trim, max_trim = st.columns(2)
|
| 931 |
-
with min_trim:
|
| 932 |
-
own_threshold_low = st.number_input("Min", value=0.0, min_value=0.0, step=1.0, key='min_trim')
|
| 933 |
-
with max_trim:
|
| 934 |
-
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')
|
| 935 |
-
|
| 936 |
-
submitted = st.form_submit_button("Trim")
|
| 937 |
-
if submitted:
|
| 938 |
-
st.write('initiated')
|
| 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 |
-
|
| 970 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
if 'portfolio' in st.session_state:
|
| 885 |
+
col1, col2 = st.columns([2, 8])
|
| 886 |
+
with col1:
|
| 887 |
+
with st.expander('Macro Filter Options'):
|
| 888 |
+
with st.form(key='macro_filter_form'):
|
| 889 |
+
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
| 890 |
+
min_salary = st.number_input("Min acceptable salary?", value=1000, min_value=1000, step=100)
|
| 891 |
+
max_salary = st.number_input("Max acceptable salary?", value=100000, min_value=1000, step=100)
|
| 892 |
+
max_finish_percentile = st.number_input("Max acceptable finish percentile?", value=.50, min_value=0.005, step=.001)
|
| 893 |
+
min_lineup_edge = st.number_input("Min acceptable Lineup Edge?", value=-.5, min_value=-1.00, step=.001)
|
| 894 |
+
if stack_dict is not None:
|
| 895 |
+
stack_toggle = st.selectbox("Include specific stacks?", options=['All Stacks', 'Specific Stacks'], index=0)
|
| 896 |
+
stack_selections = st.multiselect("If Specific Stacks, Which to include?", options=sorted(list(set(stack_dict.values()))), default=[])
|
| 897 |
+
stack_remove = st.multiselect("If Specific Stacks, Which to remove?", options=sorted(list(set(stack_dict.values()))), default=[])
|
| 898 |
+
|
| 899 |
+
submitted = st.form_submit_button("Submit")
|
| 900 |
+
with st.expander('Micro Filter Options'):
|
| 901 |
+
with st.form(key='micro_filter_form'):
|
| 902 |
+
player_names = set()
|
| 903 |
+
for col in st.session_state['portfolio'].columns:
|
| 904 |
+
if col not in excluded_cols:
|
| 905 |
+
player_names.update(st.session_state['portfolio'][col].unique())
|
| 906 |
+
player_lock = st.multiselect("Lock players?", options=sorted(list(player_names)), default=[])
|
| 907 |
+
player_remove = st.multiselect("Remove players?", options=sorted(list(player_names)), default=[])
|
| 908 |
+
|
| 909 |
+
submitted = st.form_submit_button("Submit")
|
| 910 |
+
with st.expander('Trimming Options'):
|
| 911 |
+
st.info("Make sure you filter before trimming if you want to filter, trimming before a filter will reset your portfolio")
|
| 912 |
+
with st.form(key='trim_form'):
|
| 913 |
+
st.write("Sorting and trimming variables:")
|
| 914 |
+
perf_var, own_var = st.columns(2)
|
| 915 |
+
with perf_var:
|
| 916 |
+
performance_type = st.selectbox("Sorting variable", ['median', 'Finish_percentile'], key='sort_var')
|
| 917 |
+
with own_var:
|
| 918 |
+
own_type = st.selectbox("Trimming variable", ['Own', 'Geomean', 'Weighted Own'], key='trim_var')
|
| 919 |
|
| 920 |
+
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 921 |
|
| 922 |
+
st.write("Sorting threshold range:")
|
| 923 |
+
min_sort, max_sort = st.columns(2)
|
| 924 |
+
with min_sort:
|
| 925 |
+
performance_threshold_low = st.number_input("Min", value=0.0, min_value=0.0, step=1.0, key='min_sort')
|
| 926 |
+
with max_sort:
|
| 927 |
+
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 928 |
|
| 929 |
+
st.write("Trimming threshold range:")
|
| 930 |
+
min_trim, max_trim = st.columns(2)
|
| 931 |
+
with min_trim:
|
| 932 |
+
own_threshold_low = st.number_input("Min", value=0.0, min_value=0.0, step=1.0, key='min_trim')
|
| 933 |
+
with max_trim:
|
| 934 |
+
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')
|
|
|
|
|
|
|
| 935 |
|
| 936 |
+
submitted = st.form_submit_button("Trim")
|
| 937 |
+
if submitted:
|
| 938 |
+
st.write('initiated')
|
| 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 |
+
if player_lock:
|
| 961 |
+
# Create mask for lineups that contain all locked players
|
| 962 |
+
player_columns = [col for col in st.session_state['portfolio'].columns if col not in excluded_cols]
|
| 963 |
+
|
| 964 |
+
lock_mask = st.session_state['portfolio'][player_columns].apply(
|
| 965 |
+
lambda row: all(player in list(row) for player in player_lock), axis=1
|
| 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')
|