James McCool commited on
Commit
e1f40de
·
1 Parent(s): cbe1c19

Enhance data processing in grab_contest_data and load_contest_file functions

Browse files

- Updated the 'EntryId' generation in grab_contest_data to ensure proper type conversion for both index and entry names, improving data integrity.
- Added error handling in load_contest_file for the 'Own' column to manage potential data format issues, enhancing robustness and user experience.

global_func/grab_contest_data.py CHANGED
@@ -60,7 +60,7 @@ def grab_contest_data(sport, contest_name, contest_id_map, contest_date_map):
60
  lineups_df = lineups_df.reset_index()
61
  lineups_df['index'] = lineups_df.index + 1
62
  lineups_df['TimeRemaining'] = str(0)
63
- lineups_df['EntryId'] = str(lineups_df['index']) + str(lineups_df['entryNameList'])
64
  lineups_df['lineupHash'] = ':' + lineups_df['lineupHash']
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
 
60
  lineups_df = lineups_df.reset_index()
61
  lineups_df['index'] = lineups_df.index + 1
62
  lineups_df['TimeRemaining'] = str(0)
63
+ lineups_df['EntryId'] = lineups_df['index'].astype(str) + lineups_df['entryNameList'].astype(str)
64
  lineups_df['lineupHash'] = ':' + lineups_df['lineupHash']
65
  lineups_df = lineups_df.rename(columns={'index': 'Rank', 'points': 'Points', 'entryNameList': 'EntryName', 'lineupHash': 'Lineup'})
66
  lineups_df['EntryName'] = lineups_df['EntryName'] + ' (1/1)'
global_func/load_contest_file.py CHANGED
@@ -48,7 +48,10 @@ def load_contest_file(upload, sport):
48
 
49
  if sport == 'MLB':
50
  df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
51
- df['Own'] = df['Own'].str.replace('%', '').astype(float)
 
 
 
52
  ownership_df = df[['Player', 'Own']]
53
  fpts_df = df[['Player', 'FPTS']]
54
  cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
 
48
 
49
  if sport == 'MLB':
50
  df = df.rename(columns={1: '1B', 2: '2B', 3: '3B', 4: 'C', 5: 'OF1', 6: 'OF2', 7: 'OF3', 8: 'SP1', 9: 'SP2', 10: 'SS'})
51
+ try:
52
+ df['Own'] = df['Own'].str.replace('%', '').astype(float)
53
+ except:
54
+ df['Own'] = df['Own'].astype(float)
55
  ownership_df = df[['Player', 'Own']]
56
  fpts_df = df[['Player', 'FPTS']]
57
  cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])