Validate labels: the user agrees with all the labels of a finished analysis, each gets review (the date)
A change of the labels afterwards (an edit in the page, the analyst after a message) removes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a733575d65
commit
b31371a241
4 files changed
+72
-4
No files matched your search
+25
-2
@@ -4,7 +4,8 @@ by `claude -p`, non-interactive, on a range chosen in the page, with the user's
|
||||
labeling/auto/analyses/<STATION>_<start>_<end>/ its labels (labels.jsonl) and a diagnostic report (report.md, its figures
|
||||
next to it); at the end, the server submits its labels to labeling/auto/<STATION>.jsonl, marked with their analysis (field
|
||||
`analysis`). Then the user can write to it: the same session resumes (`claude -p --resume`), and its labels, if they
|
||||
change, replace those it had submitted.
|
||||
change, replace those it had submitted. "Validate labels": the user agrees with all the labels of the analysis, each gets
|
||||
`review`, the date (labeling/README.md); labels the analyst changes afterwards are submitted again without it.
|
||||
On a finished analysis, "Optimize" launches `/optimize` in Optimizer (optimizer/, the skill that, from the analysis, improves
|
||||
the detectors on its range, its labels as truth, then brings the analyst's scripts into the reading tools, tools/); one
|
||||
optimization at a time, no analysis or message meanwhile; the summary of the session
|
||||
@@ -186,11 +187,33 @@ def state(name):
|
||||
analyses[name] = {"state": "done" if (out / "report.md").exists() else "interrupted", "lines": lines,
|
||||
"submitted": None, "station": request["station"], "request": request}
|
||||
a, r = analyses[name], out / "report.md"
|
||||
return {"name": name, "state": a["state"], "lines": a["lines"], "submitted": a["submitted"],
|
||||
labels = [e for e in station.read(a["station"], "auto") if e.get("analysis") == name]
|
||||
validated = max(e["review"] for e in labels) if labels and all(e.get("review") for e in labels) else None
|
||||
return {"name": name, "state": a["state"], "lines": a["lines"], "submitted": a["submitted"], "validated": validated,
|
||||
"report": int(r.stat().st_mtime) if r.exists() else None,
|
||||
"dialogue": (out / "work" / "session").exists(), "request": a["request"], "optimization": optimization(name)}
|
||||
|
||||
|
||||
def validate(name):
|
||||
"""The "Validate labels" button: the user agrees with all the labels of the finished analysis -> their number."""
|
||||
a = state(name)
|
||||
if a["state"] != "done":
|
||||
raise station.Refusal("only a finished analysis can be validated")
|
||||
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
with lock:
|
||||
f = station.label_file(a["request"]["station"], "auto") # the other lines stay as they are
|
||||
lines, n = f.read_text(encoding="utf-8").split("\n") if f.exists() else [], 0
|
||||
for i, l in enumerate(lines):
|
||||
if l.strip() and (e := json.loads(l)).get("analysis") == name:
|
||||
lines[i], n = json.dumps(e | {"review": today}, ensure_ascii=False), n + 1
|
||||
if not n:
|
||||
raise station.Refusal(f"no label of this analysis in labeling/auto/{f.name}")
|
||||
temp = f.with_name(f.name + ".tmp")
|
||||
temp.write_text("\n".join(lines), encoding="utf-8")
|
||||
os.replace(temp, f)
|
||||
return {"validated": n}
|
||||
|
||||
|
||||
def list_analyses():
|
||||
"""The history of the analyses (the sidebar), the most recent first: those of the server with their state, the others
|
||||
read on disk (done with a report, otherwise interrupted: an analysis stops with the server)."""
|
||||
|
||||
+35
-1
@@ -260,7 +260,41 @@ def check_analysis():
|
||||
analysis.analyses.clear()
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis]
|
||||
def check_validation():
|
||||
# "Validate labels" (analysis.validate): review on all the labels of the analysis, the others untouched; an edit in
|
||||
# the page removes it from one label, and the analysis is no longer validated
|
||||
import analysis
|
||||
before = station.LABELS, analysis.FOLDER
|
||||
station.LABELS = temp_folder()
|
||||
analysis.FOLDER = station.LABELS / "auto" / "analyses"
|
||||
try:
|
||||
for name, report in (("NORDEND_a", True), ("NORDEND_b", False)):
|
||||
(analysis.FOLDER / name).mkdir(parents=True)
|
||||
(analysis.FOLDER / name / "request.json").write_text(json.dumps({"station": "NORDEND"}))
|
||||
if report:
|
||||
(analysis.FOLDER / name / "report.md").write_text("# report")
|
||||
mine = [{"id": f"NORDEND-{i}", "start": "2026-11-05T06:00Z", "end": "2026-11-05T07:00Z", "family": "Visibility",
|
||||
"description": f"fog {i}", "analysis": "NORDEND_a"} for i in (1, 2)]
|
||||
other = {"id": "NORDEND-3", "start": "2026-11-05T06:00Z", "end": "2026-11-05T07:00Z", "family": "Visibility",
|
||||
"description": "rain"}
|
||||
(station.LABELS / "auto" / "NORDEND.jsonl").write_text("".join(json.dumps(e) + "\n" for e in mine + [other]))
|
||||
assert analysis.state("NORDEND_a")["validated"] is None
|
||||
assert "finished" in refuses(analysis.validate, "NORDEND_b") # interrupted, no report
|
||||
assert analysis.validate("NORDEND_a") == {"validated": 2}
|
||||
labels = station.read("NORDEND", "auto")
|
||||
assert [bool(e.get("review")) for e in labels] == [True, True, False], labels
|
||||
assert analysis.state("NORDEND_a")["validated"] == labels[0]["review"]
|
||||
station.update({"station": "NORDEND", "before": labels[0], "family": "Visibility", "description": "fog again"})
|
||||
assert analysis.state("NORDEND_a")["validated"] is None
|
||||
(station.LABELS / "auto" / "NORDEND.jsonl").write_text(json.dumps(other) + "\n")
|
||||
assert "no label" in refuses(analysis.validate, "NORDEND_a")
|
||||
finally:
|
||||
shutil.rmtree(station.LABELS)
|
||||
station.LABELS, analysis.FOLDER = before
|
||||
analysis.analyses.clear()
|
||||
|
||||
|
||||
CHECKS = [check_server, check_station, check_optimization, check_analysis, check_validation]
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
|
||||
@@ -147,6 +147,11 @@ def analysis_report(name: str, dark: bool = False):
|
||||
return HTMLResponse(analysis.report(name, dark))
|
||||
|
||||
|
||||
@app.post("/api/analyses/{name}/validate")
|
||||
def validate_analysis(name: str):
|
||||
return analysis.validate(name)
|
||||
|
||||
|
||||
@app.post("/api/analyses/{name}/optimize")
|
||||
def optimize_analysis(name: str):
|
||||
return analysis.optimize(name)
|
||||
|
||||
@@ -539,6 +539,9 @@ function Analysis({ name, dark, done, close }) {
|
||||
async function optimize() {
|
||||
if (await call(`/api/analyses/${name}/optimize`, "POST") != null) setTurn(t => t + 1);
|
||||
}
|
||||
async function validate() {
|
||||
if (await call(`/api/analyses/${name}/validate`, "POST") != null) { setTurn(t => t + 1); done(); }
|
||||
}
|
||||
if (!a) return <Loader size="sm" />;
|
||||
const d = a.request, o = a.optimization, busy = a.state === "running", optimizing = o?.state === "running";
|
||||
const end = new Date(Date.parse(d.end.slice(0, 10)) + 864e5).toISOString().slice(0, 10);
|
||||
@@ -552,6 +555,9 @@ function Analysis({ name, dark, done, close }) {
|
||||
{busy && <Loader size="xs" />}
|
||||
</Group>
|
||||
<Group gap="xs">
|
||||
{a.validated ? <Badge color="green" variant="light">labels validated {a.validated}</Badge>
|
||||
: a.state === "done" && <Tooltip label="I agree with all the labels of this analysis: they become reference labels">
|
||||
<Button size="xs" color="green" variant="light" onClick={validate} disabled={optimizing}>Validate labels</Button></Tooltip>}
|
||||
{a.state === "done" && <Tooltip label="Improve the detectors (Optimizer), then the reading tools (tool-builder), from this analysis">
|
||||
<Button size="xs" variant="light" onClick={optimize} disabled={optimizing}>Optimize the detectors</Button></Tooltip>}
|
||||
<ActionIcon variant="subtle" color="gray" aria-label="Close the report" onClick={close}><IconX size={16} /></ActionIcon>
|
||||
@@ -560,7 +566,7 @@ function Analysis({ name, dark, done, close }) {
|
||||
{d.hints && <Text size="sm" c="dimmed">Hints: {d.hints}</Text>}
|
||||
{a.state === "interrupted" && <Text size="sm" c="orange">Stopped with the server before the end.{a.dialogue
|
||||
? " Its session is kept: write “continue” below to resume it where it left off." : ""}</Text>}
|
||||
{a.submitted !== null && a.state === "done" && <Text size="sm">{a.submitted} label(s) of this analysis in labeling/auto/{d.station}.jsonl, to review.</Text>}
|
||||
{a.submitted !== null && a.state === "done" && <Text size="sm">{a.submitted} label(s) of this analysis in labeling/auto/{d.station}.jsonl{a.validated ? ", validated" : ", to validate"}.</Text>}
|
||||
{a.report && <Page title="Report" src={`/api/analyses/${name}/report.html?dark=${dark}&v=${a.report}`} />}
|
||||
<Thread lines={a.lines} />
|
||||
{a.dialogue && (
|
||||
|
||||
Reference in new issue
Block a user