fix: restore recency weighting in compute_mastery (#618)

This commit is contained in:
whm
2026-07-12 16:36:02 +08:00
parent 3e3b9a6ecb
commit 5d7647002e
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ def compute_mastery(correctness: list[bool]) -> float:
return 0.0
recent = correctness[-len(_RECENCY_WEIGHTS) :]
weights = _RECENCY_WEIGHTS[-len(recent) :]
score = sum(w * (1.0 if c else 0.0) for w, c in zip(recent, weights, strict=True)) / sum(
score = sum(w * (1.0 if c else 0.0) for c, w in zip(recent, weights, strict=True)) / sum(
weights
)
return min(score, _CONFIDENCE_CAP.get(len(recent), 1.0))
@@ -69,6 +69,18 @@ def test_compute_mastery_partial_correctness_scales():
assert one_of_five < two_of_five < three_of_five
def test_compute_mastery_weighs_recent_attempts_more_heavily():
"""Regression test for #618: recency weighting must actually distinguish
a recovering history from a declining one, even with the same correct
count. A miss-then-two-hits history should score higher than a
two-hits-then-miss history."""
recovering = compute_mastery([False, True, True])
declining = compute_mastery([True, True, False])
assert recovering > declining
assert recovering == pytest.approx(0.696, abs=1e-3)
assert declining == pytest.approx(0.643, abs=1e-3)
# ── grade_and_record: the unified post-answer pipeline ─────────────────────