-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment_loader.py
More file actions
41 lines (31 loc) · 852 Bytes
/
segment_loader.py
File metadata and controls
41 lines (31 loc) · 852 Bytes
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
from openpyxl import load_workbook
def load_segments(in_file: str) -> list:
"""
Parses an Excel file for CSIL segment definitions and returns a list of dicts.
"""
wb = load_workbook(filename=in_file, read_only=True,)
ws = wb.active
segments = []
for row in ws.rows:
if row[0].value == "SID":
# skip the first row of headers
continue
attrs = [
"SID",
"YEAR",
"DISTRICT",
"COUNTY",
"MUNI",
"ROUTE",
"MP_START",
"MP_END",
"TOTAL_ACCIDENTS",
"CONTROL_TYPE",
"CSIS",
"SEVERITY_INDEX",
]
d = {}
for attr in attrs:
d[attr] = row[attrs.index(attr)].value
segments.append(d)
return segments