Spaces:
Running
Running
James McCool
commited on
Commit
·
a924502
1
Parent(s):
dbd6109
Enhance player data management in app.py by adding 'Team_Total' and 'Opp_Total' columns to the lineup. Updated DataFrame structures and quick fill options to incorporate these new metrics, improving the clarity and depth of player selection information.
Browse files
app.py
CHANGED
@@ -89,6 +89,8 @@ def init_baselines():
|
|
89 |
hold_frame['Order'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['Order']), 0)
|
90 |
hold_frame['Hand'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['bats']), hold_frame['Player'].map(RHH_Info.set_index('Player')['Hand']))
|
91 |
hold_frame['Opp'] = hold_frame['Team'].map(RHH_Info.set_index('Team')['Opp'])
|
|
|
|
|
92 |
|
93 |
roo_data.insert(3, 'Opp', hold_frame['Opp'])
|
94 |
roo_data.insert(4, 'Hand', hold_frame['Hand'])
|
@@ -96,6 +98,8 @@ def init_baselines():
|
|
96 |
roo_data.insert(5, 'Order', hold_frame['Order'].astype(int))
|
97 |
except:
|
98 |
roo_data.insert(5, 'Order', hold_frame['Order'])
|
|
|
|
|
99 |
|
100 |
dk_roo = roo_data[roo_data['Site'] == 'Draftkings']
|
101 |
dk_id_map = dict(zip(dk_roo['Player'], dk_roo['player_ID']))
|
@@ -832,7 +836,7 @@ with tab4:
|
|
832 |
|
833 |
# --- LINEUP STATE ---
|
834 |
if 'handbuilder_lineup' not in st.session_state:
|
835 |
-
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%'])
|
836 |
if 'handbuilder_select_key' not in st.session_state:
|
837 |
st.session_state['handbuilder_select_key'] = 0
|
838 |
|
@@ -859,14 +863,14 @@ with tab4:
|
|
859 |
if selected_teams:
|
860 |
player_select_df = handbuild_roo[
|
861 |
handbuild_roo['Team'].isin(selected_teams)
|
862 |
-
][['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
|
863 |
else:
|
864 |
-
player_select_df = handbuild_roo[['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
865 |
|
866 |
with st.expander("Quick Fill Options"):
|
867 |
auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
|
868 |
auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
|
869 |
-
auto_range_var = st.selectbox("Auto Fill Order", options=['Top (1-5)', 'Mid (
|
870 |
# --- QUICK FILL LOGIC ---
|
871 |
if st.button("Quick Fill", key="quick_fill"):
|
872 |
# 1. Get all eligible players from the selected team, not already in the lineup
|
@@ -907,7 +911,7 @@ with tab4:
|
|
907 |
add_row['Slot'] = slot_to_fill
|
908 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
909 |
[st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
|
910 |
-
'Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
|
911 |
]]])],
|
912 |
ignore_index=True
|
913 |
)
|
@@ -954,7 +958,7 @@ with tab4:
|
|
954 |
# Add the slot info
|
955 |
player_row = player_row.assign(Slot=slot_to_fill)
|
956 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
957 |
-
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Order', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot']]],
|
958 |
ignore_index=True
|
959 |
)
|
960 |
st.session_state['handbuilder_select_key'] += 1
|
@@ -1087,5 +1091,5 @@ with tab4:
|
|
1087 |
|
1088 |
# Optionally, add a button to clear the lineup
|
1089 |
if st.button("Clear Lineup", key='clear_lineup'):
|
1090 |
-
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Salary', 'Median', '2x%', 'Own%', 'Slot', 'Order'])
|
1091 |
st.rerun()
|
|
|
89 |
hold_frame['Order'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['Order']), 0)
|
90 |
hold_frame['Hand'] = np.where(hold_frame['pos_group'] == 'Hitters', hold_frame['Player'].map(RHP_Info.set_index('Player')['bats']), hold_frame['Player'].map(RHH_Info.set_index('Player')['Hand']))
|
91 |
hold_frame['Opp'] = hold_frame['Team'].map(RHH_Info.set_index('Team')['Opp'])
|
92 |
+
hold_frame['Team_Total'] = hold_frame['Team'].map(RHP_Info.set_index('Team')['Opp_TT'])
|
93 |
+
hold_frame['Opp_Total'] = hold_frame['Team'].map(RHH_Info.set_index('Team')['Opp_TT'])
|
94 |
|
95 |
roo_data.insert(3, 'Opp', hold_frame['Opp'])
|
96 |
roo_data.insert(4, 'Hand', hold_frame['Hand'])
|
|
|
98 |
roo_data.insert(5, 'Order', hold_frame['Order'].astype(int))
|
99 |
except:
|
100 |
roo_data.insert(5, 'Order', hold_frame['Order'])
|
101 |
+
roo_data.insert(6, 'Team_Total', hold_frame['Team_Total'])
|
102 |
+
roo_data.insert(7, 'Opp_Total', hold_frame['Opp_Total'])
|
103 |
|
104 |
dk_roo = roo_data[roo_data['Site'] == 'Draftkings']
|
105 |
dk_id_map = dict(zip(dk_roo['Player'], dk_roo['player_ID']))
|
|
|
836 |
|
837 |
# --- LINEUP STATE ---
|
838 |
if 'handbuilder_lineup' not in st.session_state:
|
839 |
+
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Order', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Own%'])
|
840 |
if 'handbuilder_select_key' not in st.session_state:
|
841 |
st.session_state['handbuilder_select_key'] = 0
|
842 |
|
|
|
863 |
if selected_teams:
|
864 |
player_select_df = handbuild_roo[
|
865 |
handbuild_roo['Team'].isin(selected_teams)
|
866 |
+
][['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).sort_values(by='Order', ascending=True).copy()
|
867 |
else:
|
868 |
+
player_select_df = handbuild_roo[['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Order', 'Hand', 'Own%']].drop_duplicates(subset=['Player', 'Team']).copy()
|
869 |
|
870 |
with st.expander("Quick Fill Options"):
|
871 |
auto_team_var = st.selectbox("Auto Fill Team", options=all_teams)
|
872 |
auto_size_var = st.selectbox("Auto Fill Size", options=[3, 4, 5])
|
873 |
+
auto_range_var = st.selectbox("Auto Fill Order", options=['Top (1-5)', 'Mid (4-8)', 'Wrap (7-2)'])
|
874 |
# --- QUICK FILL LOGIC ---
|
875 |
if st.button("Quick Fill", key="quick_fill"):
|
876 |
# 1. Get all eligible players from the selected team, not already in the lineup
|
|
|
911 |
add_row['Slot'] = slot_to_fill
|
912 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
913 |
[st.session_state['handbuilder_lineup'], pd.DataFrame([add_row[[
|
914 |
+
'Player', 'Order', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Own%', 'Slot'
|
915 |
]]])],
|
916 |
ignore_index=True
|
917 |
)
|
|
|
958 |
# Add the slot info
|
959 |
player_row = player_row.assign(Slot=slot_to_fill)
|
960 |
st.session_state['handbuilder_lineup'] = pd.concat(
|
961 |
+
[st.session_state['handbuilder_lineup'], player_row[['Player', 'Order', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Own%', 'Slot']]],
|
962 |
ignore_index=True
|
963 |
)
|
964 |
st.session_state['handbuilder_select_key'] += 1
|
|
|
1091 |
|
1092 |
# Optionally, add a button to clear the lineup
|
1093 |
if st.button("Clear Lineup", key='clear_lineup'):
|
1094 |
+
st.session_state['handbuilder_lineup'] = pd.DataFrame(columns=['Player', 'Position', 'Team', 'Team_Total', 'Opp_Total', 'Salary', 'Median', '2x%', 'Own%', 'Slot', 'Order'])
|
1095 |
st.rerun()
|