Practice test on all the material: a bypass for skills not started yet
Browse filesThe test card now offers "诪讘讞谉 转专讙讜诇 1/2 注诇 讻诇 讛讞讜诪专". It draws like the
simulation: an even spread over every skill of the test's lessons,
including skills the student has not started, so the student is not told
to practise on the path first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files changed (7)
11 unmodified lines121314151617181920212223242526272811 unmodified linesdef draw(bank, lessons: list[str], states: dict[str, str], n: int, *, share: float = 0.0, weak_before: set[str] | None = None,used: dict[str, int] | None = None, rng: random.Random | None = None) -> dict:"""{"questions": [{skill_id, key}], "weak": [skill ids], "practice_first": [skill ids]}.Covered skills are those of `lessons` that have questions. A skill in the not-started state is never drawn: it is listed in`practice_first`. A weak skill is a started covered skill in the learning state, or one in `weak_before` (answered wrong in anearlier exercise test of this real test). Weak skills give one question each, up to `round(n * share)`; the rest comes from theother skills one per skill round after round (least-used questions first, ties random), then from the weak ones again."""used, rng, weak_before = used or {}, rng or random.Random(), weak_before or set()covered = [s["id"] for s in bank.skills if s["unit"] in lessons and bank.question_keys(s["id"])]started = [i for i in covered if states.get(i, "not_started") != "not_started"]practice_first = [i for i in covered if i not in started]weak = [i for i in started if states.get(i) == "learning" or i in weak_before]other = [i for i in started if i not in weak]pools = {i: sorted(bank.question_keys(i), key=lambda key: (used.get(key, 0), rng.random())) for i in started}11 unmodified lines1213141516171819202122232425262728293011 unmodified linesdef draw(bank, lessons: list[str], states: dict[str, str], n: int, *, share: float = 0.0, weak_before: set[str] | None = None,used: dict[str, int] | None = None, rng: random.Random | None = None, include_unstarted: bool = False) -> dict:"""{"questions": [{skill_id, key}], "weak": [skill ids], "practice_first": [skill ids]}.Covered skills are those of `lessons` that have questions. A skill in the not-started state is never drawn: it is listed in`practice_first`. A weak skill is a started covered skill in the learning state, or one in `weak_before` (answered wrong in anearlier exercise test of this real test). With `include_unstarted`, not-started skills are drawn too (and still listed in `practice_first`). Weak skills give one question each, up to `round(n * share)`; the rest comes from theother skills one per skill round after round (least-used questions first, ties random), then from the weak ones again."""used, rng, weak_before = used or {}, rng or random.Random(), weak_before or set()covered = [s["id"] for s in bank.skills if s["unit"] in lessons and bank.question_keys(s["id"])]started = [i for i in covered if states.get(i, "not_started") != "not_started"]practice_first = [i for i in covered if i not in started]if include_unstarted:started = coveredweak = [i for i in started if states.get(i) == "learning" or i in weak_before]other = [i for i in started if i not in weak]pools = {i: sorted(bank.question_keys(i), key=lambda key: (used.get(key, 0), rng.random())) for i in started}
306 unmodified lines3073083093103113123132 unmodified lines3163173183193203213221 unmodified line324325326327328329330331332333334306 unmodified lines# ---- starting an exercise test or the simulation (reading, answering and submitting use the /api/attempts routes) ----def _start(request: Request, user: dict, test: dict, kind: str, scope: str, share: float) -> dict:"""Resume the student's open attempt of this scope, else draw a new one (questions weighted toward weak skills when `share`)."""from .quizzes import viewstore, bank, now = request.app.state.store, request.app.state.bank, clock.now()2 unmodified linesfor row in mine:if attempts.is_open(row) or kind == "simulation": # open: resume; the simulation is taken once, so its result comes backreturn view(request, row)drawn = exam.draw(bank, test["lessons"], facts["states"], test["questions"], share=share, weak_before=facts["weak_before"], used=facts["used"])if not drawn["questions"]:raise HTTPException(409, "注讜讚 诇讗 讛转讞诇转诐 诪讬讜诪谞讜讬讜转 讘砖讬注讜专讬诐 砖诇 讛诪讘讞谉. 拽讜讚诐 诪转专讙诇讬诐 讘诪住诇讜诇.")row = store.create_attempt(user["id"], kind, scope, now, now + timedelta(minutes=test["minutes"]), drawn["questions"])1 unmodified line@router.post("/tests/{test_id}/exercise/{number}/start")def start_exercise(test_id: int, number: int, request: Request, user: dict = Depends(learner)) -> dict:if number not in exam.EXERCISE_SHARE:raise HTTPException(404, "诪讘讞谉 讛转专讙讜诇 诇讗 谞诪爪讗")test = _student_test(request, user, test_id)return _start(request, user, test, "exercise_test", f"{test_id}:{number}", exam.EXERCISE_SHARE[number])@router.post("/tests/{test_id}/simulation/start")306 unmodified lines3073083093103113123132 unmodified lines3163173183193203213223231 unmodified line325326327328329330331332333334335336337306 unmodified lines# ---- starting an exercise test or the simulation (reading, answering and submitting use the /api/attempts routes) ----def _start(request: Request, user: dict, test: dict, kind: str, scope: str, share: float, include_unstarted: bool = False) -> dict:"""Resume the student's open attempt of this scope, else draw a new one (questions weighted toward weak skills when `share`)."""from .quizzes import viewstore, bank, now = request.app.state.store, request.app.state.bank, clock.now()2 unmodified linesfor row in mine:if attempts.is_open(row) or kind == "simulation": # open: resume; the simulation is taken once, so its result comes backreturn view(request, row)drawn = exam.draw(bank, test["lessons"], facts["states"], test["questions"], share=share, weak_before=facts["weak_before"], used=facts["used"],include_unstarted=include_unstarted)if not drawn["questions"]:raise HTTPException(409, "注讜讚 诇讗 讛转讞诇转诐 诪讬讜诪谞讜讬讜转 讘砖讬注讜专讬诐 砖诇 讛诪讘讞谉. 拽讜讚诐 诪转专讙诇讬诐 讘诪住诇讜诇.")row = store.create_attempt(user["id"], kind, scope, now, now + timedelta(minutes=test["minutes"]), drawn["questions"])1 unmodified line@router.post("/tests/{test_id}/exercise/{number}/start")def start_exercise(test_id: int, number: int, request: Request, user: dict = Depends(learner),all_skills: bool = Query(False, description="the simulation's material: every skill of the test's lessons, started or not, evenly")) -> dict:if number not in exam.EXERCISE_SHARE:raise HTTPException(404, "诪讘讞谉 讛转专讙讜诇 诇讗 谞诪爪讗")test = _student_test(request, user, test_id)share = 0.0 if all_skills else exam.EXERCISE_SHARE[number] # all_skills: drawn like the simulation (an even spread, no weak share)return _start(request, user, test, "exercise_test", f"{test_id}:{number}", share, all_skills)@router.post("/tests/{test_id}/simulation/start")
29 unmodified lines30313233343536373829 unmodified lineslocation.replace(`#/quiz/${encodeURIComponent(lessonId)}/${encodeURIComponent(data.id)}`);}/** An exercise test (1 or 2) of a real test, or its simulation: the same, with the attempt's id put in the address. */export async function startExam(testId, number) {const data = await api(`/api/tests/${encodeURIComponent(testId)}/exercise/${encodeURIComponent(number)}/start`, { method: "POST" });location.replace(`#/exam/${encodeURIComponent(testId)}/${encodeURIComponent(number)}/${encodeURIComponent(data.id)}`);}29 unmodified lines3031323334353637383929 unmodified lineslocation.replace(`#/quiz/${encodeURIComponent(lessonId)}/${encodeURIComponent(data.id)}`);}/** An exercise test (1 or 2) of a real test, or its simulation: the same, with the attempt's id put in the address.* `allSkills` (address `#/exam/<test>/<n>/all`) also draws the skills not started yet. */export async function startExam(testId, number, allSkills = false) {const data = await api(`/api/tests/${encodeURIComponent(testId)}/exercise/${encodeURIComponent(number)}/start${allSkills ? "?all_skills=true" : ""}`, { method: "POST" });location.replace(`#/exam/${encodeURIComponent(testId)}/${encodeURIComponent(number)}/${encodeURIComponent(data.id)}`);}
49 unmodified lines5051525354555657585949 unmodified linesexercise.close();const [kind, ...rest] = where.slice(1).split("/").map(decodeURIComponent);const [test, second, third] = rest;const attempt = kind === "exam" ? third : second;if (!document.getElementById("path") && !document.getElementById("test-card")) await (await import("./testcard.js")).show(view, test); // a link or a reload: the test's card firstif (attempt) await quiz.open(attempt);else if (kind === "exam") await quiz.startExam(test, second);else await quiz.startSimulation(test);} else if (where.startsWith("/test/")) {exercise.close(); quiz.close();49 unmodified lines505152535455565758596049 unmodified linesexercise.close();const [kind, ...rest] = where.slice(1).split("/").map(decodeURIComponent);const [test, second, third] = rest;const allSkills = kind === "exam" && third === "all"; // "/exam/<test>/<n>/all": not an attempt idconst attempt = kind === "exam" ? (allSkills ? undefined : third) : second;if (!document.getElementById("path") && !document.getElementById("test-card")) await (await import("./testcard.js")).show(view, test); // a link or a reload: the test's card firstif (attempt) await quiz.open(attempt);else if (kind === "exam") await quiz.startExam(test, second, allSkills);else await quiz.startSimulation(test);} else if (where.startsWith("/test/")) {exercise.close(); quiz.close();
42 unmodified lines4344454647484942 unmodified lines<section class="card"><h3>讛转讜讻谞讬转</h3>${planList(test)}</section><section class="card"><h3>诪讘讞谞讬 转专讙讜诇</h3>${exercises(test)}${test.practice_first.length ? `<p id="practice-first"><b>讻讚讗讬 诇转专讙诇 拽讜讚诐:</b> ${test.practice_first.map(s => `<a class="ex-chip link" href="#/skill/${esc(s.id)}">${fmt(s.name)}</a>`).join(" ")}</p><p class="muted">讗诇讛 诪讬讜诪谞讜讬讜转 砖注讜讚 诇讗 讛转讞诇转诐, 讜诇讻谉 讗讬谉 诇讛谉 砖讗诇讜转 讘诪讘讞谞讬 讛转专讙讜诇.</p>` : ""}</section><section class="card"><h3>诪讘讞谉 住讬诪讜诇爪讬讛</h3>${simulation(test)}</section>${others.length ? `<section class="card"><h3>诪讘讞谞讬诐 谞讜住驻讬诐</h3><ul class="plain" id="other-tests">${others.map(t => `<li><a href="#/test/${t.id}">${shortDate(t.date)} 路 ${t.lessons.map(l => fmt(l.name)).join(", ")}</a><span class="muted">${daysText(t.days_left)} 路 诪讜讻谞讜转 ${t.readiness.number}</span></li>`).join("")}</ul></section>` : ""}`);42 unmodified lines43444546474849505142 unmodified lines<section class="card"><h3>讛转讜讻谞讬转</h3>${planList(test)}</section><section class="card"><h3>诪讘讞谞讬 转专讙讜诇</h3>${exercises(test)}${test.practice_first.length ? `<p id="practice-first"><b>讻讚讗讬 诇转专讙诇 拽讜讚诐:</b> ${test.practice_first.map(s => `<a class="ex-chip link" href="#/skill/${esc(s.id)}">${fmt(s.name)}</a>`).join(" ")}</p><p class="muted">讗诇讛 诪讬讜诪谞讜讬讜转 砖注讜讚 诇讗 讛转讞诇转诐, 讜诇讻谉 讗讬谉 诇讛谉 砖讗诇讜转 讘诪讘讞谞讬 讛转专讙讜诇.</p><p id="all-skills">${test.exercise_tests.map(e => `<a class="button" href="#/exam/${test.id}/${e.number}/all">诪讘讞谉 转专讙讜诇 ${e.number} 注诇 讻诇 讛讞讜诪专</a>`).join(" ")}</p><p class="muted">"注诇 讻诇 讛讞讜诪专": 砖讗诇讜转 诪讻诇 讛谞讜砖讗讬诐 砖诇 讛诪讘讞谉, 讻诪讜 讘诪讘讞谉 讛住讬诪讜诇爪讬讛, 讙诐 诪诪讬讜诪谞讜讬讜转 砖注讜讚 诇讗 讛转讞诇转诐.</p>` : ""}</section><section class="card"><h3>诪讘讞谉 住讬诪讜诇爪讬讛</h3>${simulation(test)}</section>${others.length ? `<section class="card"><h3>诪讘讞谞讬诐 谞讜住驻讬诐</h3><ul class="plain" id="other-tests">${others.map(t => `<li><a href="#/test/${t.id}">${shortDate(t.date)} 路 ${t.lessons.map(l => fmt(l.name)).join(", ")}</a><span class="muted">${daysText(t.days_left)} 路 诪讜讻谞讜转 ${t.readiness.number}</span></li>`).join("")}</ul></section>` : ""}`);
59 unmodified lines60616263646559 unmodified linesassert not set(per_skill(got)) & set(skills[5:])def test_a_skill_answered_wrong_in_an_earlier_exercise_test_counts_as_weak(bank):lessons, skills = lessons_and_skills(bank)st = states(skills, mastered=skills) # everything mastered: nothing weak by state59 unmodified lines60616263646566676869707159 unmodified linesassert not set(per_skill(got)) & set(skills[5:])def test_include_unstarted_draws_the_not_started_skills_too(bank):lessons, skills = lessons_and_skills(bank)got = exam.draw(bank, lessons, states(skills), 12, share=0.6, include_unstarted=True, rng=random.Random(11))assert len(got["questions"]) == 12 and got["practice_first"] == skillsdef test_a_skill_answered_wrong_in_an_earlier_exercise_test_counts_as_weak(bank):lessons, skills = lessons_and_skills(bank)st = states(skills, mastered=skills) # everything mastered: nothing weak by state
342 unmodified lines343344345346347348342 unmodified linesassert start_ex(client, test["id"], 3).status_code == 404def test_the_simulation_is_refused_8_days_before_with_its_opening_date(world):client, store, lessons = worldtest = set_test(client, lessons, days=14).json()342 unmodified lines343344345346347348349350351352353354355356357342 unmodified linesassert start_ex(client, test["id"], 3).status_code == 404def test_an_exercise_test_with_all_skills_starts_even_when_nothing_is_started(world):client, store, lessons = worldtest = set_test(client, lessons, days=14, questions=6).json()got = client.post(f"/api/tests/{test['id']}/exercise/1/start?all_skills=true", headers=auth(KID))assert got.status_code == 200 and len(got.json()["questions"]) == 6bank, lessons_of_test = client.app.state.bank, set(lessons[:2])assert all(bank.skill(q["skill_id"])["unit"] in lessons_of_test for q in store.get_attempt(got.json()["id"])["questions"])def test_the_simulation_is_refused_8_days_before_with_its_opening_date(world):client, store, lessons = worldtest = set_test(client, lessons, days=14).json()
mathly2/exam.py+4-2
mathly2/realtests.py+7-4
mathly2/static/quiz.js+4-3
mathly2/static/student.js+3-2
mathly2/static/testcard.js+3-1
mathly2/tests/test_exam.py+6
mathly2/tests/test_realtests_api.py+9