-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathloglibPlus.py
More file actions
1093 lines (1062 loc) · 40.9 KB
/
Copy pathloglibPlus.py
File metadata and controls
1093 lines (1062 loc) · 40.9 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import math
from datetime import datetime, timezone
import logging
import gzip
from multiprocessing import Pool
import json
import matplotlib
def date2num(d):
return matplotlib.dates.date2num(d)
def num2date(n):
return matplotlib.dates.num2date(n).replace(tzinfo=None)
def rbktimetodate(rbktime):
""" 将rbk的时间戳转化为datatime """
if len(rbktime) == 17:
return datetime.strptime(rbktime, '%y%m%d %H%M%S.%f')
else:
return datetime.strptime(rbktime, '%Y-%m-%d %H:%M:%S.%f')
def findrange(ts, t1, t2):
""" 在ts中寻找大于t1小于t2对应的下标 """
small_ind = -1
large_ind = len(ts)-1
for i, data in enumerate(ts):
large_ind = i
if(t1 <= data and small_ind < 0):
small_ind = i
if(t2 <= data):
break
return small_ind, large_ind
def polar2xy(angle, dist):
""" 将极坐标angle,dist 转化为xy坐标 """
x , y = [], []
for a, d in zip(angle, dist):
x.append(d * math.cos(a))
y.append(d * math.sin(a))
return x,y
def worker(args):
lines = args[0]
argv = args[1]
l0 = lines["l0"]
print("lines size", len(lines["data"]), "argv size", len(argv))
for ind, line in enumerate(lines["data"]):
break_flag = False
for data in argv:
if type(data).__name__ == 'dict':
for k in data.keys():
data[k].parsed_flag = True
if data[k].parse(line, ind + l0):
break_flag = True
break
if break_flag:
break_flag = False
break
elif data.parse(line):
break
return (l0, argv)
class ReadLog:
""" 读取Log """
def __init__(self, filenames):
""" 支持传入多个文件名称"""
self.filenames = filenames
self.lines = []
self.lines_num = 0
self.thread_num = 4
self.tmin = None
self.tmax = None
self.regex = re.compile("\[(.*?)\].*")
def _startTime(self, f, file):
for line in f.readlines():
try:
line = line.decode('utf-8')
except UnicodeDecodeError:
try:
line = line.decode('gbk')
except UnicodeDecodeError:
logging.debug("{}: {} {}".format(file, " Skipped due to decoding failure!", line))
continue
if "RoboKit Log Start" in line:
continue
out = self.regex.match(line)
if out:
return rbktimetodate(out.group(1))
return None
def _readData(self, f, file):
lines = []
for line in f.readlines():
try:
line = line.decode('utf-8')
except UnicodeDecodeError:
try:
line = line.decode('gbk')
except UnicodeDecodeError:
logging.debug("{}: {} {}".format(file, " Skipped due to decoding failure!", line))
continue
if "RoboKit Log Start" in line:
continue
lines.append(line)
for line in lines:
out = self.regex.match(line)
if out:
t = rbktimetodate(out.group(1))
if self.tmin is None:
self.tmin = t
elif self.tmin > t:
self.tmin = t
break
for line in reversed(lines):
out = self.regex.match(line)
if out:
t = rbktimetodate(out.group(1))
if self.tmax is None:
self.tmax = t
elif self.tmax < t:
self.tmax = t
break
self.lines.extend(lines)
def _work(self, argv):
self.lines_num = len(self.lines)
al = int(self.lines_num/self.thread_num)
if al < 1000:
for ind, line in enumerate(self.lines):
break_flag = False
for data in argv:
if type(data).__name__ == 'dict':
for k in data.keys():
data[k].parsed_flag = True
if data[k].parse(line, ind):
break_flag = True
break
if break_flag:
break_flag = False
break
elif data.parse(line):
break
else:
line_caches = []
print("thread num:", self.thread_num, ' lines_num:', self.lines_num)
for i in range(self.thread_num):
if i is self.thread_num -1:
tmp = dict()
tmp['l0'] = i * al
tmp['data'] = self.lines[i*al:]
line_caches.append((tmp, argv))
else:
tmp = dict()
tmp['l0'] = i * al
tmp['data'] = self.lines[i*al:((i+1)*al)]
line_caches.append((tmp, argv))
result = []
with Pool(self.thread_num) as pool:
result = pool.map(worker, line_caches)
def sortFunc(ds):
return ds[0]
result.sort(key = sortFunc)
print("done!!!")
print("len(result): ", len(result))
for s in result:
for (a,b) in zip(argv,s[1]):
if type(a) is dict:
for k in a.keys():
a[k].insert_data(b[k])
else:
a.insert_data(b)
for data in argv:
if type(data).__name__ == 'dict':
for k in data.keys():
data[k].parsed_flag = True
print("content size:", len(data[k].data['t']))
def parse(self,*argv):
"""依据输入的正则进行解析"""
self.lines = []
self.tmin = None
self.tmax = None
file_ind = []
file_stime = []
for (ind,file) in enumerate(self.filenames):
if file.endswith(".log"):
try:
with open(file,'rb') as f:
st = self._startTime(f, file_ind)
if st != None:
file_ind.append(ind)
file_stime.append(st)
except:
continue
else:
try:
with gzip.open(file,'rb') as f:
st = self._startTime(f, file_ind)
if st != None:
file_ind.append(ind)
file_stime.append(st)
except:
continue
max_location =sorted(enumerate(file_stime), key=lambda y:y[1])
#print(max_location)
new_file_ind = []
for i in range(len(max_location)):
new_file_ind.append(file_ind[max_location[i][0]])
for i in new_file_ind:
file = self.filenames[i]
if file.endswith(".log"):
try:
with open(file,'rb') as f:
self._readData(f,file)
except:
continue
else:
try:
with gzip.open(file,'rb') as f:
self._readData(f, file)
except:
continue
self._work(argv)
class Data:
def __init__(self, info, key_name:str, text_key:str = None):
if key_name == "Text":
self.type = text_key
self.text_key = text_key
self.regex = re.compile("\[(.*?)\].*\[Text\]\[(.*?)\]$")
self.regex2 = re.compile("\[(.*?)\].*\[Text\|(.*?)\]$")
self.short_regx = "["+"Text"
else:
self.type = key_name
self.text_key = None
self.regex = re.compile("\[(.*?)\].*\["+self.type+"\]\[(.*?)\]$")
self.regex2 = re.compile("\[(.*?)\].*\["+self.type+"\|(.*?)\]$")
self.short_regx = "["+self.type
self.info = info['content']
self.data = dict()
self.data['t'] = []
self.description = dict()
self.unit = dict()
self.parse_error = False
self.parsed_flag = False
self.line_num = []
for tmp in self.info:
if 'name' not in tmp:
continue
self.data[tmp['name']] = []
if 'unit' in tmp:
self.unit[tmp['name']] = tmp['unit']
else:
self.unit[tmp['name']] = ""
if 'description' in tmp:
if type(tmp['description']) is str:
self.description[tmp['name']] = tmp['description'] + " " + self.unit[tmp['name']]
elif type(tmp['description']) is int:
self.description[tmp['name']] = tmp['description']
else:
self.description[tmp['name']] = self.type + '.' + tmp['name'] + " " + self.unit[tmp['name']]
else:
self.description[tmp['name']] = self.type + '.' + tmp['name'] + " " + self.unit[tmp['name']]
def _storeData(self, tmp, ind, values):
name = tmp['name']
if tmp['type'] == 'double' or tmp['type'] == 'int64' or tmp['type'] == 'int':
try:
self.data[name].append(float(values[ind]))
except:
try:
d = "".join([i for i in values[ind] if i.isdigit() or i == "."])
self.data[name].append(float(d))
except:
self.data[name].append(0.0)
elif tmp['type'] == 'mm':
try:
self.data[name].append(float(values[ind])/1000.0)
except:
self.data[name].append(0.0)
elif tmp['type'] == 'cm':
try:
self.data[name].append(float(values[ind])/100.0)
except:
self.data[name].append(0.0)
elif tmp['type'] == 'rad':
try:
self.data[name].append(float(values[ind])/math.pi * 180.0)
except:
self.data[name].append(0.0)
elif tmp['type'] == 'm':
try:
self.data[name].append(float(values[ind]))
except:
self.data[name].append(0.0)
elif tmp['type'] == 'LSB':
try:
self.data[name].append(float(values[ind])/16.03556)
except:
self.data[name].append(0.0)
elif tmp['type'] == 'bool':
try:
if values[ind] == "true" or values[ind] == "1":
self.data[name].append(1.0)
else:
self.data[name].append(0.0)
except:
self.data[name].append(0.0)
elif tmp['type'] == 'json':
try:
self.data[name].append(json.loads(values[ind]))
except:
self.data[name].append(values[ind])
elif tmp['type'] == 'str':
self.data[name].append(values[ind])
else:
self.data[name].append(values[ind])
def parse(self, line, num):
if self.short_regx not in line:
return False
if self.isText() and self.text_key not in line:
return False
out = self.regex.match(line)
if not out:
out = self.regex2.match(line)
if not out:
return False
datas = out.groups()
values = datas[1].split('|')
self.data['t'].append(rbktimetodate(datas[0]))
info = self.info
if self.info == "key|value":
info = []
half_value = int(len(values)/2)
for d in range(half_value):
try:
_ = float(values[d*2])
info.append({'name': "value_{}".format(d*2), "index": d*2, "type": "double"})
info.append({'name': "value_{}".format(d*2+1), "index": d*2+1, "type": "double"})
except:
info.append({'name': values[d*2], "index": d * 2 + 1, "type": "double"})
if half_value *2 < len(values):
# 对于奇数项的数据
for d in range(half_value*2, len(values)):
info.append({'name': "value_{}".format(d), "index": d, "type": "double"})
for (ind, tmp) in enumerate(info):
if 'index' not in tmp:
tmp["index"] = ind
if 'type' in tmp and 'index' in tmp and 'name' in tmp:
index = int(tmp['index'])
if index < 0:
index = len(values) + index
name = tmp['name']
if name not in self.data:
self.data[name] =[]
if len(self.data['t']) > 0:
for _ in range(len(self.data['t'])-1):
self.data[name].append(None)
if name not in self.description:
self.description[name] = name
if name in self.description:
if type(self.description[name]) is int:
if 'description' in tmp:
tmp_type = type(tmp['description'])
description = ""
has_description = False
if tmp_type is str:
description = tmp['description']
has_description = True
elif tmp_type is int:
if tmp['description'] < len(values) and index < len(values):
description = values[tmp['description']]
has_description = True
if has_description:
self.description[name] = description + " " + self.unit[name]
else:
self.description[name] = name
if index < len(values) and index >=0 :
self._storeData(tmp, index, values)
else:
self.data[name].append(None)
else:
if not self.parse_error:
logging.error("Error in {} {} ".format(self.type, tmp.keys()))
self.parse_error = True
self.line_num.append(num)
return True
def parse_now(self, lines):
if not self.parsed_flag:
for ind, line in enumerate(lines):
self.parse(line, ind)
def __getitem__(self,k):
return self.data[k]
def __setitem__(self,k,value):
self.data[k] = value
def insert_data(self, other):
org_len_t = len(self.data['t'])
for key in other.data.keys():
if key in self.data.keys():
self.data[key].extend(other.data[key])
else:
if self.info == "key|value":
if key != 't':
if org_len_t > 0:
self.data[key] = [None] * org_len_t
else:
self.data[key] = []
self.data[key].extend(other.data[key])
else:
self.data[key] = other.data[key]
for key in self.data:
if key == 't':
continue
if len(self.data[key]) < len(self.data['t']):
self.data[key].extend([None] * (len(self.data['t']) - len(self.data[key])))
for key in other.description.keys():
if key not in self.description.keys():
self.description[key] = other.description[key]
self.line_num.extend(other.line_num)
def isText(self):
return self.text_key != None
class Laser:
""" 激光雷达的数据
data[0]: t
data[1]: ts 激光点的时间戳
data[2]: angle rad
data[3]: dist m
data[4]: x m
data[5]: y m
data[6]: number
data[7]: rssi
"""
def __init__(self, max_dist):
""" max_dist 为激光点的最远距离,大于此距离激光点无效"""
self.regex = re.compile('\[(.*?)\].*\[Laser:? ?(\d*?)\]\[(.*?)\]')
self.regexV2 = re.compile('\[(.*?)\].*\[LaserWithRssi:? ?(\d*?)\]\[(.*?)\]')
self.regexV3 = re.compile('\[(.*?)\].*\[LaserWithRssiAndPose:? ?(\d*?)\]\[(.*?)\]')
self.short_regx = "[Laser"
#self.data = [[] for _ in range(7)]
self.datas = dict()
self.max_dist = max_dist
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
datas = out.groups()
laser_id = 0
if datas[1] != "":
laser_id = int(datas[1])
if laser_id not in self.datas:
self.datas[laser_id] = [[] for _ in range(11)]
self.datas[laser_id][0].append(rbktimetodate(datas[0]))
tmp_datas = datas[2].split('|')
self.datas[laser_id][1].append(float(tmp_datas[0]))
angle = [float(tmp)/180.0*math.pi for tmp in tmp_datas[4::2]]
dist = [float(tmp) for tmp in tmp_datas[5::2]]
rssi = [0 for i in angle]
tmp_a, tmp_d = [], []
for a, d in zip(angle,dist):
if d < self.max_dist:
tmp_a.append(a)
tmp_d.append(d)
angle = tmp_a
dist = tmp_d
self.datas[laser_id][2].append(angle)
self.datas[laser_id][3].append(dist)
x , y = polar2xy(angle, dist)
self.datas[laser_id][4].append(x)
self.datas[laser_id][5].append(y)
self.datas[laser_id][6].append(len(x))
self.datas[laser_id][7].append(rssi)
self.datas[laser_id][8].append(None)
self.datas[laser_id][9].append(None)
self.datas[laser_id][10].append(None)
return True
out = self.regexV2.match(line)
if out:
datas = out.groups()
laser_id = 0
if datas[1] != "":
laser_id = int(datas[1])
if laser_id not in self.datas:
self.datas[laser_id] = [[] for _ in range(11)]
self.datas[laser_id][0].append(rbktimetodate(datas[0]))
tmp_datas = datas[2].split('|')
self.datas[laser_id][1].append(float(tmp_datas[0]))
angle = [float(tmp)/180.0*math.pi for tmp in tmp_datas[4::3]]
dist = [float(tmp) for tmp in tmp_datas[5::3]]
rssi = [float(tmp) for tmp in tmp_datas[6::3]]
tmp_a, tmp_d, tmp_r = [], [], []
for a, d, r in zip(angle,dist, rssi):
if d < self.max_dist and r >= 0:
tmp_a.append(a)
tmp_d.append(d)
tmp_r.append(r)
angle = tmp_a
dist = tmp_d
self.datas[laser_id][2].append(angle)
self.datas[laser_id][3].append(dist)
x , y = polar2xy(angle, dist)
self.datas[laser_id][4].append(x)
self.datas[laser_id][5].append(y)
self.datas[laser_id][6].append(len(x))
self.datas[laser_id][7].append(tmp_r)
self.datas[laser_id][8].append(None)
self.datas[laser_id][9].append(None)
self.datas[laser_id][10].append(None)
return True
out = self.regexV3.match(line)
if out:
datas = out.groups()
laser_id = 0
if datas[1] != "":
laser_id = int(datas[1])
if laser_id not in self.datas:
self.datas[laser_id] = [[] for _ in range(11)]
self.datas[laser_id][0].append(rbktimetodate(datas[0]))
tmp_datas = datas[2].split('|')
self.datas[laser_id][1].append(float(tmp_datas[0]))
loc_x = float(tmp_datas[4])
loc_y = float(tmp_datas[5])
loc_yaw = float(tmp_datas[6])
angle = [float(tmp)/180.0*math.pi for tmp in tmp_datas[7::3]]
dist = [float(tmp) for tmp in tmp_datas[8::3]]
rssi = [float(tmp) for tmp in tmp_datas[9::3]]
tmp_a, tmp_d, tmp_r = [], [], []
for a, d, r in zip(angle,dist, rssi):
if d < self.max_dist and r >= 0:
tmp_a.append(a)
tmp_d.append(d)
tmp_r.append(r)
angle = tmp_a
dist = tmp_d
self.datas[laser_id][2].append(angle)
self.datas[laser_id][3].append(dist)
x , y = polar2xy(angle, dist)
self.datas[laser_id][4].append(x)
self.datas[laser_id][5].append(y)
self.datas[laser_id][6].append(len(x))
self.datas[laser_id][7].append(tmp_r)
self.datas[laser_id][8].append(loc_x)
self.datas[laser_id][9].append(loc_y)
self.datas[laser_id][10].append(loc_yaw)
return True
return False
return False
def t(self, laser_index):
return self.datas[laser_index][0]
def ts(self, laser_index):
return self.datas[laser_index][1], self.datas[laser_index][0]
def angle(self, laser_index):
return self.datas[laser_index][2], self.datas[laser_index][0]
def dist(self, laser_index):
return self.datas[laser_index][3], self.datas[laser_index][0]
def x(self, laser_index):
return self.datas[laser_index][4], self.datas[laser_index][0]
def y(self, laser_index):
return self.datas[laser_index][5], self.datas[laser_index][0]
def number(self, laser_index):
return self.datas[laser_index][6], self.datas[laser_index][0]
def rssi(self, laser_index):
return self.datas[laser_index][7], self.datas[laser_index][0]
def loc_x(self, laser_index):
if len(self.datas[laser_index]) == 11:
return self.datas[laser_index][8], self.datas[laser_index][0]
return None, None
def loc_y(self, laser_index):
if len(self.datas[laser_index]) == 11:
return self.datas[laser_index][9], self.datas[laser_index][0]
return None, None
def loc_yaw(self, laser_index):
if len(self.datas[laser_index]) == 11:
return self.datas[laser_index][10], self.datas[laser_index][0]
return None, None
def insert_data(self, other):
for key in other.datas.keys():
if key in self.datas.keys():
for k in range(len(self.datas[key])):
self.datas[key][k].extend(other.datas[key][k])
else:
self.datas[key] = other.datas[key]
class DepthCamera:
""" 深度摄像头的数据
data[0]: t
data[1]: x m
data[2]: y m
data[3]: z m
data[4]: number
data[5]: ts
"""
def __init__(self):
""" max_dist 为激光点的最远距离,大于此距离激光点无效"""
self.regex = re.compile('\[(.*?)\].* \[DepthCamera\d*?\]\[(.*?)\]')
self.short_regx = "[DepthCamera"
#self.data = [[] for _ in range(7)]
self.datas = [[] for _ in range(6)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
datas = out.groups()
tmp_datas = datas[1].split('|')
if(len(tmp_datas) < 2):
return True
self.datas[0].append(rbktimetodate(datas[0]))
ts = 0
if len(tmp_datas[1:]) %3 == 0:
dx = [float(tmp) for tmp in tmp_datas[1::3]]
dy = [float(tmp) for tmp in tmp_datas[2::3]]
dz = [float(tmp) for tmp in tmp_datas[3::3]]
ts = float(tmp_datas[0])
elif len(tmp_datas)%2 == 0:
dx = [float(tmp) for tmp in tmp_datas[0::2]]
dy = [float(tmp) for tmp in tmp_datas[1::2]]
dz = [0 for tmp in dx]
else:
dx = [float(tmp) for tmp in tmp_datas[1::2]]
dy = [float(tmp) for tmp in tmp_datas[2::2]]
dz = [0 for tmp in dx]
ts = float(tmp_datas[0])
self.datas[1].append(dx)
self.datas[2].append(dy)
self.datas[3].append(dz)
self.datas[4].append(len(tmp_datas))
self.datas[5].append(ts)
return True
return False
return False
def t(self):
return self.datas[0]
def x(self):
return self.datas[1], self.datas[0]
def y(self):
return self.datas[2], self.datas[0]
def z(self):
return self.datas[3], self.datas[0]
def number(self):
return self.datas[4], self.datas[0]
def ts(self):
return self.datas[5], self.datas[0]
def insert_data(self, other):
for i in range(len(self.datas)):
self.datas[i].extend(other.datas[i])
class ParticleState:
""" 粒子滤波数据
data[0]: t
data[1]: x m
data[2]: y m
data[3]: theta m
data[4]: number
data[5]: ts
"""
def __init__(self):
self.regex = re.compile('\[(.*?)\].* \[Particle State: \]\[(.*?)\]')
self.short_regx = "[Particle State:"
#self.data = [[] for _ in range(7)]
self.datas = [[] for _ in range(6)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
datas = out.groups()
tmp_datas = datas[1].split('|')
if(len(tmp_datas) < 2):
return True
dx, dy, dz, ts = [], [], [], 0
if len(tmp_datas[1:]) %3 == 0:
dx = [float(tmp) for tmp in tmp_datas[1::3]]
dy = [float(tmp) for tmp in tmp_datas[2::3]]
dz = [float(tmp) for tmp in tmp_datas[3::3]]
ts = float(tmp_datas[0])
else:
return True
self.datas[0].append(rbktimetodate(datas[0]))
self.datas[1].append(dx)
self.datas[2].append(dy)
self.datas[3].append(dz)
self.datas[4].append(len(dx))
self.datas[5].append(ts)
return True
return False
return False
def t(self):
return self.datas[0]
def x(self):
return self.datas[1], self.datas[0]
def y(self):
return self.datas[2], self.datas[0]
def theta(self):
return self.datas[3], self.datas[0]
def number(self):
return self.datas[4], self.datas[0]
def ts(self):
return self.datas[5], self.datas[0]
def insert_data(self, other):
for i in range(len(self.datas)):
self.datas[i].extend(other.datas[i])
class ErrorLine:
""" 错误信息
data[0]: t
data[1]: 错误信息内容
data[2]: Alarm 错误编号
data[3]: Alarm 内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[Alarm\]\[Error\|(.*?)\|(.*?)\|.*")
self.short_regx = "[Alarm][Error"
self.data = [[] for _ in range(4)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
new_num = out.group(2)
if not new_num in self.data[2]:
self.data[2].append(new_num)
self.data[3].append(out.group(3))
return True
else:
pass
# out = self.general_regex.match(line)
# if out:
# self.data[0].append(rbktimetodate(out.group(1)))
# self.data[1].append(out.group(0))
# new_num = '00000'
# if not new_num in self.data[2]:
# self.data[2].append(new_num)
# self.data[3].append('unKnown Error')
# return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def alarmnum(self):
return self.data[2], self.data[0]
def alarminfo(self):
return self.data[3], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class WarningLine:
""" 报警信息
data[0]: t
data[1]: 报警信息内容
data[2]: Alarm 错误编号
data[3]: Alarm 内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*?\[Alarm\]\[Warning\|(.*?)\|(.*?)\|.*")
self.short_regx = "[Alarm][Warning"
self.data = [[] for _ in range(4)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
new_num = out.group(2)
if not new_num in self.data[2]:
self.data[2].append(new_num)
self.data[3].append(out.group(3))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def alarmnum(self):
return self.data[2], self.data[0]
def alarminfo(self):
return self.data[3], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class FatalLine:
""" 错误信息
data[0]: t
data[1]: 报警信息内容
data[2]: Alarm 错误编号
data[3]: Alarm 内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[f.*?\].*\[Alarm\]\[Fatal\|(.*?)\|(.*?)\|.*")
self.short_regx = "[Alarm][Fatal"
self.data = [[] for _ in range(4)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
new_num = out.group(2)
if not new_num in self.data[2]:
self.data[2].append(new_num)
self.data[3].append(out.group(3))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def alarmnum(self):
return self.data[2], self.data[0]
def alarminfo(self):
return self.data[3], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class NoticeLine:
""" 注意信息
data[0]: t
data[1]: 注意信息内容
data[2]: Alarm 错误编号
data[3]: Alarm 内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[Alarm\]\[Notice\|(.*?)\|(.*?)\|.*")
self.short_regx = "[Alarm][Notice"
self.data = [[] for _ in range(4)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
new_num = out.group(2)
if not new_num in self.data[2]:
self.data[2].append(new_num)
self.data[3].append(out.group(3))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def alarmnum(self):
return self.data[2], self.data[0]
def alarminfo(self):
return self.data[3], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class TaskStart:
""" 任务开始信息
data[0]: t
data[1]: 开始信息内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[Text\]\[cnt:.*")
self.short_regx = "Text][cnt"
self.data = [[] for _ in range(2)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class TaskFinish:
""" 任务结束信息
data[0]: t
data[1]: 结束信息内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[Text\]\[Task finished.*")
self.short_regx = "Text][Task finished"
self.data = [[] for _ in range(2)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class Service:
""" 服务信息
data[0]: t
data[1]: 服务内容
"""
def __init__(self):
self.regex = re.compile("\[(.*?)\].*\[Service\].*")
self.short_regx = "[Service"
self.data = [[] for _ in range(2)]
def parse(self, line):
if self.short_regx in line:
out = self.regex.match(line)
if out:
if "(call from C++)" not in line :
self.data[0].append(rbktimetodate(out.group(1)))
self.data[1].append(out.group(0))
return True
return False
return False
def t(self):
return self.data[0]
def content(self):
return self.data[1], self.data[0]
def insert_data(self, other):
for i in range(len(self.data)):
self.data[i].extend(other.data[i])
class Memory:
""" 内存信息
t[0]:
t[1]:
t[2]:
t[3]:
t[4]:
t[5]:
data[0]: used_sys
data[1]: free_sys
data[2]: rbk_phy
data[3]: rbk_vir
data[4]: rbk_max_phy
data[5]: rbk_max_vir
data[6]: cpu_usage
"""
def __init__(self):
self.regex = [re.compile("\[(.*?)\].*\[Text\]\[Used system memory *: *(.*?) *([MG])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Free system memory *: *(.*?) *([MG])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Robokit physical memory usage *: *(.*?) *([GM])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Robokit virtual memory usage *: *(.*?) *([GM])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Robokit Max physical memory usage *: *(.*?) *([GM])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Robokit Max virtual memory usage *: *(.*?) *([GM])B\]"),
re.compile("\[(.*?)\].*\[Text\]\[Robokit CPU usage *: *(.*?)%\]"),
re.compile("\[(.*?)\].*\[Text\]\[System CPU usage *: *(.*?)%\]")]
self.short_regx = ["Used system",
"Free system",
"Robokit physical memory",
"Robokit physical memory",
"Max physical memory",
"Max virtual memory",
"Robokit CPU usage",
"System CPU usage"]
self.time = [[] for _ in range(8)]
self.data = [[] for _ in range(8)]
def parse(self, line):
for iter in range(0,8):
if self.short_regx[iter] in line:
out = self.regex[iter].match(line)
if out:
self.time[iter].append(rbktimetodate(out.group(1)))
if iter == 6 or iter == 7:
self.data[iter].append(float(out.group(2)))
else:
if out.group(3) == "G":
self.data[iter].append(float(out.group(2)) * 1024.0)
else:
self.data[iter].append(float(out.group(2)))
return True
return False
return False
def t(self):
return self.time[0]
def used_sys(self):
return self.data[0], self.time[0]
def free_sys(self):
return self.data[1], self.time[1]