James McCool commited on
Commit
433ab29
·
1 Parent(s): a8cf688

Update contest data handling in app.py and related functions to include position data

Browse files

- Modified the load_contest_file function to return position data alongside existing contest data, enhancing the information available for each player.
- Updated app.py to utilize the new position data, ensuring that session state variables are populated with the latest player information.
- Adjusted the grab_contest_data function to improve the handling of lineup strings, ensuring accurate data representation.
- These changes contribute to ongoing efforts to improve data integrity and user experience within the application.

app.py CHANGED
@@ -86,7 +86,7 @@ with tab1:
86
  del st.session_state['Contest']
87
 
88
  if 'Contest_file' in st.session_state and 'Adj_Contest' not in st.session_state:
89
- st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['salary_df'], st.session_state['team_df'], st.session_state['entry_list'] = load_contest_file(st.session_state['Contest_file'], sport_select)
90
  st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
91
  st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
92
  if st.session_state['Contest'] is not None:
@@ -98,11 +98,12 @@ with tab1:
98
  st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
99
  st.session_state['salary_dict'] = dict(zip(st.session_state['salary_df']['Player'], st.session_state['salary_df']['Salary']))
100
  st.session_state['team_dict'] = dict(zip(st.session_state['team_df']['Player'], st.session_state['team_df']['Team']))
 
101
  st.write(st.session_state['ownership_dict'])
102
  st.write(st.session_state['actual_dict'])
103
  st.write(st.session_state['salary_dict'])
104
  st.write(st.session_state['team_dict'])
105
-
106
 
107
  with tab2:
108
  excluded_cols = ['BaseName', 'EntryCount']
 
86
  del st.session_state['Contest']
87
 
88
  if 'Contest_file' in st.session_state and 'Adj_Contest' not in st.session_state:
89
+ st.session_state['Contest'], st.session_state['ownership_df'], st.session_state['actual_df'], st.session_state['salary_df'], st.session_state['team_df'], st.session_state['pos_df'], st.session_state['entry_list'] = load_contest_file(st.session_state['Contest_file'], sport_select)
90
  st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
91
  st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
92
  if st.session_state['Contest'] is not None:
 
98
  st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
99
  st.session_state['salary_dict'] = dict(zip(st.session_state['salary_df']['Player'], st.session_state['salary_df']['Salary']))
100
  st.session_state['team_dict'] = dict(zip(st.session_state['team_df']['Player'], st.session_state['team_df']['Team']))
101
+ st.session_state['pos_dict'] = dict(zip(st.session_state['pos_df']['Player'], st.session_state['pos_df']['Pos']))
102
  st.write(st.session_state['ownership_dict'])
103
  st.write(st.session_state['actual_dict'])
104
  st.write(st.session_state['salary_dict'])
105
  st.write(st.session_state['team_dict'])
106
+ st.write(st.session_state['pos_dict'])
107
 
108
  with tab2:
109
  excluded_cols = ['BaseName', 'EntryCount']
global_func/grab_contest_data.py CHANGED
@@ -66,7 +66,7 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
66
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
67
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
68
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
69
- lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map, regex=True)
70
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
71
 
72
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)
 
66
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
67
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
68
  lineups_df['Lineup'] = lineups_df['Lineup'].apply(lambda x: format_lineup_string(x, position_inserts))
69
+ lineups_df['Lineup'] = lineups_df['Lineup'].replace(pid_map, regex=False)
70
  lineups_df = lineups_df[['Rank', 'EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup']]
71
 
72
  total_data = lineups_df.merge(players_df, how='left', left_index=True, right_index=True)
global_func/load_contest_file.py CHANGED
@@ -54,12 +54,13 @@ def load_contest_file(upload, sport):
54
  fpts_df = df[['Player', 'FPTS']]
55
  salary_df = df[['Player', 'Salary']]
56
  team_df = df[['Player', 'Team']]
 
57
  cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS', 'Salary', 'Team'])
58
  cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
59
  entry_list = list(set(df['BaseName']))
60
  entry_list.sort()
61
 
62
- return cleaned_df, ownership_df, fpts_df, salary_df, team_df, entry_list
63
  except Exception as e:
64
  st.error(f'Error loading file: {str(e)}')
65
  return None
 
54
  fpts_df = df[['Player', 'FPTS']]
55
  salary_df = df[['Player', 'Salary']]
56
  team_df = df[['Player', 'Team']]
57
+ pos_df = df[['Player', 'Pos']]
58
  cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS', 'Salary', 'Team'])
59
  cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
60
  entry_list = list(set(df['BaseName']))
61
  entry_list.sort()
62
 
63
+ return cleaned_df, ownership_df, fpts_df, salary_df, team_df, pos_df, entry_list
64
  except Exception as e:
65
  st.error(f'Error loading file: {str(e)}')
66
  return None