James McCool commited on
Commit
76ff10d
·
1 Parent(s): 220e04f

Refactor data export functionality in app.py by replacing hardcoded column indices with named column mappings for DraftKings and FanDuel, improving code readability and maintainability.

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -443,12 +443,14 @@ with tab3:
443
 
444
  if st.button("Prepare data export", key='data_export'):
445
  data_export = st.session_state.working_seed.copy()
446
- # if site_var == 'Draftkings':
447
- # for col_idx in range(6):
448
- # data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
449
- # elif site_var == 'Fanduel':
450
- # for col_idx in range(6):
451
- # data_export[:, col_idx] = np.array([id_dict.get(player, player) for player in data_export[:, col_idx]])
 
 
452
  st.download_button(
453
  label="Export optimals set",
454
  data=convert_df(data_export),
@@ -492,11 +494,13 @@ with tab3:
492
 
493
  export_file = st.session_state.data_export_display.copy()
494
  if site_var == 'Draftkings':
495
- for col_idx in range(10):
496
- export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(dk_id_map)
 
497
  elif site_var == 'Fanduel':
498
- for col_idx in range(9):
499
- export_file.iloc[:, col_idx] = export_file.iloc[:, col_idx].map(fd_id_map)
 
500
 
501
  with st.container():
502
  if st.button("Reset Optimals", key='reset3'):
 
443
 
444
  if st.button("Prepare data export", key='data_export'):
445
  data_export = st.session_state.working_seed.copy()
446
+ if site_var == 'Draftkings':
447
+ map_columns = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']
448
+ for col_idx in map_columns:
449
+ data_export[col_idx] = data_export[col_idx].map(dk_id_map)
450
+ elif site_var == 'Fanduel':
451
+ map_columns = ['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL']
452
+ for col_idx in map_columns:
453
+ data_export[col_idx] = data_export[col_idx].map(fd_id_map)
454
  st.download_button(
455
  label="Export optimals set",
456
  data=convert_df(data_export),
 
494
 
495
  export_file = st.session_state.data_export_display.copy()
496
  if site_var == 'Draftkings':
497
+ map_columns = ['SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']
498
+ for col_idx in map_columns:
499
+ export_file[col_idx] = export_file[col_idx].map(dk_id_map)
500
  elif site_var == 'Fanduel':
501
+ map_columns = ['P', 'C_1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3', 'UTIL']
502
+ for col_idx in map_columns:
503
+ export_file[col_idx] = export_file[col_idx].map(fd_id_map)
504
 
505
  with st.container():
506
  if st.button("Reset Optimals", key='reset3'):