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

Enhance contest data handling in app.py and related functions for improved functionality

Browse files

- Updated the load_contest_file function to include 'Salary' and 'Team' columns, enhancing the data structure for contest entries.
- Modified the grab_contest_data function to capture additional player information, including salary and current team, improving data completeness.
- Adjusted app.py to utilize the new data structures, ensuring that session state variables are populated with the latest contest data.
- 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['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:
@@ -96,8 +96,12 @@ with tab1:
96
  if 'Contest_file' in st.session_state:
97
  st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_df']['Player'], st.session_state['ownership_df']['Own']))
98
  st.session_state['actual_dict'] = dict(zip(st.session_state['actual_df']['Player'], st.session_state['actual_df']['FPTS']))
 
 
99
  st.write(st.session_state['ownership_dict'])
100
  st.write(st.session_state['actual_dict'])
 
 
101
 
102
 
103
  with tab2:
 
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:
 
96
  if 'Contest_file' in st.session_state:
97
  st.session_state['ownership_dict'] = dict(zip(st.session_state['ownership_df']['Player'], st.session_state['ownership_df']['Own']))
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:
global_func/grab_contest_data.py CHANGED
@@ -37,6 +37,8 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
37
  player_data.append({
38
  'fullName': player_info['fullName'],
39
  'playerId': player_info['playerId'],
 
 
40
  'rosterPosition': player_info['rosterPosition'],
41
  'ownership': player_info['ownership'],
42
  'actualPoints': player_info['actualPoints']
@@ -44,7 +46,7 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
44
 
45
  players_df = pd.DataFrame(player_data)
46
  players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
47
- players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS'})
48
  pid_map = dict(zip(players_df['playerId'].astype(str), players_df['Player']))
49
 
50
  for lineup_hash, lineup_info in lineups_json['lineups'].items():
 
37
  player_data.append({
38
  'fullName': player_info['fullName'],
39
  'playerId': player_info['playerId'],
40
+ 'salary': player_info['salary'],
41
+ 'currentTeam': player_info['currentTeam'],
42
  'rosterPosition': player_info['rosterPosition'],
43
  'ownership': player_info['ownership'],
44
  'actualPoints': player_info['actualPoints']
 
46
 
47
  players_df = pd.DataFrame(player_data)
48
  players_df = players_df.sort_values(by='ownership', ascending=False).reset_index(drop=True)
49
+ players_df = players_df.rename(columns={'fullName': 'Player', 'rosterPosition': 'Roster Position', 'ownership': '%Drafted', 'actualPoints': 'FPTS', 'salary': 'Salary', 'currentTeam': 'Team'})
50
  pid_map = dict(zip(players_df['playerId'].astype(str), players_df['Player']))
51
 
52
  for lineup_hash, lineup_info in lineups_json['lineups'].items():
global_func/load_contest_file.py CHANGED
@@ -17,7 +17,7 @@ def load_contest_file(upload, sport):
17
  except:
18
  raw_df = upload
19
 
20
- df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS']]
21
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
22
 
23
  # Split EntryName into base name and entry count
@@ -52,12 +52,14 @@ def load_contest_file(upload, sport):
52
  df['Own'] = df['Own'].astype(float)
53
  ownership_df = df[['Player', 'Own']]
54
  fpts_df = df[['Player', 'FPTS']]
55
- cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
 
 
56
  cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
57
  entry_list = list(set(df['BaseName']))
58
  entry_list.sort()
59
 
60
- return cleaned_df, ownership_df, fpts_df, entry_list
61
  except Exception as e:
62
  st.error(f'Error loading file: {str(e)}')
63
  return None
 
17
  except:
18
  raw_df = upload
19
 
20
+ df = raw_df[['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Roster Position', '%Drafted', 'FPTS', 'Salary', 'Team']]
21
  df = df.rename(columns={'Roster Position': 'Pos', '%Drafted': 'Own'})
22
 
23
  # Split EntryName into base name and entry count
 
52
  df['Own'] = df['Own'].astype(float)
53
  ownership_df = df[['Player', 'Own']]
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