Spaces:
Running
Running
James McCool
commited on
Commit
·
63cac6f
1
Parent(s):
93f2f42
Add team filter and quick fill options in app.py to enhance lineup management. Introduced UI elements for auto-filling players based on selected team and size, improving user experience and efficiency in lineup building.
Browse files
app.py
CHANGED
@@ -826,10 +826,66 @@ with tab4:
|
|
826 |
slot_counts = lineup['Slot'].value_counts() if not lineup.empty else {}
|
827 |
|
828 |
# --- TEAM FILTER UI ---
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
selected_teams = []
|
834 |
for idx, team in enumerate(all_teams):
|
835 |
col = team_cols[idx % len(team_cols)]
|
|
|
826 |
slot_counts = lineup['Slot'].value_counts() if not lineup.empty else {}
|
827 |
|
828 |
# --- TEAM FILTER UI ---
|
829 |
+
with st.expander("Team Filters"):
|
830 |
+
all_teams = sorted(dk_roo['Team'].unique())
|
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)]
|