ConsDrive / scripts /analysis /stall_summary.py
ZenoNing's picture
Upload ConsDrive v2 source (part 2)
314ecfb verified
Raw History Blame Contribute Delete
1.25 kB
"""Summarise stall_reasons.py output for several runs.
Usage: python stall_summary.py NAME=stalls.json [NAME=stalls.json ...]
"""
import json
import sys
FREE_RUNS = (5, 10, 20)
print(f"{'run':10s} {'stops':>5s} {'stopped_s':>9s} {'free_s':>7s} {'blocked_s':>9s} {'red_s':>6s} "
+ " ".join(f"{'free>=' + str(k):>8s}" for k in FREE_RUNS)
+ f" {'start_free>=5':>13s} {'creep':>5s} {'creep_free':>10s} {'creep_conf':>10s} {'end_stopped':>11s}")
for arg in sys.argv[1:]:
name, path = arg.split("=", 1)
stalls = json.load(open(path))
stops = [s for v in stalls.values() for s in v]
creeps = [s for s in stops if s["ended"] == "creep"]
print(f"{name:10s} {len(stops):5d} {sum(s['duration'] for s in stops):9.0f} {sum(s['free'] for s in stops):7.0f} "
f"{sum(s['blocked'] for s in stops):9.0f} {sum(s['red_light'] for s in stops):6.0f} "
+ " ".join(f"{sum(s['free_run_s'] >= k for s in stops):8d}" for k in FREE_RUNS)
+ f" {sum(s['route_start'] and s['free_run_s'] >= 5 for s in stops):13d} {len(creeps):5d}"
f" {sum(s['free_run_s'] >= 5 for s in creeps):10d} {sum(s['departed_into_conflict'] for s in creeps):10d}"
f" {sum(s['ended'] == 'route_end' for s in stops):11d}")