From 3ebff5c415e6c109b7cfeceb0373faae1a82b4a5 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Sun, 16 Jul 2023 17:59:27 -0600 Subject: [PATCH] Events: debug script (#28898) * Move to separate branch * Fix mypy * Better printout * Fix spacing * cleanup --------- Co-authored-by: Adeeb Shihadeh old-commit-hash: 22c413af6de56450cad3db4a978527549a924eaa --- selfdrive/controls/lib/events.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) mode change 100644 => 100755 selfdrive/controls/lib/events.py diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py old mode 100644 new mode 100755 index 9f3c2fa92..19540f06f --- a/selfdrive/controls/lib/events.py +++ b/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")