-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelf_utils.py
155 lines (132 loc) · 4 KB
/
elf_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from glob import glob
import os
def parse_names(name: str):
name = name.replace('ß', 'ss')
name = name.replace('ó', 'ss')
name = name.replace('ó', 'o')
name = name.replace('á', 'a')
name = name.replace('é', 'e')
name = name.replace('Groón', 'Grosse')
name = name.replace('Gródecki', 'Grodecki')
name = name.replace('Adrián', 'Adrian')
name = name.replace('Jiménez', 'Jimenez')
name = name.replace('UÄ°nan', 'Ugur')
name = name.replace('İ', 'I')
name = name.replace('Berçin', 'Bercin')
name = name.replace('Fernández', 'Fernandez')
# name = name.replace('Gündoħkesen', 'Agackesen')
name = name.replace('Groðnan', 'Grosse')
# name = name.replace('ó', 'o')
# name = name.replace('ó', 'o')
return name
def parse_position_names(position: str) -> str:
match position:
case "Quarterback":
return "QB"
case "Running Back":
return "RB"
case "Halfback":
return "HB"
case "Fullback":
return "FB"
case "Wide Receiver":
return "WR"
case "Tight End":
return "TE"
case "Offensive Tackle":
return "OT"
case "Offensive Guard":
return "OG"
case "Center":
return "C"
case "Defensive Line":
return "DL"
case "Defensive End":
return "DE"
case "Defensive Tackle":
return "DT"
case "Linebacker":
return "LB"
case "Outside Linebacker":
return "OLB"
case "Inside Linebacker":
return "ILB"
case "Middle Linebacker":
return "MLB"
case "Defensive Back":
return "DB"
case "Cornerback":
return "CB"
case "Safety":
return "SAF"
case "Free Safety":
return "FS"
case "Strong Safety":
return "SS"
case "Kicker":
return "K"
case "Punter":
return "P"
case "Long Snapper":
return "LS"
case "PR":
return "PR"
case "KR":
return "KR"
case "OTHERS":
return "ATH"
case None:
return "ATH"
case default:
raise ValueError(f'Unhandled player position:\n\t{position}')
def reformat_folder_string(folder: str):
"""
Reformats a string that represents a directory,
into a string Python recognizes as a directory.
Args:
folder (str):
Required parameter. Indicates the string you want
to represent a directory, or a directory path.
Returns:
reform_folder (str):
String intended to represent a directory,
or a directory path.
"""
reform_folder = folder.replace("\\", "/")
# print(f'Working Directory: \n\t{reform_folder}')
return reform_folder
def get_json_in_folder(folder_path="") -> list:
if len(folder_path) > 0:
json_dir = folder_path
del folder_path
else:
json_dir = "./raw_game_data/json/"
del folder_path
json_dir = os.path.abspath(json_dir)
json_dir = reformat_folder_string(json_dir)
print(json_dir)
json_files = []
json_file_list = glob(f"{json_dir}/*.json")
for j in json_file_list:
json_file = reformat_folder_string(j)
json_files.append(json_file)
del json_file
return json_files
def get_csv_in_folder(folder_path: str) -> list:
"""
"""
if len(folder_path) > 0:
pass
else:
raise ValueError(
'Cannot run `get_csv_in_folder()` without an inputted directory.')
csv_dir = os.path.abspath(folder_path)
csv_dir = reformat_folder_string(csv_dir)
print(csv_dir)
csv_files = []
csv_file_list = glob(f"{csv_dir}/*.csv")
for j in csv_file_list:
csv_file = reformat_folder_string(j)
csv_files.append(csv_file)
del csv_file
return csv_files