James McCool commited on
Commit
fa0e4a7
·
1 Parent(s): e32d65b

Enhance lineup display in Handbuilder tab of app.py by implementing an explicit order for player slots. Update DataFrame to show filled and unfilled slots clearly, and adjust summary calculations to ensure accurate representation of total salary, median, and ownership percentage. This improves user experience and data clarity.

Browse files
Files changed (1) hide show
  1. app.py +49 -11
app.py CHANGED
@@ -895,36 +895,74 @@ with tab4:
895
 
896
  with col1:
897
  st.subheader("Lineup")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
898
  st.dataframe(
899
- st.session_state['handbuilder_lineup'][['Player', 'Slot', 'Position', 'Team', 'Salary', 'Median', 'Own%']],
900
  use_container_width=True,
901
- height=450,
902
  hide_index=True
903
  )
904
 
905
  # --- SUMMARY ROW ---
906
- lineup = st.session_state['handbuilder_lineup']
907
- if not lineup.empty:
908
- total_salary = lineup['Salary'].sum()
909
- total_median = lineup['Median'].sum()
910
- total_own = lineup['Own%'].sum()
911
- most_common_team = lineup['Team'].mode()[0] if not lineup['Team'].mode().empty else ""
912
 
913
  summary_row = pd.DataFrame({
914
- 'Player': ['TOTAL'],
915
  'Slot': [''],
 
916
  'Position': [''],
917
  'Team': [most_common_team],
918
  'Salary': [total_salary],
919
  'Median': [total_median],
920
  'Own%': [total_own]
921
  })
922
- summary_row = summary_row[lineup[['Player', 'Slot', 'Position', 'Team', 'Salary', 'Median', 'Own%']].columns]
923
 
924
  st.dataframe(
925
  summary_row,
926
  use_container_width=True,
927
- height=50,
928
  hide_index=True
929
  )
930
 
 
895
 
896
  with col1:
897
  st.subheader("Lineup")
898
+
899
+ # --- EXPLICIT LINEUP ORDER ---
900
+ lineup_slots = ['SP', 'SP', 'C', '1B', '2B', '3B', 'SS', 'OF', 'OF', 'OF']
901
+ display_columns = ['Slot', 'Player', 'Position', 'Team', 'Salary', 'Median', 'Own%']
902
+
903
+ # Prepare a DataFrame for display in the explicit order
904
+ filled_lineup = st.session_state['handbuilder_lineup']
905
+ display_rows = []
906
+ used_indices = set()
907
+
908
+ for slot in lineup_slots:
909
+ # Find the first player in the lineup who fills this slot and hasn't been used yet
910
+ match = filled_lineup[(filled_lineup['Slot'] == slot) & (~filled_lineup.index.isin(used_indices))]
911
+ if not match.empty:
912
+ row = match.iloc[0]
913
+ used_indices.add(match.index[0])
914
+ display_rows.append({
915
+ 'Slot': slot,
916
+ 'Player': row['Player'],
917
+ 'Position': row['Position'],
918
+ 'Team': row['Team'],
919
+ 'Salary': row['Salary'],
920
+ 'Median': row['Median'],
921
+ 'Own%': row['Own%']
922
+ })
923
+ else:
924
+ # Blank row for unfilled slot
925
+ display_rows.append({
926
+ 'Slot': slot,
927
+ 'Player': '',
928
+ 'Position': '',
929
+ 'Team': '',
930
+ 'Salary': '',
931
+ 'Median': '',
932
+ 'Own%': ''
933
+ })
934
+
935
+ lineup_display_df = pd.DataFrame(display_rows, columns=display_columns)
936
+
937
  st.dataframe(
938
+ lineup_display_df,
939
  use_container_width=True,
940
+ height=445,
941
  hide_index=True
942
  )
943
 
944
  # --- SUMMARY ROW ---
945
+ if not filled_lineup.empty:
946
+ total_salary = filled_lineup['Salary'].sum()
947
+ total_median = filled_lineup['Median'].sum()
948
+ total_own = filled_lineup['Own%'].sum()
949
+ most_common_team = filled_lineup['Team'].mode()[0] if not filled_lineup['Team'].mode().empty else ""
 
950
 
951
  summary_row = pd.DataFrame({
 
952
  'Slot': [''],
953
+ 'Player': ['TOTAL'],
954
  'Position': [''],
955
  'Team': [most_common_team],
956
  'Salary': [total_salary],
957
  'Median': [total_median],
958
  'Own%': [total_own]
959
  })
960
+ summary_row = summary_row[display_columns]
961
 
962
  st.dataframe(
963
  summary_row,
964
  use_container_width=True,
965
+ height=45,
966
  hide_index=True
967
  )
968