James McCool
commited on
Commit
·
9d66c9c
1
Parent(s):
6af53eb
Refactor file type checks in load_file.py and load_ss_file.py: streamline file extension validation using endswith method for improved readability. Update app.py to handle salary conversion more robustly by removing unnecessary exception handling.
Browse files- app.py +3 -3
- global_func/load_dk_fd_file.py +2 -2
- global_func/load_file.py +9 -3
- global_func/load_ss_file.py +8 -2
app.py
CHANGED
@@ -191,12 +191,12 @@ with tab1:
|
|
191 |
try:
|
192 |
st.session_state['projections_df']['ownership'] = st.session_state['projections_df']['ownership'].str.replace('%', '').astype(float)
|
193 |
except:
|
194 |
-
|
195 |
|
196 |
try:
|
197 |
-
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace([',', '$', ' '], '', regex=True).astype(
|
198 |
except:
|
199 |
-
|
200 |
|
201 |
try:
|
202 |
name_id_map = dict(zip(
|
|
|
191 |
try:
|
192 |
st.session_state['projections_df']['ownership'] = st.session_state['projections_df']['ownership'].str.replace('%', '').astype(float)
|
193 |
except:
|
194 |
+
pass
|
195 |
|
196 |
try:
|
197 |
+
st.session_state['projections_df']['salary'] = (st.session_state['projections_df']['salary'].astype(str).str.replace([',', '$', ' '], '', regex=True).astype(int))
|
198 |
except:
|
199 |
+
pass
|
200 |
|
201 |
try:
|
202 |
name_id_map = dict(zip(
|
global_func/load_dk_fd_file.py
CHANGED
@@ -19,9 +19,9 @@ def load_dk_fd_file(lineups, csv_file):
|
|
19 |
print(clean_name)
|
20 |
print(lineups.name)
|
21 |
|
22 |
-
if '.csv'
|
23 |
lineups_df = pd.read_csv(lineups)
|
24 |
-
elif
|
25 |
lineups_df = pd.read_excel(lineups)
|
26 |
else:
|
27 |
st.error('Please upload either a CSV or Excel file for lineups')
|
|
|
19 |
print(clean_name)
|
20 |
print(lineups.name)
|
21 |
|
22 |
+
if clean_name.endswith('.csv'):
|
23 |
lineups_df = pd.read_csv(lineups)
|
24 |
+
elif clean_name.endswith(('.xls', '.xlsx')):
|
25 |
lineups_df = pd.read_excel(lineups)
|
26 |
else:
|
27 |
st.error('Please upload either a CSV or Excel file for lineups')
|
global_func/load_file.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import pandas as pd
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
|
|
6 |
|
7 |
## import global functions
|
8 |
from global_func.clean_player_name import clean_player_name
|
@@ -10,12 +11,17 @@ from global_func.clean_player_name import clean_player_name
|
|
10 |
def load_file(upload):
|
11 |
if upload is not None:
|
12 |
try:
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
df = pd.read_csv(upload)
|
15 |
-
elif
|
16 |
df = pd.read_excel(upload)
|
17 |
else:
|
18 |
-
st.error('Please upload either a CSV or Excel file
|
19 |
return None, None
|
20 |
|
21 |
export_df = df.copy()
|
|
|
3 |
import pandas as pd
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
6 |
+
import re
|
7 |
|
8 |
## import global functions
|
9 |
from global_func.clean_player_name import clean_player_name
|
|
|
11 |
def load_file(upload):
|
12 |
if upload is not None:
|
13 |
try:
|
14 |
+
clean_name = re.sub(r' \(\d+\)', '', upload.name)
|
15 |
+
|
16 |
+
print(clean_name)
|
17 |
+
print(upload.name)
|
18 |
+
|
19 |
+
if clean_name.endswith('.csv'):
|
20 |
df = pd.read_csv(upload)
|
21 |
+
elif clean_name.endswith(('.xls', '.xlsx')):
|
22 |
df = pd.read_excel(upload)
|
23 |
else:
|
24 |
+
st.error('Please upload either a CSV or Excel file')
|
25 |
return None, None
|
26 |
|
27 |
export_df = df.copy()
|
global_func/load_ss_file.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import pandas as pd
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
|
|
6 |
|
7 |
def load_ss_file(lineups, csv_file):
|
8 |
df = csv_file.copy()
|
@@ -13,9 +14,14 @@ def load_ss_file(lineups, csv_file):
|
|
13 |
|
14 |
# Now load and process the lineups file
|
15 |
try:
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
lineups_df = pd.read_csv(lineups)
|
18 |
-
elif
|
19 |
lineups_df = pd.read_excel(lineups)
|
20 |
else:
|
21 |
st.error('Please upload either a CSV or Excel file for lineups')
|
|
|
3 |
import pandas as pd
|
4 |
import time
|
5 |
from fuzzywuzzy import process
|
6 |
+
import re
|
7 |
|
8 |
def load_ss_file(lineups, csv_file):
|
9 |
df = csv_file.copy()
|
|
|
14 |
|
15 |
# Now load and process the lineups file
|
16 |
try:
|
17 |
+
clean_name = re.sub(r' \(\d+\)', '', lineups.name)
|
18 |
+
|
19 |
+
print(clean_name)
|
20 |
+
print(lineups.name)
|
21 |
+
|
22 |
+
if clean_name.endswith('.csv'):
|
23 |
lineups_df = pd.read_csv(lineups)
|
24 |
+
elif clean_name.endswith(('.xls', '.xlsx')):
|
25 |
lineups_df = pd.read_excel(lineups)
|
26 |
else:
|
27 |
st.error('Please upload either a CSV or Excel file for lineups')
|