-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalyze.py
More file actions
executable file
·49 lines (39 loc) · 1.68 KB
/
Copy pathanalyze.py
File metadata and controls
executable file
·49 lines (39 loc) · 1.68 KB
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
#!/usr/bin/python
# analyze the data coming from netlogo
# update the traffic and speed on networkx
# update the attributes of cars
def analyze(data, cars, network):
from ast import literal_eval
from car import update_car
from network import update_network
#create a dictionary of the cars on links to
#update the networkx later with it
network_usage_dict = dict()
# go through the data coming from netlogo
for item in data:
id, xcor, ycor, stopped, link_on,\
speed, direction, on_route_time, dist_travelled,\
drop_first_dir, travel_time,\
iteration = item.split("_")
# check if the car is entered the core network (red intersections)
try:
past_int, next_int = literal_eval(link_on)
except:
past_int, next_int = None, None
# update the car attributes
cars = update_car(cars, id, xcor, ycor, stopped, past_int, next_int, speed, direction,\
on_route_time, dist_travelled, drop_first_dir,\
travel_time, iteration)
# if the car is not the core network, networkx is not being updated
if not past_int:
continue
# add to the network usage dictioknary as we stream through
# the data coming from netlogo
if not link_on in network_usage_dict:
network_usage_dict[link_on] = []
car = [c for c in cars if c.id == int(id)][0]
network_usage_dict[link_on].append(car)
# now update network (link speed and traffic)
# based on network_usage_dict
network = update_network(network, network_usage_dict)
return cars, network