Support evaluation-local configuration and names overrides
This commit is contained in:
1 parent
0bb6f7d97c
commit
d4404e4c27
36 files changed
+409
-184
No files matched your search
@@ -10,21 +10,11 @@ import pandas as pd
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from copienator import atomic_write_json, read_json
|
||||
from copienator.configuration import (
|
||||
FINAL_SCORE_FONT_PATH,
|
||||
FINAL_SCORE_HISTOGRAM_PATH,
|
||||
FINAL_SCORE_ODS_PATH,
|
||||
FINAL_SCORE_OUTPUT_DIR,
|
||||
)
|
||||
|
||||
# Configuration constants
|
||||
ODS_PATH = Path(FINAL_SCORE_ODS_PATH).expanduser()
|
||||
OUTPUT_DIR = Path(FINAL_SCORE_OUTPUT_DIR).expanduser()
|
||||
HISTOGRAM_PATH = Path(FINAL_SCORE_HISTOGRAM_PATH).expanduser()
|
||||
from copienator import configuration
|
||||
|
||||
|
||||
def score_font(size):
|
||||
candidates = [FINAL_SCORE_FONT_PATH, "DejaVuSans-Bold.ttf", "arial.ttf"]
|
||||
candidates = [configuration.FINAL_SCORE_FONT_PATH, "DejaVuSans-Bold.ttf", "arial.ttf"]
|
||||
for candidate in candidates:
|
||||
if not candidate:
|
||||
continue
|
||||
@@ -64,9 +54,10 @@ def copy_return_artifacts(source_dir: Path, destination_dir: Path) -> None:
|
||||
|
||||
def copy_histogram(output_dir: Path, *, copy_merged_histogramme: bool = False) -> None:
|
||||
"""Copy the score histogram beside the per-student output folders."""
|
||||
sources = [(HISTOGRAM_PATH, "histogramme.pdf")]
|
||||
histogram_path = Path(configuration.FINAL_SCORE_HISTOGRAM_PATH).expanduser()
|
||||
sources = [(histogram_path, "histogramme.pdf")]
|
||||
if copy_merged_histogramme:
|
||||
sources.append((HISTOGRAM_PATH.with_name("merged_histogramme.pdf"), "merged_histogramme.pdf"))
|
||||
sources.append((histogram_path.with_name("merged_histogramme.pdf"), "merged_histogramme.pdf"))
|
||||
for source, filename in sources:
|
||||
if not source.is_file():
|
||||
print(f"Warning: Missing histogram '{source}'.")
|
||||
@@ -113,7 +104,7 @@ def process_images(base_dir, output_dir, *, copy_merged_histogramme=False):
|
||||
try:
|
||||
# header=None assumes the file starts directly with data.
|
||||
# If row 0 is a header, change to header=0
|
||||
df = pd.read_excel(ODS_PATH, engine="odf", header=None)
|
||||
df = pd.read_excel(Path(configuration.FINAL_SCORE_ODS_PATH).expanduser(), engine="odf", header=None)
|
||||
# Create a lookup dictionary: {Name: Score}
|
||||
score_db = dict(zip(df[0], df[1]))
|
||||
except Exception as e:
|
||||
@@ -209,7 +200,8 @@ def main(argv=None):
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
base_dir = args.dir.expanduser().resolve()
|
||||
output_dir = OUTPUT_DIR / base_dir.name
|
||||
configuration.use_evaluation(base_dir)
|
||||
output_dir = Path(configuration.FINAL_SCORE_OUTPUT_DIR).expanduser() / base_dir.name
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
process_images(base_dir, output_dir, copy_merged_histogramme=args.copy_merged_histogramme)
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user