-
Notifications
You must be signed in to change notification settings - Fork 0
/
SumoUpload.py
34 lines (24 loc) · 992 Bytes
/
SumoUpload.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
import xml.etree.ElementTree as ET
from Vehicle import Vehicle
def sumo_upload(file):
outputFile = open(file, 'r')
tree = ET.parse(outputFile)
root = tree.getroot()
TIME_STEPS = {}
for timeStep in root:
time = float(timeStep.attrib['time'])
VEHICLES = {}
if len(timeStep.findall('vehicle')) == 0:
break
for vehicle in timeStep.findall('vehicle'):
id = vehicle.attrib['id']
new_vehicle = Vehicle(id,
vehicle.attrib['x'],
vehicle.attrib['y'],
vehicle.attrib['speed'],
vehicle.attrib['lane'].partition('#')[0], # delete '#' and everything after
in_accident=False,
angle=vehicle.attrib['angle'])
VEHICLES[id] = new_vehicle
TIME_STEPS[time] = VEHICLES
return TIME_STEPS