Miscs
parent
133be2a84b
commit
92d23a82ad
|
|
@ -13,7 +13,7 @@ import annotating_with_checks
|
||||||
from utils import natural_key
|
from utils import natural_key
|
||||||
|
|
||||||
# Roughly 10 A4 pages at 100 DPI
|
# Roughly 10 A4 pages at 100 DPI
|
||||||
MAX_HEIGHT_PX = 18500 # Can be increased by 10%.
|
MAX_HEIGHT_PX = 20000 # Can be increased by 10%.
|
||||||
|
|
||||||
def render_item(item):
|
def render_item(item):
|
||||||
student_id, label, content = item
|
student_id, label, content = item
|
||||||
|
|
|
||||||
|
|
@ -472,13 +472,15 @@ Here is a list of all possible lables. You need to answer with one of these :
|
||||||
tprint(f"\t\tCopie{pid} tried to move wrong {label} to {new_label}, but it already exists.")
|
tprint(f"\t\tCopie{pid} tried to move wrong {label} to {new_label}, but it already exists.")
|
||||||
res["error"] = f"wrg-lbl:{new_label}?exists"
|
res["error"] = f"wrg-lbl:{new_label}?exists"
|
||||||
else:
|
else:
|
||||||
|
res["error"] = f"wrg-lbl-moved-to:{new_label}"
|
||||||
tprint(f"\t\tCopie{pid} : moving wrong {label} to {new_label}.")
|
tprint(f"\t\tCopie{pid} : moving wrong {label} to {new_label}.")
|
||||||
shutil.move(str(pdf_path), str(new_pdf_path))
|
shutil.move(str(pdf_path), str(new_pdf_path))
|
||||||
# Since we moved the file, this Copie/label should not be taken
|
# Since we moved the file, this Copie/label should not be taken
|
||||||
# into account in the future, I think
|
# into account in the future, I think
|
||||||
idx = get_next_group_idx(INPUT_DIR, new_label)
|
idx = get_next_group_idx(INPUT_DIR, new_label)
|
||||||
height = grouping.get_pdf_height(str(new_pdf_path))
|
height = grouping.get_pdf_height(str(new_pdf_path))
|
||||||
grouping.create_jpg(new_label, idx, [(pid, str(new_pdf_path), height)], INPUT_DIR)
|
grouping.create_jpg(new_label, idx, [(pid, str(new_pdf_path), height)],
|
||||||
|
INPUT_DIR)
|
||||||
tprint(f"\t\tMaking {new_label} group {idx+1}")
|
tprint(f"\t\tMaking {new_label} group {idx+1}")
|
||||||
new_tasks.append((str(Path(INPUT_DIR) / new_label / f"Group_{idx+1}.jpg"),
|
new_tasks.append((str(Path(INPUT_DIR) / new_label / f"Group_{idx+1}.jpg"),
|
||||||
new_label, False))
|
new_label, False))
|
||||||
|
|
@ -532,9 +534,11 @@ Here is a list of all possible labels. You need to answer with a list one of the
|
||||||
grouping.create_jpg(add_label, idx, [(pid, str(new_pdf_path), height)], INPUT_DIR)
|
grouping.create_jpg(add_label, idx, [(pid, str(new_pdf_path), height)], INPUT_DIR)
|
||||||
new_tasks.append((str(Path(INPUT_DIR) / add_label / f"Group_{idx+1}.jpg"),
|
new_tasks.append((str(Path(INPUT_DIR) / add_label / f"Group_{idx+1}.jpg"),
|
||||||
add_label, False))
|
add_label, False))
|
||||||
|
error += f"(->){add_label}"
|
||||||
|
keep_error = True
|
||||||
else:
|
else:
|
||||||
keep_error = True
|
keep_error = True
|
||||||
error += f"{add_label}"
|
error += f"(xx){add_label}"
|
||||||
tprint(f"\t\tAlready present (not copied) Copie{pid} : {label} -> {add_label}")
|
tprint(f"\t\tAlready present (not copied) Copie{pid} : {label} -> {add_label}")
|
||||||
|
|
||||||
if not keep_error:
|
if not keep_error:
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,30 @@ def main():
|
||||||
work_dir = os.path.abspath(sys.argv[1])
|
work_dir = os.path.abspath(sys.argv[1])
|
||||||
bnot_dir = sys.argv[2]
|
bnot_dir = sys.argv[2]
|
||||||
target_subdir = os.path.join(work_dir, "A Rendre")
|
target_subdir = os.path.join(work_dir, "A Rendre")
|
||||||
|
|
||||||
os.makedirs(target_subdir, exist_ok=True)
|
os.makedirs(target_subdir, exist_ok=True)
|
||||||
|
|
||||||
|
# --- 1. Load the expected names list ---
|
||||||
|
expected_names = set()
|
||||||
|
names_path = os.path.join(work_dir, "names")
|
||||||
|
if not os.path.exists(names_path):
|
||||||
|
names_path = "names" # Fallback to current dir
|
||||||
|
|
||||||
|
if os.path.exists(names_path):
|
||||||
|
with open(names_path, 'r', encoding='utf-8') as f:
|
||||||
|
expected_names = {line.strip() for line in f if line.strip()}
|
||||||
|
else:
|
||||||
|
print(f"Warning: 'names' file not found in {work_dir} or current directory.")
|
||||||
|
|
||||||
|
# --- 2. Existing Collection Logic ---
|
||||||
pattern = re.compile(r"^Copie(\d+)\.json$")
|
pattern = re.compile(r"^Copie(\d+)\.json$")
|
||||||
copies_map = defaultdict(list)
|
copies_map = defaultdict(list)
|
||||||
|
assigned_names = set() # To track which names were successfully linked
|
||||||
|
|
||||||
# 1. Collect all data
|
|
||||||
for filename in os.listdir(work_dir):
|
for filename in os.listdir(work_dir):
|
||||||
match = pattern.match(filename)
|
match = pattern.match(filename)
|
||||||
if match:
|
if match:
|
||||||
copie_id = match.group(1)
|
copie_id = match.group(1)
|
||||||
json_path = os.path.join(work_dir, filename)
|
json_path = os.path.join(work_dir, filename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(json_path, 'r', encoding='utf-8') as f:
|
with open(json_path, 'r', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
@ -33,7 +44,7 @@ def main():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing {filename}: {e}")
|
print(f"Error processing {filename}: {e}")
|
||||||
|
|
||||||
# 2. Check constraints and symlink files
|
# --- 3. Process and Link ---
|
||||||
for name, ids in copies_map.items():
|
for name, ids in copies_map.items():
|
||||||
if name == "Unknown":
|
if name == "Unknown":
|
||||||
print(f"ALERT: 'Unknown' name found for IDs: {', '.join(ids)}")
|
print(f"ALERT: 'Unknown' name found for IDs: {', '.join(ids)}")
|
||||||
|
|
@ -46,50 +57,40 @@ def main():
|
||||||
path_b = os.path.join(work_dir, f"{bnot_dir}/Copie{copie_id}")
|
path_b = os.path.join(work_dir, f"{bnot_dir}/Copie{copie_id}")
|
||||||
path_a = os.path.join(work_dir, f"Anot/Copie{copie_id}")
|
path_a = os.path.join(work_dir, f"Anot/Copie{copie_id}")
|
||||||
|
|
||||||
# Determine source: must contain both files
|
|
||||||
source_folder = None
|
source_folder = None
|
||||||
|
if os.path.exists(os.path.join(path_b, "Concat.jpg")) and os.path.exists(os.path.join(path_b, "score.json")):
|
||||||
# Check Bnot first
|
|
||||||
if (os.path.exists(os.path.join(path_b, "Concat.jpg")) and
|
|
||||||
os.path.exists(os.path.join(path_b, "score.json"))):
|
|
||||||
source_folder = path_b
|
source_folder = path_b
|
||||||
# Fallback to Anot
|
elif os.path.exists(os.path.join(path_a, "Concat.jpg")) and os.path.exists(os.path.join(path_a, "score.json")):
|
||||||
elif (os.path.exists(os.path.join(path_a, "Concat.jpg")) and
|
|
||||||
os.path.exists(os.path.join(path_a, "score.json"))):
|
|
||||||
print(f"Debug : couldn't find {path_b} falling back to Anot path")
|
|
||||||
source_folder = path_a
|
source_folder = path_a
|
||||||
|
|
||||||
if not source_folder:
|
if not source_folder:
|
||||||
print(f"Skipping ID {copie_id}: Files missing in both Anot and {bnot_dir}.")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Create destination directory
|
# If we reached here, the link is possible
|
||||||
dest_folder_name = safe_name if len(ids) == 1 else f"{safe_name} ({copie_id})"
|
assigned_names.add(name)
|
||||||
|
|
||||||
|
dest_folder_name = f"{safe_name} ({copie_id})"
|
||||||
dest_path = os.path.join(target_subdir, dest_folder_name)
|
dest_path = os.path.join(target_subdir, dest_folder_name)
|
||||||
os.makedirs(dest_path, exist_ok=True)
|
os.makedirs(dest_path, exist_ok=True)
|
||||||
|
|
||||||
common = os.path.commonpath([source_folder, dest_path])
|
links = [("Concat.jpg", f"{safe_name}.jpg"), ("score.json", "score.json")]
|
||||||
s = os.path.relpath(source_folder, common)
|
|
||||||
d = os.path.relpath(dest_path, common)
|
|
||||||
|
|
||||||
print(f"Linking '{s}' -> '{d}'")
|
|
||||||
|
|
||||||
# Link configuration: (source_filename, dest_filename)
|
|
||||||
links = [
|
|
||||||
("Concat.jpg", f"{safe_name}.jpg"),
|
|
||||||
("score.json", "score.json")
|
|
||||||
]
|
|
||||||
|
|
||||||
for src_name, dst_name in links:
|
for src_name, dst_name in links:
|
||||||
src_file = os.path.join(source_folder, src_name)
|
src_file = os.path.join(source_folder, src_name)
|
||||||
dst_link = os.path.join(dest_path, dst_name)
|
dst_link = os.path.join(dest_path, dst_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os.path.lexists(dst_link):
|
if os.path.lexists(dst_link): os.remove(dst_link)
|
||||||
os.remove(dst_link)
|
|
||||||
os.symlink(src_file, dst_link)
|
os.symlink(src_file, dst_link)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error linking {src_name} for {dest_folder_name}: {e}")
|
print(f"Error linking {src_name} for {dest_folder_name}: {e}")
|
||||||
|
|
||||||
|
# --- 4. Print Unassigned Names ---
|
||||||
|
unassigned = expected_names - assigned_names
|
||||||
|
if unassigned:
|
||||||
|
print("\n" + "!" * 40)
|
||||||
|
print("NAMES FROM LIST NOT ASSIGNED:")
|
||||||
|
for n in sorted(unassigned):
|
||||||
|
print(f" - {n}")
|
||||||
|
print("!" * 40)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue