SPB Git

Repository Public MIT Research preview

validate_quizzes.py 3.8 KB 80 lines python

1#!/usr/bin/env python32"""Validate quizzes: schema, answer keys, explanations, distractor rationales, outcome coverage, variety."""3from __future__ import annotations45import argparse6import sys7from collections import Counter89from atlaslib import Report, frame_ids, load_course, load_yaml, select_sessions, session_dir1011TYPES = {"choix-unique", "vrai-faux"}12LEVELS = {"rappel", "compréhension", "application", "diagnostic"}131415def main() -> int:16    ap = argparse.ArgumentParser(description=__doc__)17    ap.add_argument("--session")18    args = ap.parse_args()19    rep = Report("quizzes")20    for s in select_sessions(load_course(), args.session):21        d, sid = session_dir(s), s["id"]22        path = d / "quizzes" / "questions.yaml"23        if not path.exists():24            rep.error(f"{sid}: quizzes/questions.yaml missing")25            continue26        quiz = load_yaml(path)27        qs = quiz.get("questions", [])28        slides = set(frame_ids(d))29        if quiz.get("language") != "fr-CA":30            rep.error(f"{sid}: quiz language must be fr-CA")31        if len(qs) < 8:32            rep.error(f"{sid}: {len(qs)} questions (minimum 8)")33        ids = [q.get("id") for q in qs]34        if len(set(ids)) != len(ids):35            rep.error(f"{sid}: duplicate question IDs")36        for q in qs:37            qid = q.get("id", "?")38            opts = [o["id"] for o in q.get("options", [])]39            if q.get("type") not in TYPES or q.get("level") not in LEVELS:40                rep.error(f"{qid}: invalid type or level")41            if len(opts) < 2 or len(set(opts)) != len(opts):42                rep.error(f"{qid}: options missing or duplicated")43            if q.get("answer") not in opts:44                rep.error(f"{qid}: answer key {q.get('answer')!r} is not an option")45            if len(q.get("explanation", "")) < 60:46                rep.error(f"{qid}: explanation missing or too short")47            if len(q.get("prompt", "")) < 20:48                rep.error(f"{qid}: prompt too short")49            wrong = set(opts) - {q.get("answer")}50            if set((q.get("distractors") or {})) != wrong:51                rep.error(f"{qid}: every wrong option needs a rationale under 'distractors'")52            if not 1 <= q.get("outcome", 0) <= len(s["outcomes"]):53                rep.error(f"{qid}: outcome index out of range")54            for ref in q.get("slides", []):55                if ref not in slides:56                    rep.error(f"{qid}: refers to unknown slide {ref}")57            if not q.get("slides"):58                rep.error(f"{qid}: must cite at least one slide (answerable from the session materials)")59            texts = [o["text"].strip().lower() for o in q.get("options", [])]60            if len(set(texts)) != len(texts):61                rep.error(f"{qid}: two options have the same text")62        covered = {q.get("outcome") for q in qs}63        for i in range(1, len(s["outcomes"]) + 1):64            if i not in covered:65                rep.error(f"{sid}: learning outcome {i} is not assessed by any question")66        levels = Counter(q.get("level") for q in qs)67        if levels["application"] + levels["diagnostic"] < 3:68            rep.error(f"{sid}: needs at least 3 application or diagnostic questions (not only recall)")69        keys = Counter(q.get("answer") for q in qs if q.get("type") == "choix-unique")70        if keys and max(keys.values()) > 0.6 * sum(keys.values()):71            rep.warn(f"{sid}: answer key is unbalanced {dict(keys)} — shuffle options at delivery time")72        if not (d / "quizzes" / "explanations.md").exists():73            rep.error(f"{sid}: quizzes/explanations.md missing (run `make docs-render`)")74        rep.note(f"{sid}: {len(qs)} questions; levels {dict(levels)}; keys {dict(keys)}")75    return rep.finish()767778if __name__ == "__main__":79    sys.exit(main())80
Files main
Menu

Theme