James McCool commited on
Commit
78266ef
·
1 Parent(s): 1ddfb47

Implement position limits and filtering logic in Handbuilder tab of app.py to manage player selection more effectively. This update enhances lineup management by preventing selection of players whose positions have reached their maximum count, improving user experience.

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -802,6 +802,29 @@ with tab3:
802
  with tab4:
803
  st.header("Handbuilder")
804
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805
  # --- TEAM FILTER UI ---
806
  all_teams = sorted(dk_roo['Team'].unique())
807
  st.markdown("**Toggle teams to include:**")
@@ -828,29 +851,6 @@ with tab4:
828
  if positions_at_max:
829
  player_select_df = player_select_df[~player_select_df['Position'].isin(positions_at_max)]
830
 
831
- # --- LINEUP STATE ---
832
- if 'handbuilder_lineup' not in st.session_state:
833
- st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', 'Own%'])
834
- if 'handbuilder_select_key' not in st.session_state:
835
- st.session_state['handbuilder_select_key'] = 0
836
-
837
- # --- POSITION LIMITS ---
838
- position_limits = {
839
- 'SP': 2,
840
- # Add other positions and their limits as needed
841
- # e.g. 'C': 1, '1B': 1, '2B': 1, '3B': 1, 'SS': 1, 'OF': 3
842
- }
843
-
844
- # Count positions in the current lineup
845
- lineup = st.session_state['handbuilder_lineup']
846
- position_counts = lineup['Position'].value_counts() if not lineup.empty else {}
847
-
848
- # Build a set of positions that have reached their max
849
- positions_at_max = set()
850
- for pos, max_count in position_limits.items():
851
- if position_counts.get(pos, 0) >= max_count:
852
- positions_at_max.add(pos)
853
-
854
  col1, col2 = st.columns([1, 2])
855
  with col2:
856
  st.subheader("Player Select")
 
802
  with tab4:
803
  st.header("Handbuilder")
804
 
805
+ # --- LINEUP STATE ---
806
+ if 'handbuilder_lineup' not in st.session_state:
807
+ st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', 'Own%'])
808
+ if 'handbuilder_select_key' not in st.session_state:
809
+ st.session_state['handbuilder_select_key'] = 0
810
+
811
+ # --- POSITION LIMITS ---
812
+ position_limits = {
813
+ 'SP': 2,
814
+ # Add other positions and their limits as needed
815
+ # e.g. 'C': 1, '1B': 1, '2B': 1, '3B': 1, 'SS': 1, 'OF': 3
816
+ }
817
+
818
+ # Count positions in the current lineup
819
+ lineup = st.session_state['handbuilder_lineup']
820
+ position_counts = lineup['Position'].value_counts() if not lineup.empty else {}
821
+
822
+ # Build a set of positions that have reached their max
823
+ positions_at_max = set()
824
+ for pos, max_count in position_limits.items():
825
+ if position_counts.get(pos, 0) >= max_count:
826
+ positions_at_max.add(pos)
827
+
828
  # --- TEAM FILTER UI ---
829
  all_teams = sorted(dk_roo['Team'].unique())
830
  st.markdown("**Toggle teams to include:**")
 
851
  if positions_at_max:
852
  player_select_df = player_select_df[~player_select_df['Position'].isin(positions_at_max)]
853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  col1, col2 = st.columns([1, 2])
855
  with col2:
856
  st.subheader("Player Select")