Spaces:
Running
Running
James McCool
commited on
Commit
·
eb50214
1
Parent(s):
70073ad
Enhance player selection logic in app.py by adding functionality to automatically fill eligible lineup slots based on selected players. This update improves lineup management by preventing duplicates and ensuring compliance with position limits, while also maintaining the existing quick fill options.
Browse files
app.py
CHANGED
@@ -870,7 +870,29 @@ with tab4:
|
|
870 |
height=500,
|
871 |
hide_index=True
|
872 |
)
|
873 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
874 |
with st.expander("Quick Fill Options"):
|
875 |
col1, col2, col3, col4 = st.columns(4)
|
876 |
with col1:
|
@@ -926,28 +948,6 @@ with tab4:
|
|
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]
|
932 |
-
player_row = player_select_df.iloc[[idx]]
|
933 |
-
eligible_positions = re.split(r'[/, ]+', player_row['Position'].iloc[0])
|
934 |
-
# Find the first eligible slot that is not full
|
935 |
-
slot_to_fill = None
|
936 |
-
for pos in eligible_positions:
|
937 |
-
if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
|
938 |
-
slot_to_fill = pos
|
939 |
-
break
|
940 |
-
if slot_to_fill is not None:
|
941 |
-
# Avoid duplicates
|
942 |
-
if not player_row['Player'].iloc[0] in st.session_state['handbuilder_lineup']['Player'].values:
|
943 |
-
# Add the slot info
|
944 |
-
player_row = player_row.assign(Slot=slot_to_fill)
|
945 |
-
st.session_state['handbuilder_lineup'] = pd.concat(
|
946 |
-
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot']]],
|
947 |
-
ignore_index=True
|
948 |
-
)
|
949 |
-
st.session_state['handbuilder_select_key'] += 1
|
950 |
-
st.rerun()
|
951 |
|
952 |
with col1:
|
953 |
st.subheader("Lineup Build")
|
|
|
870 |
height=500,
|
871 |
hide_index=True
|
872 |
)
|
873 |
+
# If a row is selected, add that player to the lineup and reset selection
|
874 |
+
if event and "rows" in event.selection and len(event.selection["rows"]) > 0:
|
875 |
+
idx = event.selection["rows"][0]
|
876 |
+
player_row = player_select_df.iloc[[idx]]
|
877 |
+
eligible_positions = re.split(r'[/, ]+', player_row['Position'].iloc[0])
|
878 |
+
# Find the first eligible slot that is not full
|
879 |
+
slot_to_fill = None
|
880 |
+
for pos in eligible_positions:
|
881 |
+
if slot_counts.get(pos, 0) < position_limits.get(pos, 0):
|
882 |
+
slot_to_fill = pos
|
883 |
+
break
|
884 |
+
if slot_to_fill is not None:
|
885 |
+
# Avoid duplicates
|
886 |
+
if not player_row['Player'].iloc[0] in st.session_state['handbuilder_lineup']['Player'].values:
|
887 |
+
# Add the slot info
|
888 |
+
player_row = player_row.assign(Slot=slot_to_fill)
|
889 |
+
st.session_state['handbuilder_lineup'] = pd.concat(
|
890 |
+
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot']]],
|
891 |
+
ignore_index=True
|
892 |
+
)
|
893 |
+
st.session_state['handbuilder_select_key'] += 1
|
894 |
+
st.rerun()
|
895 |
+
|
896 |
with st.expander("Quick Fill Options"):
|
897 |
col1, col2, col3, col4 = st.columns(4)
|
898 |
with col1:
|
|
|
948 |
slot_counts[slot_to_fill] = slot_counts.get(slot_to_fill, 0) + 1
|
949 |
st.rerun()
|
950 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
951 |
|
952 |
with col1:
|
953 |
st.subheader("Lineup Build")
|