# Print a long-tail clip's event and the vehicle's speed two seconds either side of it.
# usage: python event_speed.py roaddata-long-tail-events-sample/clips/lt_hb_0007.json
import json, sys
d = json.load(open(sys.argv[1]))
m = d["meta"]; t0 = m["event_time_s"]
who = (m.get("key_road_user") or {}).get("cls", "-")
print(m["clip_id"], m["category"], f"event at {t0} s, key road user: {who}")
win = [p for p in d["gps_track"] if t0 - 2 <= p["t"] <= t0 + 2]
print(f"speed {win[0]['speed_mps']:.1f} m/s at {win[0]['t']:.1f} s -> {win[-1]['speed_mps']:.1f} m/s at {win[-1]['t']:.1f} s")
