Data: choose the detectors, classic (detectors/scripts/) or manual (detectors/manual/, run in a process of its own)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-18 17:25:30 +01:00
1 parent 0db5775e97
commit 51e939fa3c
3 files changed
+39 -11

No files matched your search

+25 -3
View File
@@ -11,8 +11,10 @@ import functools
import glob
import json
import os
import pickle
import re
import statistics
import subprocess
import sys
from datetime import datetime, timedelta
from pathlib import Path
@@ -244,12 +246,32 @@ def pump(body):
# --- the Data page, "Detectors" labels: the events of the journal, read-only
# The sets of detectors: detectors/scripts/ (classic, imported here), detectors/manual/ (the same layout, hand-made: run in
# a process of its own, its modules bear the same names as the classic ones)
MANUAL = ROOT / "detectors" / "manual"
CHILD = ("import pickle, sys; out, sys.stdout = sys.stdout.buffer, sys.stderr; sys.path.insert(0, sys.argv[1]); import categories; "
"pickle.dump(categories.window(*pickle.load(sys.stdin.buffer)), out)")
def window(set_, every, a, b):
"""categories.window of the chosen set."""
if set_ != "manual":
return categories.window(every, a, b)
if not (MANUAL / "categories.py").is_file():
raise Refusal("no manual detectors: detectors/manual/ has no categories.py")
run = subprocess.run([sys.executable, "-c", CHILD, str(MANUAL)], input=pickle.dumps((every, a, b)), capture_output=True, cwd=ROOT)
sys.stderr.write(run.stderr.decode(errors="replace"))
if run.returncode:
raise Refusal("the manual detectors failed: " + (run.stderr.decode(errors="replace").strip().splitlines() or ["?"])[-1])
return pickle.loads(run.stdout)
# ponytail: kept until the server restarts (a minute or more per range); restart it after an /optimize run outside the app
@functools.lru_cache(maxsize=32)
def detectors(station, start, end, targets=""):
def detectors(station, start, end, targets="", set_="classic"):
"""-> the detectors' events over the range, in the label format (start, end, family, description); plus kind,
sensors, ignore (greyed area of the journal). targets: the sensors kept, comma-separated (empty: all); the others are
removed before the detectors, as if they did not exist."""
removed before the detectors, as if they did not exist. set_: classic (detectors/scripts/) or manual (detectors/manual/)."""
d = folder(station)
every = data.load(d)
if targets:
@@ -263,7 +285,7 @@ def detectors(station, start, end, targets=""):
"description": f"{ep['label']}. {v['text']}", "sensors": v["sensors"], "ignore": v["ignore"],
"targets": [s for s in v["sensors"] if s not in refs], "references": [s for s in v["sensors"] if s in refs],
"message": client.message(v["text"]), "action": client.action(v["category"], ep["label"], ep.get("level"), advice)}
for i, v in enumerate(categories.window(every, a, b))]
for i, v in enumerate(window(set_, every, a, b))]
# --- the labels