James McCool commited on
Commit
f89ff68
·
1 Parent(s): 83b30d9

Add quick fill options in app.py to streamline player selection for lineups. Implemented logic to auto-fill eligible players based on team, size, and order preferences, enhancing user experience and efficiency in lineup management.

Browse files
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -849,6 +849,56 @@ with tab4:
849
  ][['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
850
  else:
851
  player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
852
 
853
  # --- FILTER OUT PLAYERS WHOSE ALL ELIGIBLE POSITIONS ARE FILLED ---
854
  def is_player_eligible(row):
@@ -894,56 +944,6 @@ with tab4:
894
  )
895
  st.session_state['handbuilder_select_key'] += 1
896
  st.rerun()
897
-
898
- with st.expander("Quick Fill Options"):
899
- auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
900
- auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
901
- auto_range_var = st.selectbox("Auto Fill Order", options=['Top', 'Mid', 'Wrap'])
902
- # --- QUICK FILL LOGIC ---
903
- if st.button("Quick Fill", key="quick_fill"):
904
- # 1. Get all eligible players from the selected team, not already in the lineup
905
- current_players = set(st.session_state['handbuilder_lineup']['Player'])
906
- team_players = player_select_df[
907
- (player_select_df['Team'] == auto_team_var) &
908
- (~player_select_df['Player'].isin(current_players))
909
- ].copy()
910
-
911
- # 2. Sort by Order
912
- team_players = team_players.sort_values(by='Order')
913
-
914
- # 3. Select the order range
915
- if auto_range_var == 'Top':
916
- selected_players = team_players[team_players['Order'] > 0].head(auto_size_var)
917
- elif auto_range_var == 'Mid':
918
- mid_start = max(0, (len(team_players[team_players['Order'] > 0]) - auto_size_var) // 2)
919
- selected_players = team_players[team_players['Order'] > 0].iloc[mid_start:mid_start + auto_size_var]
920
- elif auto_range_var == 'Wrap':
921
- selected_players = team_players[team_players['Order'] > 0].tail(auto_size_var)
922
- else:
923
- selected_players = team_players[team_players['Order'] > 0].head(auto_size_var)
924
-
925
- # 4. Add each player to the lineup, filling the first available eligible slot
926
- for _, player_row in selected_players.iterrows():
927
- eligible_positions = re.split(r'[/, ]+', player_row['Position'])
928
- slot_to_fill = None
929
- for pos in eligible_positions:
930
- if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
931
- slot_to_fill = pos
932
- break
933
- if slot_to_fill is not None:
934
- # Avoid duplicates
935
- if player_row['Player'] not in st.session_state['handbuilder_lineup']['Player'].values:
936
- add_row = player_row.copy()
937
- add_row['Slot'] = slot_to_fill
938
- st.session_state['handbuilder_lineup'] = pd.concat(
939
- [st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
940
- 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
941
- ]]])],
942
- ignore_index=True
943
- )
944
- # Update slot_counts for next player
945
- slot_counts[slot_to_fill] = slot_counts.get(slot_to_fill, 0) + 1
946
- st.rerun()
947
 
948
 
949
  with col1:
 
849
  ][['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
850
  else:
851
  player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
852
+
853
+ with st.expander("Quick Fill Options"):
854
+ auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
855
+ auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
856
+ auto_range_var = st.selectbox("Auto Fill Order", options=['Top', 'Mid', 'Wrap'])
857
+ # --- QUICK FILL LOGIC ---
858
+ if st.button("Quick Fill", key="quick_fill"):
859
+ # 1. Get all eligible players from the selected team, not already in the lineup
860
+ current_players = set(st.session_state['handbuilder_lineup']['Player'])
861
+ team_players = player_select_df[
862
+ (player_select_df['Team'] == auto_team_var) &
863
+ (~player_select_df['Player'].isin(current_players))
864
+ ].copy()
865
+
866
+ # 2. Sort by Order
867
+ team_players = team_players.sort_values(by='Order')
868
+
869
+ # 3. Select the order range
870
+ if auto_range_var == 'Top':
871
+ selected_players = team_players[team_players['Order'] > 0].head(auto_size_var)
872
+ elif auto_range_var == 'Mid':
873
+ mid_start = max(0, (len(team_players[team_players['Order'] > 0]) - auto_size_var) // 2)
874
+ selected_players = team_players[team_players['Order'] > 0].iloc[mid_start:mid_start + auto_size_var]
875
+ elif auto_range_var == 'Wrap':
876
+ selected_players = team_players[team_players['Order'] > 0].tail(auto_size_var)
877
+ else:
878
+ selected_players = team_players[team_players['Order'] > 0].head(auto_size_var)
879
+
880
+ # 4. Add each player to the lineup, filling the first available eligible slot
881
+ for _, player_row in selected_players.iterrows():
882
+ eligible_positions = re.split(r'[/, ]+', player_row['Position'])
883
+ slot_to_fill = None
884
+ for pos in eligible_positions:
885
+ if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
886
+ slot_to_fill = pos
887
+ break
888
+ if slot_to_fill is not None:
889
+ # Avoid duplicates
890
+ if player_row['Player'] not in st.session_state['handbuilder_lineup']['Player'].values:
891
+ add_row = player_row.copy()
892
+ add_row['Slot'] = slot_to_fill
893
+ st.session_state['handbuilder_lineup'] = pd.concat(
894
+ [st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
895
+ 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
896
+ ]]])],
897
+ ignore_index=True
898
+ )
899
+ # Update slot_counts for next player
900
+ slot_counts[slot_to_fill] = slot_counts.get(slot_to_fill, 0) + 1
901
+ st.rerun()
902
 
903
  # --- FILTER OUT PLAYERS WHOSE ALL ELIGIBLE POSITIONS ARE FILLED ---
904
  def is_player_eligible(row):
 
944
  )
945
  st.session_state['handbuilder_select_key'] += 1
946
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
 
948
 
949
  with col1: