-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript.py
executable file
·64 lines (52 loc) · 2.05 KB
/
script.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
# collect the common function
# import script
# get traffic in one lane
def get_traffic_volume(traffic_file):
# only support "cross" and "synthetic"
if "cross" in traffic_file:
sta = traffic_file.find("equal_") + len("equal_")
end = traffic_file.find(".xml")
return int(traffic_file[sta:end])
elif "synthetic" in traffic_file:
traffic_file_list = traffic_file.split("-")
volume_list = []
for i in range(2, 6):
volume_list.append(int(traffic_file_list[i][2:]))
vol = min(max(volume_list[0:2]), max(volume_list[2:]))
return int(vol/100)*100
elif "flow" in traffic_file:
sta = traffic_file.find("flow_1_1_") + len("flow_1_1_")
end = traffic_file.find(".json")
return int(traffic_file[sta:end])
elif "real" in traffic_file:
sta = traffic_file.rfind("-") + 1
end = traffic_file.rfind(".json")
return int(traffic_file[sta:end])
elif "hangzhou" in traffic_file:
traffic = traffic_file.split(".json")[0]
vol = int(traffic.split("_")[-1])
return vol
## get total number of vehicles
## not very comprehensive
def get_total_traffic_volume(traffic_file):
# only support "cross" and "synthetic"
if "cross" in traffic_file:
sta = traffic_file.find("equal_") + len("equal_")
end = traffic_file.find(".xml")
return int(traffic_file[sta:end]) * 4
elif "synthetic" in traffic_file:
sta = traffic_file.rfind("-") + 1
end = traffic_file.rfind(".json")
return int(traffic_file[sta:end])
elif "flow" in traffic_file:
sta = traffic_file.find("flow_1_1_") + len("flow_1_1_")
end = traffic_file.find(".json")
return int(traffic_file[sta:end]) * 4
elif "real" in traffic_file:
sta = traffic_file.rfind("-") + 1
end = traffic_file.rfind(".json")
return int(traffic_file[sta:end])
elif "hangzhou" in traffic_file:
traffic = traffic_file.split(".json")[0]
vol = int(traffic.split("_")[-1])
return vol