27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
"""Print the raw episodes of every detector (before classification) touching a range, computed on the range plus its 3 days of history (as score.py). Usage: python3 raw_episodes.py <detectors dir> <station folder> FROM TO [detector names, comma-separated]"""
|
|
import inspect
|
|
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, start, end = sys.argv[2], iso(parse_time(sys.argv[3])), iso(parse_time(sys.argv[4]))
|
|
only = sys.argv[5].split(",") if len(sys.argv) > 5 else None
|
|
ms = load(folder)
|
|
h, b = parse_time(start) - timedelta(days=3), parse_time(end)
|
|
chunk = {s: k for s, v in ms.items() if (k := [m for m in v if h <= m["t"] < b])}
|
|
for mod in categories.detectors():
|
|
name = mod.__name__.removeprefix("detector_")
|
|
if only and name not in only:
|
|
continue
|
|
params = inspect.signature(mod.detect).parameters
|
|
kw = {k: categories._context(folder, k) for k in categories.CONTEXT if k in params}
|
|
if "end" in params:
|
|
kw["end"] = None
|
|
for e in mod.detect(chunk, **kw):
|
|
if e["end"] >= start and e["start"] < end:
|
|
print(name, e["start"], "→", e["end"], e["kind"], "|", e["label"], e.get("level", ""), "|", len(e["sensors"]),
|
|
",".join(e["sensors"][:6]), "|", e["text"][:90])
|