wf-improve scripts take their paths as arguments (--labels, --data)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-13 12:38:29 +01:00
1 parent 80e00a4898
commit cff2b0ad1e
3 files changed
+40 -42

No files matched your search

+17 -17
View File
@@ -1,15 +1,14 @@
"""Benchmark of the wf-improve workflow (D-116): the detectors against all the labeller's labels (labeling/auto/).
"""Benchmark of the detectors against a reference truth: every labelled station.
For each station of labeling/auto/ that has its folder in data/, the score per family and per instant of score.py
(D-112), over the range of its labels: from the day of the first to the midnight after the last. Then the total, family
by family, which says whether the detectors do better overall from one session to the next. The block of the session's
station is its score; the other blocks, the non-regression: a family that goes back on a station is a regression, even
if the total rises.
Usage: python3 detectors/skills/wf-improve/scripts/regression.py [--stations A,B]
For each <STATION>.jsonl of --labels that has its folder <STATION>/ in --data, the score per family and per instant of
score.py, over the range of its labels: from the day of the first to the midnight after the last. Then the total,
family by family, which says whether the detectors do better overall. The block of a station is its score; the
others, the non-regression: a family that goes back on a station is a regression, even if the total rises.
Usage: python3 regression.py --labels <folder of <STATION>.jsonl> --data <folder of <STATION>/> [--stations A,B]
"""
import argparse
import json
from datetime import timedelta
from pathlib import Path
import score # next to it
@@ -17,31 +16,32 @@ from data import iso, parse_time # on the path through score
def label_range(path):
"""labeling/auto/<STATION>.jsonl -> (start, end) iso, in whole UTC days, end excluded."""
with open(path, encoding="utf-8") as f:
labels = [json.loads(l) for l in f if l.strip()]
"""Labels JSONL -> (start, end) iso, in whole UTC days, end excluded."""
labels = score.read_labels(path)
start = min(e["debut"] for e in labels)[:10]
# ponytail: the end of the batch is not written; midnight closest to the last bound (a label bound overflows by one
# measurement after midnight); the real end of the batch in labeling/auto/ if the gap matters
# ponytail: the end of the labelled batch is not written; midnight closest to the last bound (a label bound
# overflows by one measurement after midnight)
end = iso(parse_time(max(e["fin"] for e in labels)) + timedelta(hours=12))[:10]
return iso(parse_time(start)), iso(parse_time(end))
if __name__ == "__main__":
p = argparse.ArgumentParser(usage=__doc__)
p.add_argument("--labels", required=True, help="folder of the labels, one <STATION>.jsonl per station")
p.add_argument("--data", required=True, help="folder of the station folders, <STATION>/")
p.add_argument("--stations", help="A,B: these stations only (a shorter run)")
a = p.parse_args()
total = {}
for path in sorted((score.WORK / "labeling" / "auto").glob("*.jsonl")):
for path in sorted(Path(a.labels).glob("*.jsonl")):
station = path.stem
if a.stations and station not in a.stations.split(","):
continue
folder = score.WORK / "data" / station
folder = Path(a.data) / station
if not folder.is_dir():
print(f"{station}: no data/{station}/, skipped\n")
print(f"{station}: no {folder}/, skipped\n")
continue
start, end = label_range(path)
n, labels = score.family_scores(str(folder), start, end)
n, labels = score.family_scores(str(folder), str(path), start, end)
score.show(f"{station}: {start} → {end}, {len(labels)} labels", n)
print()
for k, v in n.items():