James McCool commited on
Commit
dbc3f23
·
1 Parent(s): cb4a863

Refactor file type checks in loading functions: update conditions in load_dk_fd_file.py, load_file.py, and load_ss_file.py to use substring checks for file extensions, improving readability and maintainability. Remove debug print statements from load_dk_fd_file.py and app.py to clean up the code.

Browse files
app.py CHANGED
@@ -88,7 +88,6 @@ with tab1:
88
  st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
89
  elif upload_toggle == 'Draftkings/Fanduel (Names + IDs)':
90
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_dk_fd_file(portfolio_file, st.session_state['csv_file'])
91
- print(st.session_state['export_portfolio'])
92
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
93
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
94
  st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
 
88
  st.session_state['portfolio'] = st.session_state['portfolio'].reset_index(drop=True)
89
  elif upload_toggle == 'Draftkings/Fanduel (Names + IDs)':
90
  st.session_state['export_portfolio'], st.session_state['portfolio'] = load_dk_fd_file(portfolio_file, st.session_state['csv_file'])
 
91
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
92
  st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
93
  st.session_state['portfolio'] = st.session_state['portfolio'].dropna(how='all')
global_func/load_dk_fd_file.py CHANGED
@@ -10,13 +10,12 @@ def load_dk_fd_file(lineups, csv_file):
10
  name_dict = dict(zip(df['Name + ID'], df['Name']))
11
  except:
12
  name_dict = dict(zip(df['Id'], df['Nickname']))
13
- print(name_dict)
14
 
15
  # Now load and process the lineups file
16
  try:
17
- if lineups.name.endswith('.csv'):
18
  lineups_df = pd.read_csv(lineups)
19
- elif lineups.name.endswith(('.xls', '.xlsx')):
20
  lineups_df = pd.read_excel(lineups)
21
  else:
22
  st.error('Please upload either a CSV or Excel file for lineups')
@@ -30,9 +29,6 @@ def load_dk_fd_file(lineups, csv_file):
30
  pass
31
 
32
  export_df = lineups_df.copy()
33
-
34
- print(lineups_df)
35
- print(export_df)
36
 
37
  # Map the IDs to names
38
  for col in lineups_df.columns:
 
10
  name_dict = dict(zip(df['Name + ID'], df['Name']))
11
  except:
12
  name_dict = dict(zip(df['Id'], df['Nickname']))
 
13
 
14
  # Now load and process the lineups file
15
  try:
16
+ if '.csv' in lineups.name:
17
  lineups_df = pd.read_csv(lineups)
18
+ elif any(ext in lineups.name for ext in ['.xls', '.xlsx']):
19
  lineups_df = pd.read_excel(lineups)
20
  else:
21
  st.error('Please upload either a CSV or Excel file for lineups')
 
29
  pass
30
 
31
  export_df = lineups_df.copy()
 
 
 
32
 
33
  # Map the IDs to names
34
  for col in lineups_df.columns:
global_func/load_file.py CHANGED
@@ -10,13 +10,13 @@ from global_func.clean_player_name import clean_player_name
10
  def load_file(upload):
11
  if upload is not None:
12
  try:
13
- if upload.name.endswith('.csv'):
14
  df = pd.read_csv(upload)
15
- elif upload.name.endswith(('.xls', '.xlsx')):
16
  df = pd.read_excel(upload)
17
  else:
18
- st.error('Please upload either a CSV or Excel file')
19
- return None
20
 
21
  export_df = df.copy()
22
 
 
10
  def load_file(upload):
11
  if upload is not None:
12
  try:
13
+ if '.csv' in upload.name:
14
  df = pd.read_csv(upload)
15
+ elif any(ext in upload.name for ext in ['.xls', '.xlsx']):
16
  df = pd.read_excel(upload)
17
  else:
18
+ st.error('Please upload either a CSV or Excel file for lineups')
19
+ return None, None
20
 
21
  export_df = df.copy()
22
 
global_func/load_ss_file.py CHANGED
@@ -13,9 +13,9 @@ def load_ss_file(lineups, csv_file):
13
 
14
  # Now load and process the lineups file
15
  try:
16
- if lineups.name.endswith('.csv'):
17
  lineups_df = pd.read_csv(lineups)
18
- elif lineups.name.endswith(('.xls', '.xlsx')):
19
  lineups_df = pd.read_excel(lineups)
20
  else:
21
  st.error('Please upload either a CSV or Excel file for lineups')
 
13
 
14
  # Now load and process the lineups file
15
  try:
16
+ if '.csv' in lineups.name:
17
  lineups_df = pd.read_csv(lineups)
18
+ elif any(ext in lineups.name for ext in ['.xls', '.xlsx']):
19
  lineups_df = pd.read_excel(lineups)
20
  else:
21
  st.error('Please upload either a CSV or Excel file for lineups')