Validation in the analysis: labels.jsonl carries review and says whether the analysis is validated (also in the sidebar list); Validate writes it there then submits; a page edit or removal is mirrored there; a resubmission keeps the ids of unchanged labels
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
effcf8fdcb
commit
ce0200a97a
3 files changed
+94
-42
No files matched your search
+24
-10
@@ -261,32 +261,46 @@ def 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
|
||||
# "Validate labels" (analysis.validate): review on all the labels of the analysis, in its labels.jsonl (which says
|
||||
# whether it is validated) and submitted with their id; the others untouched; an edit in the page removes it from one
|
||||
# label, there too, 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 / "work").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)]
|
||||
mine = [{"start": "2026-11-05T06:00Z", "end": "2026-11-05T07:00Z", "family": "Visibility",
|
||||
"description": f"fog {i}"} 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]))
|
||||
station.write(analysis.FOLDER / "NORDEND_a" / "labels.jsonl", mine)
|
||||
station.write(station.LABELS / "auto" / "NORDEND.jsonl",
|
||||
[{"id": f"NORDEND-{i}"} | e | {"analysis": "NORDEND_a"} for i, e in enumerate(mine, 1)] + [other])
|
||||
analysis.state("NORDEND_a")
|
||||
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}
|
||||
theirs = analysis._labels(analysis.FOLDER / "NORDEND_a")
|
||||
assert all(e.get("review") for e in theirs), theirs
|
||||
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 {e["id"]: bool(e.get("review")) for e in labels} == \
|
||||
{"NORDEND-1": True, "NORDEND-2": True, "NORDEND-3": False}, labels # the ids kept
|
||||
assert analysis.state("NORDEND_a")["validated"] == theirs[0]["review"]
|
||||
assert {a["name"]: a["validated"] for a in analysis.list_analyses()} == \
|
||||
{"NORDEND_a": theirs[0]["review"], "NORDEND_b": None} # the sidebar
|
||||
edited = next(e for e in labels if e["id"] == "NORDEND-1")
|
||||
station.update({"station": "NORDEND", "before": edited, "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 [e["description"] for e in analysis._labels(analysis.FOLDER / "NORDEND_a")] == ["fog again", "fog 2"]
|
||||
assert analysis.validate("NORDEND_a") == {"validated": 2} # validated again, the edit and the ids kept
|
||||
assert sorted((e["id"], e["description"]) for e in station.read("NORDEND", "auto")) == \
|
||||
[("NORDEND-1", "fog again"), ("NORDEND-2", "fog 2"), ("NORDEND-3", "rain")]
|
||||
station.write(analysis.FOLDER / "NORDEND_a" / "labels.jsonl", [])
|
||||
assert "no label" in refuses(analysis.validate, "NORDEND_a")
|
||||
finally:
|
||||
shutil.rmtree(station.LABELS)
|
||||
|
||||
Reference in new issue
Block a user