James McCool
commited on
Commit
·
21ba9dc
1
Parent(s):
bd643f8
Refactor lineup replacement logic in load_contest_file function
Browse files- Simplified the lineup replacement process by removing try-except blocks and directly implementing sport-specific replacements for MLB, MMA, and GOLF.
- Enhanced the clarity and maintainability of the code while ensuring consistent handling of player roles across different sports.
- Maintained existing functionality while improving the robustness of the contest file loading process.
global_func/load_contest_file.py
CHANGED
@@ -71,15 +71,12 @@ def load_contest_file(upload, helper = None, sport = None):
|
|
71 |
|
72 |
# Create the cleaned dataframe with just the essential columns
|
73 |
cleaned_df = df[['BaseName', 'Lineup']]
|
74 |
-
|
75 |
-
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace(
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' F ', 'F '], value=',', regex=True)
|
81 |
-
elif sport == 'GOLF':
|
82 |
-
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' G ', 'G '], value=',', regex=True)
|
83 |
print(sport)
|
84 |
print(cleaned_df.head(10))
|
85 |
check_lineups = cleaned_df.copy()
|
|
|
71 |
|
72 |
# Create the cleaned dataframe with just the essential columns
|
73 |
cleaned_df = df[['BaseName', 'Lineup']]
|
74 |
+
if sport == 'MLB':
|
75 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF '], value=',', regex=True)
|
76 |
+
elif sport == 'MMA':
|
77 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' F ', 'F '], value=',', regex=True)
|
78 |
+
elif sport == 'GOLF':
|
79 |
+
cleaned_df['Lineup'] = cleaned_df['Lineup'].replace([' P ', ' C ', '1B ', ' 2B ', ' 3B ', ' SS ', ' OF ', ' G ', 'G '], value=',', regex=True)
|
|
|
|
|
|
|
80 |
print(sport)
|
81 |
print(cleaned_df.head(10))
|
82 |
check_lineups = cleaned_df.copy()
|