Improve web finalisation navigation, caching and Anot support

This commit is contained in:
sebastien committed 2026-11-03 11:38:39 +01:00
1 parent 5de70dbc0d
commit b069805988
21 files changed
+339 -58

No files matched your search

+11 -1
View File
@@ -1,5 +1,6 @@
import argparse
import math
import re
import shutil
import sys
from decimal import Decimal, InvalidOperation, ROUND_CEILING
@@ -37,7 +38,7 @@ def get_rounded_score(score):
"""Round score to one decimal place below (floor)."""
try:
val = float(score)
return math.floor(val * 10) / 10
return math.floor(val * 10) / 10 if math.isfinite(val) else None
except (ValueError, TypeError):
return None
@@ -130,6 +131,7 @@ def process_images(base_dir, output_dir, *, copy_merged_histogramme=False):
print(f"Error: Directory '{search_path}' not found.")
sys.exit(1)
exported_marks = {}
for student_source in sorted(path for path in search_path.iterdir() if path.is_dir()):
image_paths = sorted(student_source.glob("*.jpg"))
pdf_paths = sorted(student_source.glob("*.pdf"))
@@ -159,6 +161,7 @@ def process_images(base_dir, output_dir, *, copy_merged_histogramme=False):
if score is None:
print(f"Error: Invalid score '{raw_score}' for '{student_name}'.")
else:
score_published = not image_paths
# 5. Process Images
for img_path in image_paths:
try:
@@ -180,13 +183,20 @@ def process_images(base_dir, output_dir, *, copy_merged_histogramme=False):
draw.text((x, y), text, fill=(255, 0, 0), font=font)
img.save(student_output / img_path.name)
score_published = True
print(f"Processed: {student_name} -> {score}")
except Exception as e:
print(f"Error processing image for '{student_name}': {e}")
match = re.search(r'\((\d+)\)$', student_source.name)
if match and score_published:
exported_marks[str(int(match[1]))] = {'name': student_name, 'score': str(score)}
for pdf_path in pdf_paths:
shutil.copy2(pdf_path, student_output / pdf_path.name)
from copienator.final_scores import FINAL_SCORES_FILE
atomic_write_json(base_dir / FINAL_SCORES_FILE, {'version': 1, 'copies': exported_marks})
write_score_statistics(search_path, output_dir)
copy_histogram(output_dir, copy_merged_histogramme=copy_merged_histogramme)