Events: debug script (#28898)

* Move to separate branch

* Fix mypy

* Better printout

* Fix spacing

* cleanup

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 22c413af6d
beeps
Eric Brown 2 years ago committed by GitHub
parent 99945aded5
commit 3ebff5c415
  1. 33
      selfdrive/controls/lib/events.py

@ -954,3 +954,36 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = {
}, },
} }
if __name__ == '__main__':
# print all alerts by type and priority
from cereal.services import service_list
from collections import defaultdict, OrderedDict
event_names = {v: k for k, v in EventName.schema.enumerants.items()}
alerts_by_type: Dict[str, Dict[int, List[str]]] = defaultdict(lambda: defaultdict(list))
CP = car.CarParams.new_message()
CS = car.CarState.new_message()
sm = messaging.SubMaster(list(service_list.keys()))
for i, alerts in EVENTS.items():
for et, alert in alerts.items():
if callable(alert):
alert = alert(CP, CS, sm, False, 1)
priority = alert.priority
alerts_by_type[et][priority].append(event_names[i])
all_alerts = {}
for et, priority_alerts in alerts_by_type.items():
all_alerts[et] = OrderedDict([
(str(priority), l)
for priority, l in sorted(priority_alerts.items(), key=lambda x: -int(x[0]))
])
for status, evs in sorted(all_alerts.items(), key=lambda x: x[0]):
print(f"**** {status} ****")
for p, alert_list in evs.items():
print(f" {p}:")
print(" ", ', '.join(alert_list), "\n")

Loading…
Cancel
Save