Configuration de l'output final

This commit is contained in:
2026-09-12 23:56:07 +02:00
parent 060859ddef
commit e8b8a11c5b
16 changed files with 814 additions and 38 deletions
+13 -6
View File
@@ -21,6 +21,7 @@ from copienator import (
workspace_from_args,
)
from copienator.annotation_actions import apply_checkbox_actions, apply_score_overrides
from copienator.answer_info import build_answer_info
from copienator.annotation_data import AnnotationData, load_annotation_data
from copienator.filesystem import staged_files
@@ -148,11 +149,12 @@ def apply_actions_and_regenerate(
raise TypeError(f"Expected a JSON object in {bnote_path}")
labels_data = data[student_id]
dirty_labels = apply_checkbox_actions(labels_data, actions, print)
apply_checkbox_actions(labels_data, actions, print)
if update_score:
dirty_labels |= apply_score_overrides(labels_data, output_dir / "score.json", print)
apply_score_overrides(labels_data, output_dir / "score.json", print)
scores = dict.fromkeys(all_labels, "")
answer_labels: list[str] = []
dirty_images: dict[str, Image.Image] = {}
concatenated: list[Image.Image] = []
filtered: list[Image.Image] = []
@@ -169,6 +171,8 @@ def apply_actions_and_regenerate(
content = labels_data[label]
result = content["result"]
scores[label] = str(result.get("score", 0))
if result.get("error") == "empty-answer":
continue
sub_note = None
if notes_layer is not None:
@@ -204,18 +208,22 @@ def apply_actions_and_regenerate(
body = sub_note.crop((0, old_header_height, width, height))
final_image.paste(body, (0, new_header_height), mask=body)
if label in dirty_labels or has_notes:
dirty_images[label] = final_image
dirty_images[label] = final_image
answer_labels.append(label)
concatenated.append(final_image)
if float(scores[label]) != 4.0 or result.get("feedback", []):
filtered.append(final_image)
concat_image = concatenate(concatenated)
filtered_image = concatenate(filtered)
with staged_files(output_dir) as staging:
with staged_files(output_dir, remove=("Concat.jpg", "Concat_F.jpg", "Concat_F.pdf",
"touched.json", "answer_labels.json")) as staging:
for label, image in dirty_images.items():
image.save(staging / f"{label}.jpg")
atomic_write_json(staging / "score.json", scores)
atomic_write_json(staging / "info.json", build_answer_info(
scores, labels_data, answer_labels
))
if concat_image is not None:
concat_image.save(staging / "Concat.jpg")
if filtered_image is not None:
@@ -284,4 +292,3 @@ def main(argv: Sequence[str] | None = None) -> int:
if __name__ == "__main__":
raise SystemExit(main())