Refaire support
This commit is contained in:
@@ -57,7 +57,7 @@ def apply_actions_and_regenerate_grouped(root_dir, data, student_id, actions, la
|
||||
fb["norectangle"] = True
|
||||
dirty_labels.add(label)
|
||||
logs.append(f" > Cleared all feedbacks in {label}")
|
||||
|
||||
|
||||
elif act['type'] == 'del_global':
|
||||
if act['index'] < len(global_fb):
|
||||
global_fb[act['index']]["to_delete"] = True
|
||||
@@ -171,13 +171,14 @@ def apply_actions_and_regenerate_grouped(root_dir, data, student_id, actions, la
|
||||
|
||||
return "\n".join(logs)
|
||||
|
||||
|
||||
from utils import read_all_labels
|
||||
import argparse
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python reading_grouped_annotations.py <Dir>")
|
||||
sys.exit(1)
|
||||
parser = argparse.ArgumentParser(description="Read grouped annotations and compile PDFs")
|
||||
parser.add_argument("input_path", help="Directory path")
|
||||
parser.add_argument("--with-refaire", action="store_true", help="Merge refaire annotations from Bnot")
|
||||
args = parser.parse_args()
|
||||
|
||||
root_dir = sys.argv[1]
|
||||
bgnot_dir = os.path.join(root_dir, "BGnot")
|
||||
@@ -197,6 +198,18 @@ if __name__ == "__main__":
|
||||
actions_by_student = collections.defaultdict(list)
|
||||
notes_by_student = collections.defaultdict(dict)
|
||||
|
||||
# --- 0. Read refaire.json if requested ---
|
||||
refaire_dict = {}
|
||||
if args.with_refaire:
|
||||
refaire_path = os.path.join(root_dir, "refaire.json")
|
||||
if os.path.exists(refaire_path):
|
||||
with open(refaire_path, "r", encoding="utf-8") as f:
|
||||
refaire_list = json.load(f)
|
||||
for c_name, labels in refaire_list:
|
||||
sid = c_name.replace("Copie", "")
|
||||
refaire_dict[sid] = labels
|
||||
else:
|
||||
print(f"Warning: --with-refaire flag used, but {refaire_path} not found.")
|
||||
# --- 1. Scan BGnot grouped directories and extract all checks & notes ---
|
||||
for entry in os.listdir(bgnot_dir):
|
||||
gdir = os.path.join(bgnot_dir, entry)
|
||||
@@ -236,6 +249,55 @@ if __name__ == "__main__":
|
||||
'old_header_h': img_info.get("header_height", 0)
|
||||
}
|
||||
|
||||
# --- 1.5. Override BGnot actions with Bnot actions for Refaire targets ---
|
||||
if args.with_refaire and refaire_dict:
|
||||
bnot_dir = os.path.join(root_dir, "Bnot")
|
||||
for sid, r_labels in refaire_dict.items():
|
||||
s_bnot_dir = os.path.join(bnot_dir, f"Copie{sid}")
|
||||
if not os.path.exists(s_bnot_dir):
|
||||
continue
|
||||
|
||||
# If empty list, it targets all labels for this Copie
|
||||
if not r_labels:
|
||||
r_labels = list(original_data.get(sid, {}).keys())
|
||||
|
||||
# Clear out existing BGnot actions & notes for the refaire labels
|
||||
actions_by_student[sid] = [
|
||||
a for a in actions_by_student[sid] if a.get('label') not in r_labels
|
||||
]
|
||||
for lbl in r_labels:
|
||||
notes_by_student[sid].pop(lbl, None)
|
||||
|
||||
print(f"\nScanning refaire annotations in Bnot for Copie{sid}")
|
||||
b_actions, b_notes_img = detect_checks_and_notes(s_bnot_dir)
|
||||
|
||||
b_bnote_path = os.path.join(s_bnot_dir, "bnote.json")
|
||||
if os.path.exists(b_bnote_path):
|
||||
with open(b_bnote_path, "r") as f:
|
||||
b_bnote_data = json.load(f)
|
||||
|
||||
# Inject actions
|
||||
for act in b_actions:
|
||||
# Bnot checkboxes don't natively have student_id, so we inject it
|
||||
act["student_id"] = sid
|
||||
actions_by_student[sid].append(act)
|
||||
|
||||
# Inject notes
|
||||
if b_notes_img is not None:
|
||||
for img_info in b_bnote_data.get("images", []):
|
||||
lbl = img_info.get("label")
|
||||
hmin = img_info.get("hmin", 0)
|
||||
hmax = img_info.get("hmax", 0)
|
||||
|
||||
if hmax > hmin:
|
||||
crop = b_notes_img.crop((0, hmin, b_notes_img.width, hmax))
|
||||
if has_significant_notes(crop):
|
||||
notes_by_student[sid][lbl] = {
|
||||
'img': crop,
|
||||
'old_header_h': img_info.get("header_height", 0)
|
||||
}
|
||||
|
||||
|
||||
def process_student(sid):
|
||||
if sid not in original_data:
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user