-
Notifications
You must be signed in to change notification settings - Fork 2
/
mc_rtc_log_conv.py
73 lines (63 loc) · 2.34 KB
/
mc_rtc_log_conv.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
import sys
import os
import mc_log_ui
import argparse
# import metayaml
import re
import pandas as pd
def has_duplicates(l):
return len(l) != len(set(l))
def expand_str_to_list (input_str):
parsed = re.match("([0-9]+)-([0-9]+)", input_str)
if parsed:
return range(int(parsed.group(1)),int(parsed.group(2))+1)
else:
return input_str
def main():
# args
parser = argparse.ArgumentParser(description='Convert data from mc_rtc log to hrpsys log')
parser.add_argument('-f', type=str, help='input file', metavar='file', required=True)
parser.add_argument('-d', type=str, help='output dir', metavar='file')
parser.add_argument('-p', type=str, help='prefix', metavar='file')
parser.add_argument('--plot', type=str, help='plot configure file', metavar='file')
parser.add_argument('--output', type=str, help='output file', metavar='file')
args = parser.parse_args()
# load log file
mc_rtc_log = mc_log_ui.read_log(args.f)
# mc_rtc logのtopic名を取得
topic_list = {}
# mc_rtc topic list
if args.plot:
pass
# plot_dict = metayaml.read(args.plot)
# file_expand_name = plot_dict.keys()
# for i in file_expand_name:
# topic_list[plot_dict[i]['data'][0]['log']] = [key for key in mc_rtc_log.keys() if plot_dict[i]['data'][0]['log'] in key]
else:
for keys in mc_rtc_log.keys():
key = keys.rsplit('_',1)
if key[0] == 't':
continue
else:
if key[0] in topic_list.keys():
topic_list[key[0]].append(keys)
else:
topic_list[key[0]] = [keys]
if args.p is None:
prefix=args.f.split('.')[0]
## 'mc-control-BaselineWalkingController-2024-10-29-12-51-28'
else:
prefix = args.p
if args.d is not None:
prefix = args.d + '/' + prefix.split('/')[-1]
df_list = {}
for topic in topic_list.keys():
df = pd.DataFrame(index=mc_rtc_log["t"], columns=topic_list[topic])
for key in topic_list[topic]:
if key in mc_rtc_log.keys():
df[key] = mc_rtc_log[key]
if not df.empty:
df.to_csv(prefix + '.' + topic , sep=' ', na_rep= 0, index=True, header=False, float_format="%.16e")
df_list[topic] = df
if __name__ == "__main__":
main()