Bnot : split large copies into pieces.
This commit is contained in:
1 parent
834ffe32f2
commit
1959c5d3bb
10 files changed
+333
-52
No files matched your search
@@ -22,6 +22,7 @@ from copienator import (
|
||||
)
|
||||
from copienator.annotation_actions import apply_checkbox_actions, apply_score_overrides
|
||||
from copienator.annotation_data import AnnotationData, load_annotation_data
|
||||
from copienator.annotation_documents import copy_documents
|
||||
from copienator.annotation_layout import legacy_layout
|
||||
from copienator.annotation_modifications import (
|
||||
BASELINE,
|
||||
@@ -154,6 +155,7 @@ def apply_actions_and_regenerate(
|
||||
all_labels: list[str],
|
||||
*,
|
||||
update_score: bool = False,
|
||||
label_notes: dict[str, Image.Image] | None = None,
|
||||
) -> ExitCode:
|
||||
"""Apply annotations and atomically merge the regenerated student files."""
|
||||
output_dir = workspace.annotation_dir("checks") / f"Copie{student_id}"
|
||||
@@ -205,7 +207,7 @@ def apply_actions_and_regenerate(
|
||||
scores[label] = str(result.get("score", 0))
|
||||
is_empty = result.get("error") == "empty-answer"
|
||||
|
||||
sub_note = None
|
||||
sub_note = label_notes.get(label) if label_notes is not None else None
|
||||
if notes_layer is not None and "hmin" in image_info:
|
||||
hmin = int(image_info.get("hmin", 0))
|
||||
hmax = int(image_info.get("hmax", 0))
|
||||
@@ -325,11 +327,33 @@ def run(
|
||||
status = ExitCode.PARTIAL
|
||||
continue
|
||||
print(f"Processing annotations for: {student_id}")
|
||||
actions, notes = ([], None) if only_empty else detect_checks_and_notes(output_dir)
|
||||
if notes is None and not actions and not update_score and not only_empty:
|
||||
documents = copy_documents(output_dir)
|
||||
label_notes = None
|
||||
actions, notes = [], None
|
||||
if not only_empty and documents == [output_dir]:
|
||||
actions, notes = detect_checks_and_notes(output_dir)
|
||||
elif not only_empty:
|
||||
label_notes = {}
|
||||
incomplete = False
|
||||
for document in documents:
|
||||
part_actions, part_notes = detect_checks_and_notes(document)
|
||||
if part_notes is None:
|
||||
incomplete = True
|
||||
continue
|
||||
actions.extend(part_actions)
|
||||
for item in read_json(document / "bnote.json")["images"]:
|
||||
label_notes[item["label"]] = part_notes.crop(
|
||||
(0, item["hmin"], part_notes.width, item["hmax"])
|
||||
)
|
||||
if incomplete:
|
||||
print(" Missing a readable annotation part; copy was preserved.")
|
||||
status = ExitCode.PARTIAL
|
||||
continue
|
||||
if notes is None and not label_notes and not actions and not update_score and not only_empty:
|
||||
print(" No readable annotation input found.")
|
||||
status = ExitCode.PARTIAL
|
||||
continue
|
||||
extra = {"label_notes": label_notes} if label_notes is not None else {}
|
||||
result = apply_actions_and_regenerate(
|
||||
workspace,
|
||||
loaded.data,
|
||||
@@ -338,6 +362,7 @@ def run(
|
||||
notes,
|
||||
all_labels,
|
||||
update_score=update_score,
|
||||
**extra,
|
||||
)
|
||||
if result != ExitCode.SUCCESS:
|
||||
status = ExitCode.PARTIAL
|
||||
|
||||
Reference in new issue
Block a user