Precalculus Studio: placement, worked examples, retrieval quizzes, peer instruction (part 5)
1289247 verified Download src/edtech_core/assessment.py from BenjaminKaindu0506/ed-tech-studio: direct link, hf CLI and curl.
- Browser
- Download file 6.15 kB
-
https://huggingface.co/spaces/BenjaminKaindu0506/ed-tech-studio/resolve/main/src/edtech_core/assessment.py
- Command line
-
hf download hf://spaces/BenjaminKaindu0506/ed-tech-studio/src/edtech_core/assessment.py
-
curl -L -o assessment.py https://huggingface.co/spaces/BenjaminKaindu0506/ed-tech-studio/resolve/main/src/edtech_core/assessment.py
6.15 kB
| """Placement assessment β required before any quiz; its result is handed to the Research Agent. | |
| Design: | |
| - One constructed-response problem per assessable topic (β€ ASSESSMENT_MAX_ITEMS, spread across | |
| the curriculum in textbook order), answered by hand (photo) or typed, with reasoning shown. | |
| Reasoning matters: a right answer with broken reasoning is "partial", not "solid". | |
| - Per-topic level: solid (correct + sound reasoning) / partial / gap. "I don't know yet" is a | |
| valid answer and maps to gap β guessing would only blur the placement. | |
| - Why it exists: the expertise-reversal effect (Kalyuga 2007): full worked examples help novices | |
| but become redundant for learners who already know the material, where problem solving wins. | |
| The level decides where each topic's tutoring starts (worked example β faded β full problem). | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import random | |
| import uuid | |
| from datetime import datetime, timezone | |
| from src.config import ASSESSMENT_MAX_ITEMS, ASSESSMENT_MIN_TOPIC_ITEMS | |
| from src.edtech_core.curriculum import TOPIC_BY_ID, TOPICS | |
| from src.edtech_core.judge import evaluate_work | |
| from src.edtech_core.learner_model import LearnerState | |
| from src.edtech_core.quiz import load_bank | |
| LEVEL_FROM_VERDICT = {"correct": "solid", "partially_correct": "partial", "incorrect": "gap"} | |
| def assessable_topics() -> list[str]: | |
| bank = load_bank() | |
| return [t.id for t in TOPICS | |
| if sum(1 for p in bank.get(t.id, []) if p["answer_format"] == "short_answer") >= ASSESSMENT_MIN_TOPIC_ITEMS] | |
| def _spread(seq: list[str], k: int) -> list[str]: | |
| if len(seq) <= k: | |
| return seq | |
| step = (len(seq) - 1) / (k - 1) | |
| return [seq[round(i * step)] for i in range(k)] | |
| def _path(state: LearnerState, aid: str): | |
| return state.quiz_dir().parent / "assessments" / f"{aid}.json" | |
| def build_assessment(learner_id: str, max_items: int = ASSESSMENT_MAX_ITEMS, seed: int | None = None) -> dict: | |
| state = LearnerState.load(learner_id) | |
| rng = random.Random(seed) | |
| topics = _spread(assessable_topics(), max_items) | |
| items = [] | |
| for i, tid in enumerate(topics, 1): | |
| pool = [p for p in load_bank()[tid] if p["answer_format"] == "short_answer" and len(p["statement"]) < 700] | |
| pool = pool or [p for p in load_bank()[tid] if p["answer_format"] != "multiple_choice"] | |
| p = rng.choice(pool) | |
| items.append({"n": i, "topic": tid, "topic_title": TOPIC_BY_ID[tid].title, "problem_id": p["id"], | |
| "statement": p["statement"], "image_paths": p["image_paths"], "answer_key": p["answer"], | |
| "answer_format": p["answer_format"], "solution": p["solution"], "evaluation": None}) | |
| assessment = {"assessment_id": f"a-{datetime.now(timezone.utc):%Y%m%d%H%M%S}-{uuid.uuid4().hex[:6]}", | |
| "learner_id": learner_id, "created": datetime.now(timezone.utc).isoformat(timespec="seconds"), | |
| "instructions": ("Work each problem on paper and upload a photo (or type). Show every step and " | |
| "say which concept/idea you used. If you haven't learned a topic yet, answer " | |
| "\"I don't know yet\" β that's useful information, not a failure."), | |
| "items": items} | |
| path = _path(state, assessment["assessment_id"]) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| path.write_text(json.dumps(assessment, indent=2, ensure_ascii=False)) | |
| state.assessment = {"assessment_id": assessment["assessment_id"], "started_at": assessment["created"]} | |
| state.save() | |
| return assessment | |
| def load_assessment(learner_id: str, assessment_id: str) -> dict: | |
| return json.loads(_path(LearnerState.load(learner_id), assessment_id).read_text()) | |
| def submit_assessment_answer(learner_id: str, assessment_id: str, n: int, response: str) -> dict: | |
| state = LearnerState.load(learner_id) | |
| path = _path(state, assessment_id) | |
| a = json.loads(path.read_text()) | |
| item = next(it for it in a["items"] if it["n"] == n) | |
| if response.strip().lower().strip(".! ") in ("i don't know yet", "i dont know yet", "i don't know", "idk", "skip"): | |
| ev = {"verdict": "incorrect", "correct": False, "answer_correct": False, "reasoning_quality": "missing", | |
| "gaps": ["Not learned yet (self-reported)."], "faulty_reasoning": [], "why_correct": "", | |
| "feedback": "Thanks β noted as not learned yet. We'll start this topic with a worked example.", | |
| "learner_final_answer": None, "graded_by": "self-report"} | |
| else: | |
| ev = evaluate_work(item["statement"], item["answer_key"], response, mode="explain", | |
| reference_solution=item["solution"], answer_format=item["answer_format"]) | |
| item["evaluation"] = ev | |
| item["response"] = response | |
| path.write_text(json.dumps(a, indent=2, ensure_ascii=False)) | |
| return ev | |
| def finalize_assessment(learner_id: str, assessment_id: str) -> dict: | |
| """Levels per topic + placement; marks solid topics as covered; hands the result to the | |
| Research Agent, which turns it into a learning plan.""" | |
| state = LearnerState.load(learner_id) | |
| a = json.loads(_path(state, assessment_id).read_text()) | |
| levels = {it["topic"]: LEVEL_FROM_VERDICT[(it["evaluation"] or {}).get("verdict", "incorrect")] | |
| for it in a["items"]} | |
| placement = next((t for t in levels if levels[t] != "solid"), None) | |
| state.assessment = {"assessment_id": assessment_id, "started_at": a["created"], | |
| "completed_at": datetime.now(timezone.utc).isoformat(timespec="seconds"), | |
| "levels": levels, "placement": placement, | |
| "score": f"{sum(v == 'solid' for v in levels.values())}/{len(levels)} solid"} | |
| for t in levels: # prior knowledge becomes material for interleaved review | |
| if levels[t] == "solid": | |
| state.cover(t) | |
| state.save() | |
| from src.edtech_core.research import receive_assessment # handoff β Research Agent | |
| plan = receive_assessment(learner_id) | |
| return {"assessment": state.assessment, "learning_plan": plan} | |