James McCool
commited on
Commit
·
e13ecee
1
Parent(s):
28d3e56
Refactor contest date handling in app.py and grab_contest_data.py for improved consistency
Browse files- Removed the contest_date_map from the grab_contest_names function, simplifying the return values and enhancing data handling.
- Updated the date selection logic in app.py to directly utilize the 'Date' column from curr_info, ensuring a consistent format for date representation.
- Adjusted the grab_contest_data function to accept the formatted date directly, streamlining the data retrieval process.
- These changes contribute to ongoing efforts to enhance data integrity and improve user experience within the application.
- app.py +6 -6
- global_func/grab_contest_data.py +1 -2
app.py
CHANGED
@@ -26,9 +26,8 @@ def grab_contest_names(db, sport):
|
|
26 |
curr_info['Date'] = curr_info['Date'].dt.strftime('%Y-%m-%d')
|
27 |
contest_names = curr_info['Contest Name']
|
28 |
contest_id_map = dict(zip(curr_info['Contest Name'], curr_info['Contest ID']))
|
29 |
-
contest_date_map = dict(zip(curr_info['Contest Name'], curr_info['Date'].astype(str).replace('-', '')))
|
30 |
|
31 |
-
return contest_names, contest_id_map,
|
32 |
|
33 |
db = init_conn()
|
34 |
|
@@ -59,14 +58,15 @@ with tab1:
|
|
59 |
parse_type = st.selectbox("Manual upload or DB search?", ['DB Search', 'Manual'], key='parse_type')
|
60 |
with col2:
|
61 |
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'], key='sport_select')
|
62 |
-
contest_names, contest_id_map,
|
63 |
|
64 |
with col3:
|
65 |
-
date_select = st.selectbox("Select Date",
|
|
|
66 |
name_parse = curr_info[curr_info['Date'] == date_select]['Contest Name']
|
67 |
with col4:
|
68 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'], key='type_var')
|
69 |
-
st.write(
|
70 |
col1, col2 = st.columns(2)
|
71 |
|
72 |
with col1:
|
@@ -76,7 +76,7 @@ with tab1:
|
|
76 |
contest_name_var = st.selectbox("Select Contest to load", name_parse)
|
77 |
if 'Contest_file' not in st.session_state:
|
78 |
if st.button('Load Contest Data', key='load_contest_data'):
|
79 |
-
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map,
|
80 |
else:
|
81 |
pass
|
82 |
elif parse_type == 'Manual':
|
|
|
26 |
curr_info['Date'] = curr_info['Date'].dt.strftime('%Y-%m-%d')
|
27 |
contest_names = curr_info['Contest Name']
|
28 |
contest_id_map = dict(zip(curr_info['Contest Name'], curr_info['Contest ID']))
|
|
|
29 |
|
30 |
+
return contest_names, contest_id_map, curr_info
|
31 |
|
32 |
db = init_conn()
|
33 |
|
|
|
58 |
parse_type = st.selectbox("Manual upload or DB search?", ['DB Search', 'Manual'], key='parse_type')
|
59 |
with col2:
|
60 |
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'], key='sport_select')
|
61 |
+
contest_names, contest_id_map, curr_info = grab_contest_names(db, sport_select)
|
62 |
|
63 |
with col3:
|
64 |
+
date_select = st.selectbox("Select Date", curr_info['Date'].unique(), key='date_select')
|
65 |
+
date_select = date_select.replace('-', '')
|
66 |
name_parse = curr_info[curr_info['Date'] == date_select]['Contest Name']
|
67 |
with col4:
|
68 |
type_var = st.selectbox("Select Game Type", ['Classic', 'Showdown'], key='type_var')
|
69 |
+
st.write(date_select)
|
70 |
col1, col2 = st.columns(2)
|
71 |
|
72 |
with col1:
|
|
|
76 |
contest_name_var = st.selectbox("Select Contest to load", name_parse)
|
77 |
if 'Contest_file' not in st.session_state:
|
78 |
if st.button('Load Contest Data', key='load_contest_data'):
|
79 |
+
st.session_state['Contest_file'] = grab_contest_data(sport_select, contest_name_var, contest_id_map, date_select)
|
80 |
else:
|
81 |
pass
|
82 |
elif parse_type == 'Manual':
|
global_func/grab_contest_data.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import pandas as pd
|
2 |
import requests
|
3 |
|
4 |
-
def grab_contest_data(sport, contest_name, contest_id_map,
|
5 |
|
6 |
-
contest_date = contest_date_map[contest_name]
|
7 |
contest_id = contest_id_map[contest_name]
|
8 |
|
9 |
raw_url = f'https://dh5nxc6yx3kwy.cloudfront.net/contests/{sport.lower()}/{contest_date}/{contest_id}/'
|
|
|
1 |
import pandas as pd
|
2 |
import requests
|
3 |
|
4 |
+
def grab_contest_data(sport, contest_name, contest_id_map, contest_date):
|
5 |
|
|
|
6 |
contest_id = contest_id_map[contest_name]
|
7 |
|
8 |
raw_url = f'https://dh5nxc6yx3kwy.cloudfront.net/contests/{sport.lower()}/{contest_date}/{contest_id}/'
|