forked from dsadigh/driving-interactions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
executable file
·138 lines (129 loc) · 3.96 KB
/
gen.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
import pickle
import subprocess
from pylab import *
import csv
dt = 0.1
def ls(pattern):
output = subprocess.check_output("ls {}".format(pattern), shell=True).splitlines()
return output
def load(filename):
with open(filename) as f:
ret = pickle.load(f)
u, x = ret
uh, ur = u
xh, xr = x
t = arange(len(xh))*dt
return {'uh': asarray(uh), 'ur': asarray(ur), 'xh': asarray(xh), 'xr': asarray(xr), 't': t}
def isempty(data):
return all([len(y)==0 for y in data.values()])
csvs = [[], [], []]
condition = {
'world0': 'gray',
'world1': 'orange',
'world2': 'orange',
'world3': 'blue',
'world4': 'orange',
'world5': 'gray'
}
scenario = {
'world0': 1,
'world1': 1,
'world2': 2,
'world3': 2,
'world4': 3,
'world5': 3
}
for world in ['world{}'.format(i) for i in range(6)]:
files = ls('saved_data/**/{}*'.format(world))
for filename in files:
user = int(filename.split('/')[1].split('-')[0][1:])
traj = int(filename.split('-')[-1].split('.')[0])
data = load(filename)
if isempty(data):
continue
for uh, ur, xh, xr, t in zip(data['uh'], data['ur'], data['xh'], data['xr'], data['t']):
point = {
'user': user,
'trajectory': traj,
'scenario': scenario[world],
'condition': condition[world],
'time': t,
'human_x': xh[0],
'human_y': xh[1],
'human_heading': xh[2],
'human_speed': xh[3],
'human_steer': uh[0],
'human_acceleration': uh[1],
'robot_x': xh[0],
'robot_y': xh[1],
'robot_heading': xh[2],
'robot_speed': xh[3],
'robot_steer': uh[0],
'robot_acceleration': uh[1],
}
csvs[scenario[world]-1].append(point)
for i, rows in enumerate(csvs):
with open('csvs/scenario{}.csv'.format(i+1), 'w') as f:
writer = csv.DictWriter(f, fieldnames = [
'user',
'trajectory',
'scenario',
'condition',
'time',
'human_x',
'human_y',
'human_heading',
'human_speed',
'human_steer',
'human_acceleration',
'robot_x',
'robot_y',
'robot_heading',
'robot_speed',
'robot_steer',
'robot_acceleration',
])
writer.writeheader()
writer.writerows(rows)
opts = ls('data/world*-opt.pickle')
for opt in opts:
world = opt.split('/')[1].split('-')[0]
with open('csvs/opt{}-{}.csv'.format(scenario[world], condition[world]), 'w') as f:
writer = csv.DictWriter(f, fieldnames = [
'scenario',
'condition',
'time',
'human_x',
'human_y',
'human_heading',
'human_speed',
'human_steer',
'human_acceleration',
'robot_x',
'robot_y',
'robot_heading',
'robot_speed',
'robot_steer',
'robot_acceleration',
])
writer.writeheader()
data = load(opt)
for uh, ur, xh, xr, t in zip(data['uh'], data['ur'], data['xh'], data['xr'], data['t']):
point = {
'scenario': scenario[world],
'condition': condition[world],
'time': t,
'human_x': xh[0],
'human_y': xh[1],
'human_heading': xh[2],
'human_speed': xh[3],
'human_steer': uh[0],
'human_acceleration': uh[1],
'robot_x': xh[0],
'robot_y': xh[1],
'robot_heading': xh[2],
'robot_speed': xh[3],
'robot_steer': uh[0],
'robot_acceleration': uh[1],
}
writer.writerow(point)