Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: keep adaptive SRS UI compatible with base tests

Gao-Chenkaia448e8743c78
diff --git a/deeptutor/api/routers/mastery_path.py b/deeptutor/api/routers/mastery_path.py
index 332d21fc1..bca5270fc 100644
--- a/deeptutor/api/routers/mastery_path.py
+++ b/deeptutor/api/routers/mastery_path.py
@@ -269,7 +269,9 @@ def _review_queue(progress, *, now: float | None = None) -> list[dict]:
)
),
}
- for task in sorted(progress.review_queue, key=lambda item: review_sort_key(item, now=moment))
+ for task in sorted(
+ progress.review_queue, key=lambda item: review_sort_key(item, now=moment)
+ )
]
@@ -279,9 +281,7 @@ def _read_projection(progress, *, now: float | None = None):
projected = progress.model_copy(deep=True)
moment = time.time() if now is None else now
- projected.review_queue = SpacedRepetitionScheduler().build_review_queue(
- projected, now=moment
- )
+ projected.review_queue = SpacedRepetitionScheduler().build_review_queue(projected, now=moment)
return projected
diff --git a/deeptutor/learning/policy.py b/deeptutor/learning/policy.py
index d31d64cee..f97c64bc9 100644
--- a/deeptutor/learning/policy.py
+++ b/deeptutor/learning/policy.py
@@ -258,9 +258,7 @@ def next_objective(
gate=_gate_kind(kp),
mastery=display_mastery(progress, kp),
threshold=gate_threshold(kp.type),
- reason=(
- task.reason or "This objective is due for spaced-repetition review."
- ),
+ reason=(task.reason or "This objective is due for spaced-repetition review."),
forgetting_risk=task.forgetting_risk,
)
@@ -387,8 +385,7 @@ def _review_report(
"recent_failure": bool(
state.consecutive_wrong
or any(
- record.knowledge_point_id == kp_id
- and record.status in ("active", "retrying")
+ record.knowledge_point_id == kp_id and record.status in ("active", "retrying")
for record in progress.error_records
)
),
diff --git a/deeptutor/learning/scheduler.py b/deeptutor/learning/scheduler.py
index 797098b2f..81b39528f 100644
--- a/deeptutor/learning/scheduler.py
+++ b/deeptutor/learning/scheduler.py
@@ -262,18 +262,12 @@ class SpacedRepetitionScheduler:
parts.append(f"due in {_format_span(-delta / unit)}")
desired = state.desired_retention or DEFAULT_DESIRED_RETENTION
if recall + 1e-9 < desired:
- parts.append(
- f"retrievability {recall:.0%} below {desired:.0%} target"
- )
+ parts.append(f"retrievability {recall:.0%} below {desired:.0%} target")
else:
parts.append(f"retrievability {recall:.0%}")
- failures = state.consecutive_wrong + (
- 1 if kp_id in _error_kp_ids(progress) else 0
- )
+ failures = state.consecutive_wrong + (1 if kp_id in _error_kp_ids(progress) else 0)
if state.lapse_count:
- parts.append(
- f"{state.lapse_count} lapse{'s' if state.lapse_count != 1 else ''}"
- )
+ parts.append(f"{state.lapse_count} lapse{'s' if state.lapse_count != 1 else ''}")
elif failures:
parts.append("recent failure")
return "; ".join(parts) + "."
diff --git a/deeptutor/learning/service.py b/deeptutor/learning/service.py
index 3fba14052..70103613a 100644
--- a/deeptutor/learning/service.py
+++ b/deeptutor/learning/service.py
@@ -114,9 +114,7 @@ class LearningService:
if attempt.knowledge_point_id in new_kp_ids
]
progress.learning_evidence = [
- event
- for event in progress.learning_evidence
- if event.knowledge_point_id in new_kp_ids
+ event for event in progress.learning_evidence if event.knowledge_point_id in new_kp_ids
]
progress.feynman_retries = {
k: v for k, v in progress.feynman_retries.items() if k in new_kp_ids
diff --git a/deeptutor/learning/storage.py b/deeptutor/learning/storage.py
index d93e1b361..c3f88c1b3 100644
--- a/deeptutor/learning/storage.py
+++ b/deeptutor/learning/storage.py
@@ -518,11 +518,15 @@ class LearningStore:
(migration,),
).fetchone()
if already_applied is None:
- for row in conn.execute("SELECT path_id, state_json FROM mastery_paths").fetchall():
+ for row in conn.execute(
+ "SELECT path_id, state_json FROM mastery_paths"
+ ).fetchall():
try:
progress = self._progress_from_row(row)
except (TypeError, ValueError, ValidationError, json.JSONDecodeError):
- logger.warning("Skipping evidence projection for invalid path %s", row["path_id"])
+ logger.warning(
+ "Skipping evidence projection for invalid path %s", row["path_id"]
+ )
continue
self._sync_evidence_projection(conn, str(row["path_id"]), progress)
conn.execute(
@@ -868,13 +872,14 @@ class LearningStore:
).fetchone()
return (
self._progress_from_row(row),
- [LearningEvidence.model_validate(json.loads(item["evidence_json"])) for item in evidence_rows],
+ [
+ LearningEvidence.model_validate(json.loads(item["evidence_json"]))
+ for item in evidence_rows
+ ],
int(count_row["count"] if count_row else 0),
)
- def count_learning_evidence(
- self, book_id: str, knowledge_point_id: str | None = None
- ) -> int:
+ def count_learning_evidence(self, book_id: str, knowledge_point_id: str | None = None) -> int:
path_id = self._validate_id(book_id)
self._import_legacy_if_needed(path_id)
if knowledge_point_id:
diff --git a/deeptutor/learning/tests/test_storage.py b/deeptutor/learning/tests/test_storage.py
index cfe13eac6..77d803f22 100644
--- a/deeptutor/learning/tests/test_storage.py
+++ b/deeptutor/learning/tests/test_storage.py
@@ -116,10 +116,13 @@ class TestSaveLoad:
assert len(evidence) == 1
assert evidence[0].result == "incorrect"
with sqlite3.connect(store.db_path) as conn:
- assert conn.execute(
- "SELECT COUNT(*) FROM mastery_learning_evidence WHERE path_id = ?",
- ("evidence-index",),
- ).fetchone()[0] == 2
+ assert (
+ conn.execute(
+ "SELECT COUNT(*) FROM mastery_learning_evidence WHERE path_id = ?",
+ ("evidence-index",),
+ ).fetchone()[0]
+ == 2
+ )
def test_legacy_json_without_retention_fields_imports(self, store, tmp_path):
legacy_path = tmp_path / "old-srs.json"
diff --git a/web/components/space/learning/ObjectiveDetail.tsx b/web/components/space/learning/ObjectiveDetail.tsx
index eabad7f42..df9e0dc6b 100644
--- a/web/components/space/learning/ObjectiveDetail.tsx
+++ b/web/components/space/learning/ObjectiveDetail.tsx
@@ -25,6 +25,8 @@ export function ObjectiveDetail({
}) {
const { t } = useTranslation();
const qualitative = report.gate === "qualitative";
+ const evidence = report.evidence ?? [];
+ const evidenceCount = report.evidence_count ?? evidence.length;
return (
<div className="mt-1 mb-2 ml-5 space-y-3 border-l border-[var(--border)] pl-3">
<GateBar report={report} />
@@ -113,15 +115,15 @@ export function ObjectiveDetail({
</Row>
)}
- {report.evidence.length > 0 && (
+ {evidence.length > 0 && (
<div>
<div className="text-xs text-[var(--muted-foreground)]">
{t("Retention evidence ({{count}})", {
- count: report.evidence_count,
+ count: evidenceCount,
})}
</div>
<ul className="mt-1 space-y-1">
- {report.evidence.map((evidence, index) => (
+ {evidence.map((evidence, index) => (
<li
key={`${evidence.timestamp}-${evidence.turn_id || index}`}
className="flex items-center justify-between gap-2 text-[11px] text-[var(--muted-foreground)]"
@@ -135,7 +137,7 @@ export function ObjectiveDetail({
</li>
))}
</ul>
- {report.evidence_count > report.evidence.length && (
+ {evidenceCount > evidence.length && (
<p className="mt-1 text-[10px] text-[var(--muted-foreground)]">
{t("Showing the latest 20 events")}
</p>
@@ -157,7 +159,12 @@ export function ObjectiveDetail({
/** Mastery against the gate it has to clear. */
function GateBar({ report }: { report: ObjectiveReport }) {
const { t } = useTranslation();
- const pct = Math.round(report.mastery * 100);
+ const qualitative = report.gate === "qualitative";
+ const pct = qualitative
+ ? report.mastered
+ ? 100
+ : 0
+ : Math.round(report.mastery * 100);
const thresholdPct = Math.round(report.threshold * 100);
const perfectButBelowGate =
report.gate === "quantitative" &&
@@ -202,6 +209,13 @@ function GateBar({ report }: { report: ObjectiveReport }) {
)}
</p>
)}
+ {qualitative && !report.mastered && report.attempts.length > 0 && (
+ <p className="mt-1.5 text-[11px] leading-4 text-[var(--muted-foreground)]">
+ {t(
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.",
+ )}
+ </p>
+ )}
</div>
);
}
diff --git a/web/lib/learning-api.ts b/web/lib/learning-api.ts
index 4c5d9bca8..3ad5eb2cc 100644
--- a/web/lib/learning-api.ts
+++ b/web/lib/learning-api.ts
@@ -287,8 +287,11 @@ export interface ObjectiveReport {
correct_count: number;
explanation: string;
review: ObjectiveReview | null;
- evidence: LearningEvidence[];
- evidence_count: number;
+ // These fields were added after the initial objective report contract.
+ // Keep them optional so older API responses and embedded consumers remain
+ // readable while the current server includes both values.
+ evidence?: LearningEvidence[];
+ evidence_count?: number;
errors: ObjectiveErrorRecord[];
}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 3f1475edd..672b68486 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -3175,6 +3175,7 @@
" · cleared": " · cleared",
"No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.": "No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.",
"Qualitative gate: explain it in your own words": "Qualitative gate: explain it in your own words",
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.": "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.",
"Topic name": "Topic name",
"What is this path called?": "What is this path called?",
"Review plan": "Review plan",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index ae76430f6..ebb86f1be 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -3175,6 +3175,7 @@
" · cleared": " · 已订正",
"No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.": "还没有作答记录。在对话里继续辅导后,这里会出现题目、你的回答和判分。",
"Qualitative gate: explain it in your own words": "定性门槛:用自己的话讲清楚",
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.": "练习题打不开这道门——它要等你用自己的话把这个概念讲清楚、并由导师记录下来才会打开。你在这里的作答仍然算作练习。",
"Topic name": "目标名称",
"What is this path called?": "这条路叫什么?",
"Review plan": "复习计划",