original-label-> information

This commit is contained in:
sebastien committed 2026-09-22 12:20:23 +02:00
1 parent 5009831c7c
commit 96c00fa941
5 files changed
+81

No files matched your search

+6
View File
@@ -10,6 +10,7 @@ from PIL import Image
from .json_io import read_json
from .feedback_boxes import valid_feedback_box
from .workspace import EvaluationWorkspace
from .answer_origins import origins_for
AnnotationData = dict[str, dict[str, dict[str, Any]]]
RefaireList = list[list[Any]]
@@ -208,4 +209,9 @@ def load_annotation_data(
data = {copy_id: data[copy_id]} if copy_id in data else {}
if not data:
warnings.append(f"Copy id {copy_id} was not found in correction.json")
for student_id, answers in data.items():
for label, answer in answers.items():
answer["result"]["content_origins"] = origins_for(
workspace.root, student_id, label, answer["pdf_path"]
)
return AnnotationLoadResult(data, warnings)
+4
View File
@@ -324,6 +324,10 @@ def compose_label_image(base_img, label, result, hmin,
if error == "empty-answer" and not with_empty:
return None, 0
origins = result.get("content_origins", [])
if origins:
error = " ".join([error, *(f"{origin}->" for origin in origins)]).strip()
# Filter deleted items (used by reading_annotations.py)
feedbacks = [f for f in feedbacks if "to_delete" not in f]
+3
View File
@@ -18,6 +18,7 @@ from google import genai
from copienator import configuration as config
from copienator.commands import grouping
from copienator.answer_origins import save_origins
from copienator import prompting
from copienator.feedback_boxes import valid_feedback_box
from copienator import (
@@ -435,6 +436,7 @@ def handle_label_errors(pid, label, res, pdf_path):
if not base_add_pdf_path.exists() and not add_pdf_path.exists():
shutil.copy(str(pdf_path), str(add_pdf_path))
save_origins(INPUT_DIR, pid, add_label, add_pdf_path, [label])
tprint(f"\t\tCopying Copie{pid} : {label} -> {add_label}")
idx = reserve_next_group_idx(add_label)
tprint(f"\t\tMaking {add_label} group {idx+1}")
@@ -704,6 +706,7 @@ def resolve_delayed_moves():
resolved_any = True
shutil.copy(str(pdf_path), str(add_pdf_path))
save_origins(INPUT_DIR, pid, target_label, add_pdf_path, [label])
idx = reserve_next_group_idx(target_label)
height = grouping.get_pdf_height(str(add_pdf_path))
grouping.create_jpg(target_label, idx, [(pid, str(add_pdf_path), height)], GROUPS_DIR)
+16
View File
@@ -10,6 +10,7 @@ from typing import Any
from pypdf import PdfWriter
from copienator.pdf_cut import split_pdf
from copienator.answer_origins import origins_for, save_origins
from copienator import (
CliError,
@@ -204,6 +205,8 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
_validate_pdf_inputs(instructions, initial_paths)
files_to_old: set[Path] = set()
origins = {key: origins_for(workspace.root, *key, path)
for key, path in initial_paths.items()}
temp_files: list[Path] = []
try:
for instruction in instructions:
@@ -212,6 +215,8 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
source = initial_paths[key_old]
destination = current_paths[key_new]
if instruction.cut:
origins[key_old] = []
origins[key_new] = []
percent, keep = instruction.cut
first = source.parent / f"temp_{len(temp_files)}.pdf"
second = source.parent / f"temp_{len(temp_files) + 1}.pdf"
@@ -232,6 +237,9 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
files_to_old.add(initial_paths[key_new])
if instruction.should_merge:
if not instruction.cut and instruction.operator == "->":
origins[key_new] = list(dict.fromkeys([
*origins[key_new], instruction.old_label]))
writer = PdfWriter()
try:
if instruction.pipe_first:
@@ -252,6 +260,10 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
temp_files.append(temp_output)
files_to_old.add(initial_paths[key_new])
elif instruction.should_copy:
origins[key_new] = (
[instruction.old_label] if instruction.operator == "-x"
and not instruction.cut else []
)
shutil.copy(source, temp_output)
current_paths[key_new] = temp_output
temp_files.append(temp_output)
@@ -287,6 +299,10 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
final_name = workspace.copies_dir / f"Copie{copy_id}" / f"{label}_new.pdf"
final_name.unlink(missing_ok=True)
shutil.move(str(current_path), str(final_name))
retained_origins = [origin for origin in origins[(copy_id, label)]
if (copy_id, origin) not in initial_paths
or initial_paths[(copy_id, origin)] not in files_to_old]
save_origins(workspace.root, copy_id, label, final_name, retained_origins)
set_suffix_and_clean_error(results, copy_id, label, "_new")
labels = refaire_by_copy.setdefault(f"Copie{copy_id}", [])
if label not in labels: