Detectors of the Data page: a sensitivity setting (1 to 10, 0 = the code's default) passed to categories.window of the manual set
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cccdeae67e
commit
cae07a2787
3 files changed
+35
-18
No files matched your search
@@ -78,8 +78,9 @@ 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 = "", set_: str = Query("classic", alias="set")):
|
||||
return station.detectors(station_, start, end, targets, set_)
|
||||
def detectors(station_: str = Query(alias="station"), start: str = "", end: str = "", targets: str = "", set_: str = Query("classic", alias="set"),
|
||||
sensitivity: int = 0):
|
||||
return station.detectors(station_, start, end, targets, set_, sensitivity)
|
||||
|
||||
|
||||
@app.get("/api/tracked")
|
||||
|
||||
+12
-6
@@ -273,25 +273,31 @@ CHILD = ("import pickle, sys; out, sys.stdout = sys.stdout.buffer, sys.stderr; s
|
||||
"pickle.dump(categories.window(*pickle.load(sys.stdin.buffer)), out)")
|
||||
|
||||
|
||||
def window(set_, every, a, b):
|
||||
"""categories.window of the chosen set."""
|
||||
def window(set_, every, a, b, sensitivity=0):
|
||||
"""categories.window of the chosen set; sensitivity (1 to 10, 0: the default of the code): the manual set only."""
|
||||
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)
|
||||
run = subprocess.run([sys.executable, "-c", CHILD, str(MANUAL)], input=pickle.dumps((every, a, b, sensitivity or None)), 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)
|
||||
|
||||
|
||||
def detectors(station, start, end, targets="", set_="classic", sensitivity=0):
|
||||
"""journal(), from the cache for the classic set; the manual set, being written, computed again at each call."""
|
||||
return (journal.__wrapped__ if set_ == "manual" else journal)(station, start, end, targets, set_, sensitivity)
|
||||
|
||||
|
||||
# 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="", set_="classic"):
|
||||
def journal(station, start, end, targets="", set_="classic", sensitivity=0):
|
||||
"""-> 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. set_: classic (detectors/scripts/) or manual (detectors/manual/)."""
|
||||
removed before the detectors, as if they did not exist. set_: classic (detectors/scripts/) or manual (detectors/manual/);
|
||||
sensitivity: of the manual set, 1 (tolerant) to 10 (severe), 0: the default of the code."""
|
||||
d = folder(station)
|
||||
every = data.load(d)
|
||||
if targets:
|
||||
@@ -305,7 +311,7 @@ def detectors(station, start, end, targets="", set_="classic"):
|
||||
"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(window(set_, every, a, b))]
|
||||
for i, v in enumerate(window(set_, every, a, b, sensitivity))]
|
||||
|
||||
|
||||
# --- the labels
|
||||
|
||||
Reference in new issue
Block a user