diff --git a/Readme.org b/Readme.org index 5f7731e..8bd144a 100644 --- a/Readme.org +++ b/Readme.org @@ -1,7 +1,7 @@ #+title: Script #+author: Sébastien Miquel #+date: 14-03-2026 -# Time-stamp: <02-06-26 09:26> +# Time-stamp: <06-06-26 10:10> #+OPTIONS: * Méta @@ -235,7 +235,7 @@ sous le nom =Concat_annotated.pdf=. OU 2. =python reading_grouped_annotations.py Interro= - Idem, mais pour =BGnot=. + Idem, mais pour =BGnot=. 3. =python giving_names.py Interro BGnot= @@ -245,7 +245,10 @@ OU Si un nom est =Unknown= : renommer à la main le dossier et le fichier dedans. - On peut faire des changements manuels aux =score.json= ici. + 4. On peut faire des changements manuels aux =score.json= ici, puis + - `python reading_annotations.py --update-score Interro` + - `python reading_grouped_annotations.py --update-score Interro` + pour mettre à jour les scores dans les images. 4. (gestion perso) + =gestion_classe ne= pour créer l'interro puis + =gestion_classe we= (set barème here) diff --git a/reading_annotations.py b/reading_annotations.py index a639b09..5b9a20f 100644 --- a/reading_annotations.py +++ b/reading_annotations.py @@ -161,7 +161,8 @@ def has_significant_notes(note_img, threshold=20): # print(f"Debug : visible pixels is {visible_pixels}") return visible_pixels > threshold -def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_layer, all_labels): +def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_layer, + all_labels, update_score=False): """ Modifies data based on actions, reads bnote.json, cuts notes, regenerates all label images for consistency, saves dirty ones, @@ -230,6 +231,23 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye print(f" > Deleted rect in {label}") dirty_labels.add(label) + # --- 1.5 Override with existing score.json if requested --- + if update_score and os.path.exists(score_path): + try: + with open(score_path, "r") as f: + existing_scores = json.load(f) + for label, existing_score in existing_scores.items(): + if label in labels_data: + current_score = str(labels_data[label]['result'].get('score', 0)) + # If manually modified, override the result and mark dirty + if current_score != str(existing_score): + labels_data[label]['result']['score'] = existing_score + dirty_labels.add(label) + print(f" > Overrode score for {label} to {existing_score} from existing score.json") + except json.JSONDecodeError: + print(f" > Warning: Could not read existing {score_path}") + + # --- 2. Process Images (Cut notes, Regenerate, Concatenate) --- concat_list = [] concat_list_F = [] @@ -256,7 +274,7 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye # B. Regenerate Label Image # We always regenerate to ensure Concat.jpg is consistent with any modifications # pdf_path = Path(root_dir) / "Copies" / f"Copie{student_id}" / f"{label}.pdf" - pdf_path = content.get('pdf_path') # Contient le suffixe _new si nécessaire + pdf_path = content.get('pdf_path') # Contient le suffixe _new si nécessaire if not os.path.exists(pdf_path): continue (base_img, _, _) = annotating.make_base_image(pdf_path) @@ -332,11 +350,13 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye from utils import read_all_labels if __name__ == "__main__": - if len(sys.argv) < 2: - print("Usage: python reading_annotations.py