19 lines
1.0 KiB
Python
19 lines
1.0 KiB
Python
"""Classify a long window (as the benchmark does: the labels' whole range, 3 days of history) and print only the events touching a shorter sub-window. Usage: python3 events_in_window.py <detectors dir> <station folder> FROM TO SHOW_FROM SHOW_TO"""
|
|
import sys
|
|
from datetime import timedelta
|
|
|
|
sys.path.insert(0, sys.argv[1] + "/scripts")
|
|
import categories # noqa: E402
|
|
from data import iso, load, parse_time # noqa: E402
|
|
|
|
folder, a, b, sa, sb = sys.argv[2:7]
|
|
ms = load(folder)
|
|
h, e = parse_time(a) - timedelta(days=3), parse_time(b)
|
|
chunk = {s: k for s, x in ms.items() if (k := [m for m in x if h <= m["t"] < e])}
|
|
sa, sb = iso(parse_time(sa)), iso(parse_time(sb))
|
|
for v in categories.events(chunk, folder=folder):
|
|
if v["end"] >= sa and v["start"] < sb:
|
|
print(v["start"], "→", v["end"], f"{v['category']:<20}", f"| {v['episodes'][0]['label']}",
|
|
f"| {len(v['sensors'])}:", ",".join(v["sensors"][:6]), "| absorbed:",
|
|
", ".join(f"{x['label']} {x['start'][5:16]}" for x in v["episodes"][1:])[:200] or "—")
|