Spaces:
Running
Running
James McCool
commited on
Commit
·
2b2c50a
1
Parent(s):
8348fb9
Update Handbuilder lineup DataFrame in app.py to include '2x%' column, enhancing player data management and display. Adjust related logic for player selection and summary calculations to ensure accurate representation of player statistics, improving user experience and clarity.
Browse files
app.py
CHANGED
@@ -817,7 +817,7 @@ with tab4:
|
|
817 |
|
818 |
# --- LINEUP STATE ---
|
819 |
if 'handbuilder_lineup' not in st.session_state:
|
820 |
-
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', 'Own%'])
|
821 |
if 'handbuilder_select_key' not in st.session_state:
|
822 |
st.session_state['handbuilder_select_key'] = 0
|
823 |
|
@@ -843,9 +843,9 @@ with tab4:
|
|
843 |
if selected_teams:
|
844 |
player_select_df = dk_roo[
|
845 |
dk_roo['Team'].isin(selected_teams)
|
846 |
-
][['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
|
847 |
else:
|
848 |
-
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
849 |
|
850 |
# --- FILTER OUT PLAYERS WHOSE ALL ELIGIBLE POSITIONS ARE FILLED ---
|
851 |
def is_player_eligible(row):
|
@@ -887,7 +887,7 @@ with tab4:
|
|
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', 'Own%', 'Slot']]],
|
891 |
ignore_index=True
|
892 |
)
|
893 |
st.session_state['handbuilder_select_key'] += 1
|
@@ -898,7 +898,7 @@ with tab4:
|
|
898 |
|
899 |
# --- EXPLICIT LINEUP ORDER ---
|
900 |
lineup_slots = ['SP', 'SP', 'C', '1B', '2B', '3B', 'SS', 'OF', 'OF', 'OF']
|
901 |
-
display_columns = ['Slot', 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', 'Own%']
|
902 |
|
903 |
filled_lineup = st.session_state['handbuilder_lineup']
|
904 |
display_rows = []
|
@@ -917,6 +917,7 @@ with tab4:
|
|
917 |
'Team': row['Team'],
|
918 |
'Salary': row['Salary'],
|
919 |
'Median': row['Median'],
|
|
|
920 |
'Own%': row['Own%']
|
921 |
})
|
922 |
else:
|
@@ -928,6 +929,7 @@ with tab4:
|
|
928 |
'Team': '',
|
929 |
'Salary': np.nan,
|
930 |
'Median': np.nan,
|
|
|
931 |
'Own%': np.nan
|
932 |
})
|
933 |
|
@@ -935,7 +937,7 @@ with tab4:
|
|
935 |
|
936 |
# Show the lineup table with single-row selection for removal
|
937 |
event_remove = st.dataframe(
|
938 |
-
lineup_display_df.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn', subset=['Median']).background_gradient(cmap='RdYlGn_r', subset=['Order', 'Salary', 'Own%']).format(precision=2),
|
939 |
on_select="rerun",
|
940 |
selection_mode=["single-row"],
|
941 |
key="lineup_remove",
|
@@ -958,6 +960,7 @@ with tab4:
|
|
958 |
if not filled_lineup.empty:
|
959 |
total_salary = filled_lineup['Salary'].sum()
|
960 |
total_median = filled_lineup['Median'].sum()
|
|
|
961 |
total_own = filled_lineup['Own%'].sum()
|
962 |
most_common_team = filled_lineup['Team'].mode()[0] if not filled_lineup['Team'].mode().empty else ""
|
963 |
|
@@ -969,6 +972,7 @@ with tab4:
|
|
969 |
'Team': [most_common_team],
|
970 |
'Salary': [total_salary],
|
971 |
'Median': [total_median],
|
|
|
972 |
'Own%': [total_own]
|
973 |
})
|
974 |
summary_row = summary_row[display_columns]
|
@@ -982,5 +986,5 @@ with tab4:
|
|
982 |
|
983 |
# Optionally, add a button to clear the lineup
|
984 |
if st.button("Clear Lineup", key='clear_lineup'):
|
985 |
-
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', 'Own%', 'Slot', 'Order'])
|
986 |
st.rerun()
|
|
|
817 |
|
818 |
# --- LINEUP STATE ---
|
819 |
if 'handbuilder_lineup' not in st.session_state:
|
820 |
+
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%'])
|
821 |
if 'handbuilder_select_key' not in st.session_state:
|
822 |
st.session_state['handbuilder_select_key'] = 0
|
823 |
|
|
|
843 |
if selected_teams:
|
844 |
player_select_df = dk_roo[
|
845 |
dk_roo['Team'].isin(selected_teams)
|
846 |
+
][['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
|
847 |
else:
|
848 |
+
player_select_df = dk_roo[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
849 |
|
850 |
# --- FILTER OUT PLAYERS WHOSE ALL ELIGIBLE POSITIONS ARE FILLED ---
|
851 |
def is_player_eligible(row):
|
|
|
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
|
|
|
898 |
|
899 |
# --- EXPLICIT LINEUP ORDER ---
|
900 |
lineup_slots = ['SP', 'SP', 'C', '1B', '2B', '3B', 'SS', 'OF', 'OF', 'OF']
|
901 |
+
display_columns = ['Slot', 'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%']
|
902 |
|
903 |
filled_lineup = st.session_state['handbuilder_lineup']
|
904 |
display_rows = []
|
|
|
917 |
'Team': row['Team'],
|
918 |
'Salary': row['Salary'],
|
919 |
'Median': row['Median'],
|
920 |
+
'2x%': row['2x%'],
|
921 |
'Own%': row['Own%']
|
922 |
})
|
923 |
else:
|
|
|
929 |
'Team': '',
|
930 |
'Salary': np.nan,
|
931 |
'Median': np.nan,
|
932 |
+
'2x%': np.nan,
|
933 |
'Own%': np.nan
|
934 |
})
|
935 |
|
|
|
937 |
|
938 |
# Show the lineup table with single-row selection for removal
|
939 |
event_remove = st.dataframe(
|
940 |
+
lineup_display_df.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn', subset=['Median', '2x%']).background_gradient(cmap='RdYlGn_r', subset=['Order', 'Salary', 'Own%']).format(precision=2),
|
941 |
on_select="rerun",
|
942 |
selection_mode=["single-row"],
|
943 |
key="lineup_remove",
|
|
|
960 |
if not filled_lineup.empty:
|
961 |
total_salary = filled_lineup['Salary'].sum()
|
962 |
total_median = filled_lineup['Median'].sum()
|
963 |
+
avg_2x = filled_lineup['2x%'].mean()
|
964 |
total_own = filled_lineup['Own%'].sum()
|
965 |
most_common_team = filled_lineup['Team'].mode()[0] if not filled_lineup['Team'].mode().empty else ""
|
966 |
|
|
|
972 |
'Team': [most_common_team],
|
973 |
'Salary': [total_salary],
|
974 |
'Median': [total_median],
|
975 |
+
'2x%': [avg_2x],
|
976 |
'Own%': [total_own]
|
977 |
})
|
978 |
summary_row = summary_row[display_columns]
|
|
|
986 |
|
987 |
# Optionally, add a button to clear the lineup
|
988 |
if st.button("Clear Lineup", key='clear_lineup'):
|
989 |
+
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot', 'Order'])
|
990 |
st.rerun()
|