James McCool commited on
Commit
70073ad
·
1 Parent(s): 63cac6f

Refactor Quick Fill Options in app.py by reintroducing the feature with improved layout and logic for auto-filling players based on team selection and size. This enhances user experience in lineup management.

Browse files
Files changed (1) hide show
  1. app.py +55 -55
app.py CHANGED
@@ -831,61 +831,6 @@ with tab4:
831
  st.markdown("**Toggle teams to include:**")
832
  team_cols = st.columns(len(all_teams) // 2 + 1)
833
 
834
- with st.expander("Quick Fill Options"):
835
- col1, col2, col3, col4 = st.columns(4)
836
- with col1:
837
- auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
838
- with col2:
839
- auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
840
- with col3:
841
- auto_range_var = st.selectbox("Auto Fill Order", options=['Top', 'Mid', 'Wrap'])
842
- with col4:
843
- # --- QUICK FILL LOGIC ---
844
- if st.button("Quick Fill", key="quick_fill"):
845
- # 1. Get all eligible players from the selected team, not already in the lineup
846
- current_players = set(st.session_state['handbuilder_lineup']['Player'])
847
- team_players = player_select_df[
848
- (player_select_df['Team'] == auto_team_var) &
849
- (~player_select_df['Player'].isin(current_players))
850
- ].copy()
851
-
852
- # 2. Sort by Order
853
- team_players = team_players.sort_values(by='Order')
854
-
855
- # 3. Select the order range
856
- if auto_range_var == 'Top':
857
- selected_players = team_players.head(auto_size_var)
858
- elif auto_range_var == 'Mid':
859
- mid_start = max(0, (len(team_players) - auto_size_var) // 2)
860
- selected_players = team_players.iloc[mid_start:mid_start + auto_size_var]
861
- elif auto_range_var == 'Wrap':
862
- selected_players = team_players.tail(auto_size_var)
863
- else:
864
- selected_players = team_players.head(auto_size_var)
865
-
866
- # 4. Add each player to the lineup, filling the first available eligible slot
867
- for _, player_row in selected_players.iterrows():
868
- eligible_positions = re.split(r'[/, ]+', player_row['Position'])
869
- slot_to_fill = None
870
- for pos in eligible_positions:
871
- if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
872
- slot_to_fill = pos
873
- break
874
- if slot_to_fill is not None:
875
- # Avoid duplicates
876
- if player_row['Player'] not in st.session_state['handbuilder_lineup']['Player'].values:
877
- add_row = player_row.copy()
878
- add_row['Slot'] = slot_to_fill
879
- st.session_state['handbuilder_lineup'] = pd.concat(
880
- [st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
881
- 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
882
- ]]])],
883
- ignore_index=True
884
- )
885
- # Update slot_counts for next player
886
- slot_counts[slot_to_fill] = slot_counts.get(slot_to_fill, 0) + 1
887
- st.rerun()
888
-
889
  selected_teams = []
890
  for idx, team in enumerate(all_teams):
891
  col = team_cols[idx % len(team_cols)]
@@ -926,6 +871,61 @@ with tab4:
926
  hide_index=True
927
  )
928
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
929
  # If a row is selected, add that player to the lineup and reset selection
930
  if event and "rows" in event.selection and len(event.selection["rows"]) > 0:
931
  idx = event.selection["rows"][0]
 
831
  st.markdown("**Toggle teams to include:**")
832
  team_cols = st.columns(len(all_teams) // 2 + 1)
833
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834
  selected_teams = []
835
  for idx, team in enumerate(all_teams):
836
  col = team_cols[idx % len(team_cols)]
 
871
  hide_index=True
872
  )
873
 
874
+ with st.expander("Quick Fill Options"):
875
+ col1, col2, col3, col4 = st.columns(4)
876
+ with col1:
877
+ auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
878
+ with col2:
879
+ auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
880
+ with col3:
881
+ auto_range_var = st.selectbox("Auto Fill Order", options=['Top', 'Mid', 'Wrap'])
882
+ with col4:
883
+ # --- QUICK FILL LOGIC ---
884
+ if st.button("Quick Fill", key="quick_fill"):
885
+ # 1. Get all eligible players from the selected team, not already in the lineup
886
+ current_players = set(st.session_state['handbuilder_lineup']['Player'])
887
+ team_players = player_select_df[
888
+ (player_select_df['Team'] == auto_team_var) &
889
+ (~player_select_df['Player'].isin(current_players))
890
+ ].copy()
891
+
892
+ # 2. Sort by Order
893
+ team_players = team_players.sort_values(by='Order')
894
+
895
+ # 3. Select the order range
896
+ if auto_range_var == 'Top':
897
+ selected_players = team_players.head(auto_size_var)
898
+ elif auto_range_var == 'Mid':
899
+ mid_start = max(0, (len(team_players) - auto_size_var) // 2)
900
+ selected_players = team_players.iloc[mid_start:mid_start + auto_size_var]
901
+ elif auto_range_var == 'Wrap':
902
+ selected_players = team_players.tail(auto_size_var)
903
+ else:
904
+ selected_players = team_players.head(auto_size_var)
905
+
906
+ # 4. Add each player to the lineup, filling the first available eligible slot
907
+ for _, player_row in selected_players.iterrows():
908
+ eligible_positions = re.split(r'[/, ]+', player_row['Position'])
909
+ slot_to_fill = None
910
+ for pos in eligible_positions:
911
+ if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
912
+ slot_to_fill = pos
913
+ break
914
+ if slot_to_fill is not None:
915
+ # Avoid duplicates
916
+ if player_row['Player'] not in st.session_state['handbuilder_lineup']['Player'].values:
917
+ add_row = player_row.copy()
918
+ add_row['Slot'] = slot_to_fill
919
+ st.session_state['handbuilder_lineup'] = pd.concat(
920
+ [st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
921
+ 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
922
+ ]]])],
923
+ ignore_index=True
924
+ )
925
+ # Update slot_counts for next player
926
+ slot_counts[slot_to_fill] = slot_counts.get(slot_to_fill, 0) + 1
927
+ st.rerun()
928
+
929
  # If a row is selected, add that player to the lineup and reset selection
930
  if event and "rows" in event.selection and len(event.selection["rows"]) > 0:
931
  idx = event.selection["rows"][0]