James McCool commited on
Commit
7e6e154
·
1 Parent(s): 420ea34

Add ROI coloring function and update dataframe display in app.py

Browse files

- Introduced a new function, color_roi, to apply conditional formatting to ROI values based on their performance (green for >100%, red for <100%, yellow for =100%).
- Updated the dataframe display in the Contest Analysis tab to utilize the new color_roi function for enhanced visualization of ROI metrics.

Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -117,6 +117,17 @@ def get_payout_for_position(finish_pos, payout_df):
117
  else:
118
  return 0 # Default value if no match found
119
 
 
 
 
 
 
 
 
 
 
 
 
120
  db = init_conn()
121
 
122
  ## import global functions for usages
@@ -941,8 +952,9 @@ if selected_tab == 'Contest Analysis':
941
  end_ROI_idx = min((st.session_state.ROI_page) * rows_per_page, total_rows)
942
 
943
  st.dataframe(st.session_state['ROI_frame'].iloc[start_ROI_idx:end_ROI_idx].style.
944
- background_gradient(cmap='RdYlGn', subset=['ROI', 'Total Fees', 'Total Payout'], axis=0).
945
- background_gradient(cmap='RdYlGn', subset=['EntryCount', 'Total Fees'], axis=0).
 
946
  format(roi_format, precision=2), hide_index=True)
947
  st.download_button(label="Download ROI Info", data=st.session_state['ROI_frame'].to_csv(index=False), file_name="ROI_info.csv", mime="text/csv", key='ROI_exp_comp_download')
948
  else:
 
117
  else:
118
  return 0 # Default value if no match found
119
 
120
+ def color_roi(val):
121
+ """Color ROI values: green if > 100%, red if < 100%"""
122
+ if pd.isna(val):
123
+ return ''
124
+ if val > 1.0: # Greater than 100%
125
+ return 'background-color: lightgreen'
126
+ elif val < 1.0: # Less than 100%
127
+ return 'background-color: lightcoral'
128
+ else: # Exactly 100%
129
+ return 'background-color: lightyellow'
130
+
131
  db = init_conn()
132
 
133
  ## import global functions for usages
 
952
  end_ROI_idx = min((st.session_state.ROI_page) * rows_per_page, total_rows)
953
 
954
  st.dataframe(st.session_state['ROI_frame'].iloc[start_ROI_idx:end_ROI_idx].style.
955
+ applymap(color_roi, subset=['ROI']).
956
+ background_gradient(cmap='RdYlGn', subset=['Total Fees', 'Total Payout'], axis=0).
957
+ background_gradient(cmap='RdYlGn', subset=['EntryCount'], axis=0).
958
  format(roi_format, precision=2), hide_index=True)
959
  st.download_button(label="Download ROI Info", data=st.session_state['ROI_frame'].to_csv(index=False), file_name="ROI_info.csv", mime="text/csv", key='ROI_exp_comp_download')
960
  else: