diff --git a/app/server/server.py b/app/server/server.py
index 8641cc6..b4456e5 100644
--- a/app/server/server.py
+++ b/app/server/server.py
@@ -76,8 +76,8 @@ def curves(station_: str = Query(alias="station"), start: str = "", end: str = "
@app.get("/api/detectors")
-def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = ""):
- return station.detectors(station_, start, end, targets)
+def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = "", set_: str = Query("classic", alias="set")):
+ return station.detectors(station_, start, end, targets, set_)
@app.get("/api/tracked")
diff --git a/app/server/station.py b/app/server/station.py
index d6d88f8..db70820 100644
--- a/app/server/station.py
+++ b/app/server/station.py
@@ -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
diff --git a/app/web/src/pages/Data.jsx b/app/web/src/pages/Data.jsx
index b845c5e..cee68b2 100644
--- a/app/web/src/pages/Data.jsx
+++ b/app/web/src/pages/Data.jsx
@@ -50,6 +50,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
const [source, setSource] = useState("detectors"), [families, setFamilies] = useState(DETECTED), [targets, setTargets] = useState("");
const [focus, setFocus] = useState(false); // with an event open, the plots show only its sensors
const [hidden, setHidden] = useState([]); // the targets removed from the plots (the detectors still read them)
+ const [set, setSet] = useState("classic"); // the detectors: classic (detectors/scripts/) or manual (detectors/manual/)
const [cut, setCut] = useState(false); // the points under a label of the checked families removed, the curves joined
const { station, start, end } = selection;
useEffect(() => {
@@ -75,7 +76,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
{loading && }
{data && }
{data && setMoment({ t, nearest })}
- source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} cut={cut}
+ source={source} setSource={setSource} families={families} targets={targets} focus={focus} hidden={hidden} cut={cut} set={set}
analysis={analysis} setAnalysis={setAnalysis} support={support} setSupport={setSupport} />}
@@ -85,7 +86,7 @@ export default function Data({ selection, choose, analysis, setAnalysis, support
setWide(!wide)} moment={moment} />
{data && }
+ focus={focus} setFocus={setFocus} cut={cut} setCut={setCut} set={set} setSet={setSet} />}
@@ -117,7 +118,7 @@ function TargetFilter({ d, hidden, setHidden }) {
// The families apply at once (filter of the page, Detectors and LLM); the targets, with the button: each set of targets
// runs the detectors again (the LLM labels do not state their sensors: they do not filter them)
-function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus, cut, setCut }) {
+function Settings({ d, families, setFamilies, targets, setTargets, detect, focus, setFocus, cut, setCut, set, setSet }) {
const sensors = Object.keys(d.T).filter(k => k && !k.startsWith("system:"));
const refs = new Set(d.plots.flatMap(p => p.traces).filter(t => t.name.endsWith(" (ref.)")).map(t => t.t));
const [checked, setChecked] = useState(targets ? targets.split(",") : sensors);
@@ -126,6 +127,11 @@ function Settings({ d, families, setFamilies, targets, setTargets, detect, focus
Diagnostic settings
+
+ Detectors
+
+
setFocus(e.currentTarget.checked)} />
new RegExp(`(^|[^\\w])${s.replace(/[^\w]/g, "\\$&"
const sensorsOf = (l, names) => l.sensors ?? names.filter(s => mentions(l.description, s));
// analysis, support: the folder of the analysis, of the support request shown, held by App (the sidebar opens one)
-function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, cut, analysis, setAnalysis,
+function Curves({ selection: { station, start, end }, d, setImage, source, setSource, families, targets, focus, hidden, cut, set, analysis, setAnalysis,
support, setSupport }) {
const { A, B, T, plots: PLOTS } = d;
const plotIndex = (title, otherwise) => { const i = PLOTS.findIndex(p => p.title === title); return i < 0 ? otherwise : i; };
@@ -355,14 +361,14 @@ function Curves({ selection: { station, start, end }, d, setImage, source, setSo
useEffect(() => {
let alive = true;
setReading(true);
- const url = source === "detectors" ? `/api/detectors?${new URLSearchParams({ station, start, end, targets })}`
+ const url = source === "detectors" ? `/api/detectors?${new URLSearchParams({ station, start, end, targets, set })}`
: `/api/labels?${new URLSearchParams({ station, folder })}`;
call(url).then(l => {
if (!alive) return; // another source was chosen in the meantime
setReading(false); setAllLabels(l || []);
});
return () => { alive = false; };
- }, [source, targets, rev]);
+ }, [source, targets, set, rev]);
// One more plot: the first one the page does not show yet, vertical displacement first
function addPlot() {