James McCool
commited on
Commit
·
e560f1d
1
Parent(s):
76d511e
Add sport selection feature and update contest file loading logic
Browse files- Introduced a sport selection dropdown in app.py to allow users to specify the sport for contest data.
- Updated the load_contest_file function to accept the selected sport as a parameter, enabling sport-specific data handling.
- Enhanced the data processing logic to rename player columns based on the selected sport, improving clarity and usability.
- app.py +2 -1
- global_func/load_contest_file.py +5 -1
app.py
CHANGED
@@ -21,6 +21,7 @@ tab1, tab2 = st.tabs(["Data Load", "Contest Analysis"])
|
|
21 |
with tab1:
|
22 |
if st.button('Clear data', key='reset1'):
|
23 |
st.session_state.clear()
|
|
|
24 |
# Add file uploaders to your app
|
25 |
col1, col2, col3 = st.columns(3)
|
26 |
|
@@ -32,7 +33,7 @@ with tab1:
|
|
32 |
del st.session_state['Contest']
|
33 |
|
34 |
if Contest_file:
|
35 |
-
st.session_state['Contest'], st.session_state['ownership_dict'], st.session_state['entry_list'] = load_contest_file(Contest_file)
|
36 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
37 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
38 |
if st.session_state['Contest'] is not None:
|
|
|
21 |
with tab1:
|
22 |
if st.button('Clear data', key='reset1'):
|
23 |
st.session_state.clear()
|
24 |
+
sport_select = st.selectbox("Select Sport", ['MLB', 'NBA', 'NFL'])
|
25 |
# Add file uploaders to your app
|
26 |
col1, col2, col3 = st.columns(3)
|
27 |
|
|
|
33 |
del st.session_state['Contest']
|
34 |
|
35 |
if Contest_file:
|
36 |
+
st.session_state['Contest'], st.session_state['ownership_dict'], st.session_state['entry_list'] = load_contest_file(Contest_file, sport_select)
|
37 |
st.session_state['Contest'] = st.session_state['Contest'].dropna(how='all')
|
38 |
st.session_state['Contest'] = st.session_state['Contest'].reset_index(drop=True)
|
39 |
if st.session_state['Contest'] is not None:
|
global_func/load_contest_file.py
CHANGED
@@ -7,7 +7,7 @@ from fuzzywuzzy import process
|
|
7 |
## import global functions
|
8 |
from global_func.clean_player_name import clean_player_name
|
9 |
|
10 |
-
def load_contest_file(upload):
|
11 |
pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF']
|
12 |
if upload is not None:
|
13 |
try:
|
@@ -45,8 +45,12 @@ def load_contest_file(upload):
|
|
45 |
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
46 |
# Remove position indicators from the end of each entry
|
47 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
|
|
|
|
|
|
48 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
49 |
cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
|
|
|
50 |
entry_list = list(set(df['BaseName']))
|
51 |
entry_list.sort()
|
52 |
|
|
|
7 |
## import global functions
|
8 |
from global_func.clean_player_name import clean_player_name
|
9 |
|
10 |
+
def load_contest_file(upload, sport):
|
11 |
pos_values = ['P', 'C', '1B', '2B', '3B', 'SS', 'OF']
|
12 |
if upload is not None:
|
13 |
try:
|
|
|
45 |
df[i] = df['Lineup'].str.split(',').str[i].str.strip()
|
46 |
# Remove position indicators from the end of each entry
|
47 |
df[i] = df[i].str.replace(r'\s+(' + '|'.join(pos_values) + r')$', '', regex=True)
|
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 |
ownership_dict = dict(zip(df['Player'], df['Own']))
|
52 |
cleaned_df = df.drop(columns=['EntryId', 'EntryName', 'TimeRemaining', 'Points', 'Lineup', 'Player', 'Pos', 'Own', 'FPTS'])
|
53 |
+
cleaned_df = cleaned_df[['BaseName', 'EntryCount', 'SP1', 'SP2', 'C', '1B', '2B', '3B', 'SS', 'OF1', 'OF2', 'OF3']]
|
54 |
entry_list = list(set(df['BaseName']))
|
55 |
entry_list.sort()
|
56 |
|