count_events.py: show alerts

pull/28205/head
Adeeb Shihadeh 2 years ago
parent 13504f5ecf
commit ec53fad3c4
  1. 18
      selfdrive/debug/count_events.py

@ -5,7 +5,7 @@ import datetime
from collections import Counter from collections import Counter
from pprint import pprint from pprint import pprint
from tqdm import tqdm from tqdm import tqdm
from typing import cast from typing import List, Tuple, cast
from cereal.services import service_list from cereal.services import service_list
from tools.lib.route import Route from tools.lib.route import Route
@ -20,6 +20,7 @@ if __name__ == "__main__":
cams = [s for s in service_list if s.endswith('CameraState')] cams = [s for s in service_list if s.endswith('CameraState')]
cnt_cameras = dict.fromkeys(cams, 0) cnt_cameras = dict.fromkeys(cams, 0)
alerts: List[Tuple[float, str]] = []
start_time = math.inf start_time = math.inf
end_time = -math.inf end_time = -math.inf
for q in tqdm(r.qlog_paths()): for q in tqdm(r.qlog_paths()):
@ -27,18 +28,22 @@ if __name__ == "__main__":
continue continue
lr = list(LogReader(q)) lr = list(LogReader(q))
for msg in lr: for msg in lr:
end_time = max(end_time, msg.logMonoTime)
start_time = min(start_time, msg.logMonoTime)
if msg.which() == 'carEvents': if msg.which() == 'carEvents':
for e in msg.carEvents: for e in msg.carEvents:
cnt_events[e.name] += 1 cnt_events[e.name] += 1
elif msg.which() == 'controlsState':
if len(alerts) == 0 or alerts[-1][1] != msg.controlsState.alertType:
t = (msg.logMonoTime - start_time) / 1e9
alerts.append((t, msg.controlsState.alertType))
elif msg.which() in cams: elif msg.which() in cams:
cnt_cameras[msg.which()] += 1 cnt_cameras[msg.which()] += 1
if not msg.valid: if not msg.valid:
cnt_valid[msg.which()] += 1 cnt_valid[msg.which()] += 1
end_time = max(end_time, msg.logMonoTime)
start_time = min(start_time, msg.logMonoTime)
duration = (end_time - start_time) / 1e9 duration = (end_time - start_time) / 1e9
print("Events") print("Events")
@ -55,5 +60,10 @@ if __name__ == "__main__":
expected_frames = int(s.frequency * duration / cast(float, s.decimation)) expected_frames = int(s.frequency * duration / cast(float, s.decimation))
print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected") print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected")
print("\n")
print("Alerts")
for t, a in alerts:
print(f"{t:8.2f} {a}")
print("\n") print("\n")
print("Route duration", datetime.timedelta(seconds=duration)) print("Route duration", datetime.timedelta(seconds=duration))

Loading…
Cancel
Save