James McCool commited on
Commit
71c647d
·
1 Parent(s): 9681ab8

Enhance data upload functionality in app.py with new portfolio upload section

Browse files

- Refactored the layout in the "Data Load" tab to include three columns for data selection, contest upload, and portfolio upload.
- Added functionality for users to upload a portfolio of lineups, including data processing and validation for CSV and Excel files. This improves user experience by allowing direct comparison of portfolio performance against contest data.

Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -114,9 +114,9 @@ dupe_format = {'uniques%': '{:.2%}', 'under_5%': '{:.2%}', 'under_10%': '{:.2%}'
114
 
115
  tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
116
  with tab1:
117
- col1, col2 = st.columns(2)
118
 
119
- with col1:
120
  if st.button('Clear data', key='reset1'):
121
  st.session_state.clear()
122
  sport_options, date_options = st.columns(2)
@@ -153,7 +153,7 @@ with tab1:
153
  st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select, date_select2)
154
  else:
155
  pass
156
- with col2:
157
  st.info(f"If you are manually loading and do not have the results CSV for the contest you selected, you can find it here: https://www.draftkings.com/contest/gamecenter/{contest_id_map[contest_name_var]}#/, or you can initiate a download with this link: https://www.draftkings.com/contest/exportfullstandingscsv/{contest_id_map[contest_name_var]}")
158
  if parse_type == 'Manual':
159
  if 'Contest_file_helper' in st.session_state:
@@ -169,6 +169,19 @@ with tab1:
169
  st.warning('Please upload a Contest CSV')
170
  else:
171
  pass
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  if 'Contest_file' in st.session_state:
174
  st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], type_var, st.session_state['player_info'], sport_select)
 
114
 
115
  tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
116
  with tab1:
117
+ data_select, contest_upload, portfolio_upload = st.columns(3)
118
 
119
+ with data_select:
120
  if st.button('Clear data', key='reset1'):
121
  st.session_state.clear()
122
  sport_options, date_options = st.columns(2)
 
153
  st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select, date_select2)
154
  else:
155
  pass
156
+ with contest_upload:
157
  st.info(f"If you are manually loading and do not have the results CSV for the contest you selected, you can find it here: https://www.draftkings.com/contest/gamecenter/{contest_id_map[contest_name_var]}#/, or you can initiate a download with this link: https://www.draftkings.com/contest/exportfullstandingscsv/{contest_id_map[contest_name_var]}")
158
  if parse_type == 'Manual':
159
  if 'Contest_file_helper' in st.session_state:
 
169
  st.warning('Please upload a Contest CSV')
170
  else:
171
  pass
172
+
173
+ with portfolio_upload:
174
+ st.info("If you have a portfolio of lineups, you can upload them here to see how they perform against the field")
175
+ if st.button('Load Portfolio Data', key='load_portfolio_data'):
176
+ st.session_state['portfolio_file'] = st.file_uploader("Upload Portfolio File (CSV or Excel)", type=['csv', 'xlsx', 'xls'])
177
+ if st.session_state['portfolio_file'] is not None:
178
+ st.session_state['portfolio_df'] = pd.read_csv(st.session_state['portfolio_file'])
179
+ st.session_state['portfolio_df'] = st.session_state['portfolio_df'].columns = ['P1', 'P2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']
180
+ st.session_state['portfolio_df']['BaseName'] = 'Backtesting_upload'
181
+ st.session_state['portfolio_df']['EntryCount'] = len(st.session_state['portfolio_df'])
182
+ st.session_state['portfolio_df'] = st.session_state['portfolio_df'][['BaseName', 'EntryCount', 'P1', 'P2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
183
+ else:
184
+ pass
185
 
186
  if 'Contest_file' in st.session_state:
187
  st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['entry_list'], check_lineups = load_contest_file(st.session_state['Contest_file'], type_var, st.session_state['player_info'], sport_select)