Files

17 lines
852 B
Python

# Traces the episodes of one sensor through categories.events over a window: the event each one ends in (or none). Args: <detectors dir> <station folder> <from> <to> <sensor>
import sys
from datetime import datetime, timedelta, timezone
from pathlib import Path
det = Path(sys.argv[1]).resolve()
sys.path[:0] = [str(det / "scripts")]
import categories
from data import load
day = lambda d: datetime.strptime(d, "%Y-%m-%d").replace(tzinfo=timezone.utc)
a, b, s = day(sys.argv[3]), day(sys.argv[4]), sys.argv[5]
ms = load(sys.argv[2])
chunk = {k: x for k, v in ms.items() if (x := [m for m in v if a - timedelta(days=3) <= m["t"] < b])}
for v in categories.events(chunk, b):
for e in v["episodes"]:
if s in e["sensors"] and len(e["sensors"]) < 5:
print(v["start"], v["end"], v["category"], "<-", e["start"], e["end"], e["label"])