James McCool commited on
Commit
910ce9f
·
1 Parent(s): 8e622a8

Enhance contest name retrieval in app.py to support multiple contest types

Browse files

- Updated the grab_contest_names function to accept a new parameter for contest type, allowing for dynamic selection of contest information based on 'Classic' or 'Showdown'.
- Improved date handling by correcting the reference to 'Contest Date' for accurate date formatting.
- Maintained existing functionality while enhancing the flexibility of contest data retrieval.

Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -16,12 +16,16 @@ def init_conn():
16
 
17
  return db
18
 
19
- def grab_contest_names(db, sport):
20
- collection = db[f'{sport}_contest_info']
 
 
 
 
21
  cursor = collection.find()
22
 
23
  curr_info = pd.DataFrame(list(cursor)).drop('_id', axis=1)
24
- curr_info['Date'] = pd.to_datetime(curr_info['Date'].sort_values(ascending = False))
25
  curr_info['Date'] = curr_info['Date'].dt.strftime('%Y-%m-%d')
26
  contest_names = curr_info['Contest Name']
27
  contest_id_map = dict(zip(curr_info['Contest Name'], curr_info['Contest ID']))
 
16
 
17
  return db
18
 
19
+ def grab_contest_names(db, sport, type):
20
+ if type == 'Classic':
21
+ db_type = 'reg'
22
+ elif type == 'Showdown':
23
+ db_type = 'sd'
24
+ collection = db[f'{sport}_{db_type}_contest_info']
25
  cursor = collection.find()
26
 
27
  curr_info = pd.DataFrame(list(cursor)).drop('_id', axis=1)
28
+ curr_info['Date'] = pd.to_datetime(curr_info['Contest Date'].sort_values(ascending = False))
29
  curr_info['Date'] = curr_info['Date'].dt.strftime('%Y-%m-%d')
30
  contest_names = curr_info['Contest Name']
31
  contest_id_map = dict(zip(curr_info['Contest Name'], curr_info['Contest ID']))