James McCool commited on
Commit
c6c03f4
·
1 Parent(s): ad4de6d

Add player filters to app.py for enhanced selection options

Browse files

Implemented player filters allowing users to select specific positions and set a maximum salary. Updated player selection DataFrame to reflect these filters, improving user experience and data management in lineup creation.

Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -844,6 +844,18 @@ with tab4:
844
  lineup = st.session_state['handbuilder_lineup']
845
  slot_counts = lineup['Slot'].value_counts() if not lineup.empty else {}
846
 
 
 
 
 
 
 
 
 
 
 
 
 
847
  # --- TEAM FILTER UI ---
848
  with st.expander("Team Filters"):
849
  all_teams = sorted(handbuild_roo['Team'].unique())
@@ -867,6 +879,13 @@ with tab4:
867
  else:
868
  player_select_df = handbuild_roo[['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
869
 
 
 
 
 
 
 
 
870
  with st.expander("Quick Fill Options"):
871
  auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
872
  auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
 
844
  lineup = st.session_state['handbuilder_lineup']
845
  slot_counts = lineup['Slot'].value_counts() if not lineup.empty else {}
846
 
847
+ # --- PLAYER FILTERS ---
848
+ with st.expander("Player Filters"):
849
+ col1, col2 = st.columns(2)
850
+ with col1:
851
+ pos_var3 = st.selectbox("Which position(s) would you like to view?", ['All', 'Specific'], key='pos_var2')
852
+ if pos_var3 == 'Specific':
853
+ pos_select3 = st.multiselect("Select your position(s)", options=['P', 'C', '1B', '2B', '3B', 'SS', 'OF'], key='pos_select3')
854
+ else:
855
+ pos_select3 = None
856
+ with col2:
857
+ salary_var = st.number_input("Salary Max", min_value = 0, max_value = 20000, value = 20000, step = 100)
858
+
859
  # --- TEAM FILTER UI ---
860
  with st.expander("Team Filters"):
861
  all_teams = sorted(handbuild_roo['Team'].unique())
 
879
  else:
880
  player_select_df = handbuild_roo[['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
881
 
882
+ # If no teams selected, show all teams
883
+ if pos_select3 is not None:
884
+ position_mask_2 = handbuild_roo['Position'].apply(lambda x: any(pos in x for pos in pos_select3))
885
+ player_select_df = handbuild_roo[position_mask_2][['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
886
+ else:
887
+ player_select_df = handbuild_roo[['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
888
+
889
  with st.expander("Quick Fill Options"):
890
  auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
891
  auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])