update count_events.py to SegmentRangeReader

old-commit-hash: e9e8f4df38
chrysler-long2
Adeeb Shihadeh 1 year ago
parent f5bf1a3389
commit 05abdcdf38
  1. 48
      selfdrive/debug/count_events.py

@ -4,16 +4,12 @@ import math
import datetime import datetime
from collections import Counter from collections import Counter
from pprint import pprint from pprint import pprint
from tqdm import tqdm
from typing import List, Tuple, cast from typing import List, Tuple, cast
from cereal.services import SERVICE_LIST from cereal.services import SERVICE_LIST
from openpilot.tools.lib.route import Route from openpilot.tools.lib.srreader import SegmentRangeReader, ReadMode
from openpilot.tools.lib.logreader import LogReader
if __name__ == "__main__": if __name__ == "__main__":
r = Route(sys.argv[1])
cnt_valid: Counter = Counter() cnt_valid: Counter = Counter()
cnt_events: Counter = Counter() cnt_events: Counter = Counter()
@ -24,31 +20,29 @@ if __name__ == "__main__":
start_time = math.inf start_time = math.inf
end_time = -math.inf end_time = -math.inf
ignition_off = None ignition_off = None
for q in tqdm(r.qlog_paths()): for msg in SegmentRangeReader(sys.argv[1], ReadMode.QLOG):
if q is None: end_time = max(end_time, msg.logMonoTime)
continue start_time = min(start_time, msg.logMonoTime)
lr = list(LogReader(q))
for msg in lr:
end_time = max(end_time, msg.logMonoTime)
start_time = min(start_time, msg.logMonoTime)
if msg.which() == 'onroadEvents': if msg.which() == 'onroadEvents':
for e in msg.onroadEvents: for e in msg.onroadEvents:
cnt_events[e.name] += 1 cnt_events[e.name] += 1
elif msg.which() == 'controlsState': elif msg.which() == 'controlsState':
if len(alerts) == 0 or alerts[-1][1] != msg.controlsState.alertType: at = msg.controlsState.alertType
if "/override" not in at or "lanechange" in at.lower():
if len(alerts) == 0 or alerts[-1][1] != at:
t = (msg.logMonoTime - start_time) / 1e9 t = (msg.logMonoTime - start_time) / 1e9
alerts.append((t, msg.controlsState.alertType)) alerts.append((t, at))
elif msg.which() == 'pandaStates': elif msg.which() == 'pandaStates':
if ignition_off is None: if ignition_off is None:
ign = any(ps.ignitionLine or ps.ignitionCan for ps in msg.pandaStates) ign = any(ps.ignitionLine or ps.ignitionCan for ps in msg.pandaStates)
if not ign: if not ign:
ignition_off = msg.logMonoTime ignition_off = msg.logMonoTime
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
duration = (end_time - start_time) / 1e9 duration = (end_time - start_time) / 1e9

Loading…
Cancel
Save