diff --git a/plotting.py b/plotting.py index aed3045..7829b11 100644 --- a/plotting.py +++ b/plotting.py @@ -319,7 +319,9 @@ if __name__ == "__main__": files_to_process = sorted(cutleft_dir.glob("*.jpg")) try: - all_labels = list(filter(None, (base_dir / "labels").read_text().splitlines())) + all_labels = sorted(list(filter(None, + (base_dir / "labels").read_text().splitlines())), + key = natural_key) except FileNotFoundError: all_labels = [] diff --git a/reading_annotations.py b/reading_annotations.py index e9c55de..1f81259 100644 --- a/reading_annotations.py +++ b/reading_annotations.py @@ -158,7 +158,7 @@ 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): +def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_layer, all_labels): """ Modifies data based on actions, reads bnote.json, cuts notes, regenerates all label images for consistency, saves dirty ones, @@ -221,7 +221,7 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye # --- 2. Process Images (Cut notes, Regenerate, Concatenate) --- concat_list = [] - d_notes = {} + d_notes = dict.fromkeys(all_labels, "") # Iterate over images defined in bnote.json to maintain order/geometry for img_info in bnote_data.get("images", []): @@ -289,6 +289,14 @@ if __name__ == "__main__": root_dir = sys.argv[1] + try: + all_labels = sorted(list(filter(None, + (Path(root_dir) / "labels") + .read_text().splitlines())), + key = natural_key) + except FileNotFoundError: + all_labels = [] + # Load original data original_data = annotating.make_dictionary(root_dir) @@ -299,6 +307,6 @@ if __name__ == "__main__": print(f"Processing annotations for: {student_id}") actions, notes = detect_checks_and_notes(bnot_dir) if actions or notes: - apply_actions_and_regenerate(root_dir, original_data, student_id, actions, notes) + apply_actions_and_regenerate(root_dir, original_data, student_id, actions, notes, all_labels) else: print(" No changes detected or missing files.") diff --git a/update_ods.py b/update_ods.py index 63b0b27..31ad650 100644 --- a/update_ods.py +++ b/update_ods.py @@ -15,7 +15,10 @@ def main(): else: work_dir = os.path.abspath(sys.argv[1]) - all_labels = [l for l in (Path(work_dir) / "labels").read_text().split("\n") if l!=""] + all_labels = sorted(list(filter(None, + (Path(work_dir) / "labels") + .read_text().splitlines())), + key = natural_key) a_rendre_path = os.path.join(work_dir, TARGET_DIR_NAME) if not os.path.isdir(a_rendre_path):