Spaces:
Running
Running
James McCool
commited on
Commit
·
1ddfb47
1
Parent(s):
00eff85
Add position limits and filtering for player selection in Handbuilder tab of app.py. Implement logic to exclude players whose positions have reached their maximum count, enhancing lineup management and user experience.
Browse files
app.py
CHANGED
@@ -824,12 +824,33 @@ with tab4:
|
|
824 |
else:
|
825 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
826 |
|
|
|
|
|
|
|
|
|
827 |
# --- LINEUP STATE ---
|
828 |
if 'handbuilder_lineup' not in st.session_state:
|
829 |
-
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Team', 'Salary', 'Median', 'Own%'])
|
830 |
if 'handbuilder_select_key' not in st.session_state:
|
831 |
st.session_state['handbuilder_select_key'] = 0
|
832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
col1, col2 = st.columns([1, 2])
|
834 |
with col2:
|
835 |
st.subheader("Player Select")
|
@@ -837,13 +858,15 @@ with tab4:
|
|
837 |
player_select_df,
|
838 |
on_select="rerun",
|
839 |
selection_mode=["single-row"],
|
840 |
-
key=f"handbuilder_select_{st.session_state['handbuilder_select_key']}"
|
|
|
|
|
841 |
)
|
842 |
|
843 |
# If a row is selected, add that player to the lineup and reset selection
|
844 |
if event and "rows" in event.selection and len(event.selection["rows"]) > 0:
|
845 |
idx = event.selection["rows"][0]
|
846 |
-
player_row = player_select_df.iloc[[idx]][['Player', 'Team', 'Salary', 'Median', 'Own%']]
|
847 |
# Avoid duplicates
|
848 |
if not player_row['Player'].iloc[0] in st.session_state['handbuilder_lineup']['Player'].values:
|
849 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
@@ -859,7 +882,7 @@ with tab4:
|
|
859 |
st.dataframe(
|
860 |
st.session_state['handbuilder_lineup'],
|
861 |
use_container_width=True,
|
862 |
-
height=
|
863 |
hide_index=True
|
864 |
)
|
865 |
|
|
|
824 |
else:
|
825 |
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
826 |
|
827 |
+
# Remove players whose position is at max
|
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")
|
|
|
858 |
player_select_df,
|
859 |
on_select="rerun",
|
860 |
selection_mode=["single-row"],
|
861 |
+
key=f"handbuilder_select_{st.session_state['handbuilder_select_key']}",
|
862 |
+
height=500,
|
863 |
+
hide_index=True
|
864 |
)
|
865 |
|
866 |
# If a row is selected, add that player to the lineup and reset selection
|
867 |
if event and "rows" in event.selection and len(event.selection["rows"]) > 0:
|
868 |
idx = event.selection["rows"][0]
|
869 |
+
player_row = player_select_df.iloc[[idx]][['Player', 'Position', 'Team', 'Salary', 'Median', 'Own%']]
|
870 |
# Avoid duplicates
|
871 |
if not player_row['Player'].iloc[0] in st.session_state['handbuilder_lineup']['Player'].values:
|
872 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
|
|
882 |
st.dataframe(
|
883 |
st.session_state['handbuilder_lineup'],
|
884 |
use_container_width=True,
|
885 |
+
height=500,
|
886 |
hide_index=True
|
887 |
)
|
888 |
|