Using folders "Copies" and "Par label", hopefully

This commit is contained in:
2026-05-17 11:25:36 +02:00
parent 7e7045293a
commit c6c1a052e1
12 changed files with 142 additions and 95 deletions
+9 -10
View File
@@ -37,7 +37,7 @@ def make_dictionary(root_dir, refaire=False, refaire_list=[]):
# Find coordinates
coordinates = None
height,width= None, None
label_dir = os.path.join(root_dir, label)
label_dir = Path(root_dir) / "Par label" / label
# Search all json files in Dir/label
json_files = glob.glob(os.path.join(label_dir, "*.json"))
@@ -59,7 +59,7 @@ def make_dictionary(root_dir, refaire=False, refaire_list=[]):
break
# Construct PDF path: Dir/Copie{id}/{label}.pdf
pdf_path = os.path.join(root_dir, f"Copie{student_id}", f"{label}.pdf")
pdf_path = Path(root_dir) / "Copies" / f"Copie{student_id}" / f"{label}.pdf"
# Initialize dictionary structure for this ID if missing
if student_id not in result_data:
@@ -89,8 +89,7 @@ def make_dictionary(root_dir, refaire=False, refaire_list=[]):
# On ajoute des dummies
if labels_to_redo: # Si la liste est non vide
for lbl in labels_to_redo:
pdf_path = os.path.join(root_dir,
f"Copie{sid}", f"{lbl}.pdf")
pdf_path = Path(root_dir) / "Copies" / f"Copie{sid}" / f"{lbl}.pdf"
if not Path(pdf_path).exists():
print("Debug : asked to refaire", sid, lbl, "but pdf absent")
continue
@@ -107,8 +106,7 @@ def make_dictionary(root_dir, refaire=False, refaire_list=[]):
else: # Ce student id n'a jamais été corrigé
result_data[sid] = {}
for lbl in labels_to_redo:
pdf_path = os.path.join(root_dir,
f"Copie{sid}", f"{lbl}.pdf")
pdf_path = Path(root_dir) / "Copies" / f"Copie{sid}" / f"{lbl}.pdf"
if not pdf_path.exists():
print("Debug : asked to refaire", sid, lbl, "but pdf absent")
continue
@@ -567,13 +565,13 @@ def process_student(student_id, labels_data, root_dir, all_labels, overwrite):
d_notes = dict.fromkeys(all_labels, "")
label_images = []
# !! Trier par l'ordre des labels plutôt
sorted_labels = sorted(list(labels_data.items()), key=natural_key)
for label, content in sorted_labels:
# 1. Find PDF path
copie_folder = f"Copie{student_id}"
pdf_rel_path = os.path.join(copie_folder, f"{label}.pdf")
pdf_full_path = os.path.join(root_dir, pdf_rel_path)
pdf_full_path = Path(root_dir) / "Copies" / copie_folder / f"{label}.pdf"
if not os.path.exists(pdf_full_path):
print(f"File not found: {pdf_full_path}")
@@ -629,13 +627,14 @@ def process_correction(root_dir, data, all_labels, overwrite=False):
# # Wait for all threads to complete
# concurrent.futures.wait(futures)
# Ne pas thread cette applications
# Ne pas thread cette application
# 1. Il faut protéger les appels à matplotlib
# 2. tu vas perdre les erreurs
for student_id, labels in sorted(data.items()):
process_student(student_id, labels, root_dir, all_labels, overwrite)
import argparse
import utils
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Annotate copies")
@@ -644,7 +643,7 @@ if __name__ == "__main__":
args = parser.parse_args()
root_dir = args.root_dir
labels = list(filter(None, (Path(root_dir) / "labels").read_text().splitlines()))
labels = utils.read_all_labels(root_dir)
results = make_dictionary(root_dir)
# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates}
# Coordinates are the real coordinates (hmin, hmax) of the image in the Group