-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_repo.py
More file actions
46 lines (39 loc) · 1.03 KB
/
function_repo.py
File metadata and controls
46 lines (39 loc) · 1.03 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
def parse_path(path):
return [x.strip() for x in path.split('.')]
def path_get(msg, path):
v = msg
for p in path:
v = getattr(v, p)
return v
def bag_stamp_factory():
def bag_stamp(t, _):
return t
return bag_stamp
def stamp_to_ns_factory(path):
path = parse_path(path)
def stamp_to_ns(_, msg):
stamp = path_get(msg, path)
return stamp.sec * 10**9 + stamp.nanosec
return stamp_to_ns
def get_factory(path):
path = parse_path(path)
def get(_, msg):
return path_get(msg, path)
return get
def scale_offset_factory(path, scale, offset):
path = parse_path(path)
def scale_offset(_, msg):
return path_get(msg, path) * float(scale) + float(offset)
return scale_offset
def index_array_factory(path, idx):
path = parse_path(path)
def index(_, msg):
return path_get(msg, path)[int(idx)]
return index
FUNCTION_FACTORIES = {
'GET': get_factory,
'STAMP_TO_NS': stamp_to_ns_factory,
'SCALE_OFFSET': scale_offset_factory,
'BAG_STAMP': bag_stamp_factory,
'INDEX': index_array_factory
}