讲不清就退一层:迷你先修图(39 知识点/60 边)+讲一遍弹窗(216 测试 + 41/22/21/29 冒烟)
This commit is contained in:
@@ -525,3 +525,37 @@ python tests/smoke_http.py # 39 项 HTTP 冒烟(真起服务
|
||||
初中版(`junior/`)暂不套用这条规则:它用「做对一道变式」替代第二次连对,
|
||||
「当天再对一次」在那边本来就不算过关,语义已经不同。
|
||||
|
||||
|
||||
### 四点二十四、讲不清就退一层:迷你先修图(`kp_graph`)
|
||||
|
||||
现在的闭环里,一道题讲不清 → 换个说法再讲 → 还不过 → 7 天后再来。
|
||||
但如果孩子讲不清的原因是**前置知识缺了**(「两位数乘两位数」讲不清,其实是「表内乘法」不熟),
|
||||
再讲十遍这道题也不会过——闭环就在这里空转。
|
||||
|
||||
数据在 `data/kp_graph.json`:小学数学 1–3 年级,39 个知识点、60 条边,
|
||||
每条边写 `strength`(hard/soft)与一句人话 `reason`。id 直接复用工作台
|
||||
`kpt.json` 的编号,前端不用再维护一张名字表。
|
||||
|
||||
`backend/kp_graph.py` 只回答三个问题:
|
||||
|
||||
- `parents(kp)`:直接前置,hard 在前、年级高的在前
|
||||
- `retreat(kp)`:讲不清时退到哪(标 hard 的前置里年级最高的那个),
|
||||
带 `step` / `reason` / `chain`(从根到它的整条路)/ `tip`
|
||||
- `chain(kp, limit)`:沿 hard 边回溯,去重防环
|
||||
|
||||
接口:讲不清时 `POST /api/mistakes/<id>/explain` 的返回里多一个 `retreat`;
|
||||
另有 `GET /api/kp-graph/<kp>` 给「学情分析」用。工作台在「错题本 → 讲一遍」
|
||||
和「今日训练连对两次」的就地入口里把这张卡片画出来:**退一层:先补「多位数乘一位数」**
|
||||
+为什么退到这+这条路,家长点开能看懂理由。
|
||||
|
||||
三条边界,写在这里免得以后越做越大:
|
||||
|
||||
1. 只做小学 1–3 年级数学。语文的「知识点」不是树,硬连只会连出假因果。
|
||||
2. 只做「退一层」,不做自适应诊断。错了的边只影响**建议**,不影响判分和毕业,
|
||||
所以不需要教师逐条审核就能上线。
|
||||
3. 不给空建议:没有知识点、或没有 hard 前置(比如 `M001` 10 以内数的认识),
|
||||
`retreat` 返回 `None`,界面上就不出现这张卡片。
|
||||
|
||||
`tests/test_kp_graph.py` 14 例:图自检(无未知 id、无环、前置年级不更高)、
|
||||
每条边有理由、规模在 30–60 点 / 40–90 边、`M041` 退到 `M039`、
|
||||
根节点不给建议、讲清失败时接口带 `retreat`、没有 kp 时不带。
|
||||
|
||||
+11
-1
@@ -23,7 +23,7 @@ from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
from . import db as dbm
|
||||
from . import qr
|
||||
from . import kp_graph, qr
|
||||
from . import scanflow, services as svc
|
||||
from .services import ApiError
|
||||
|
||||
@@ -388,6 +388,16 @@ def post_explain(ctx: Ctx, mid: str, **kw):
|
||||
str(ctx.body.get("text") or ""))
|
||||
|
||||
|
||||
@route("GET", r"/api/kp-graph/(?P<kp>[^/]+)", auth="none")
|
||||
def kp_detail(ctx: Ctx, kp: str, **kw):
|
||||
"""知识点 + 前置 + 退一层建议(工作台「学情分析」与「讲一遍」用)。"""
|
||||
t = kp_graph.topic(kp)
|
||||
if not t:
|
||||
raise ApiError(404, "NO_KP", "没有这个知识点")
|
||||
return {"topic": t, "parents": kp_graph.parents(kp),
|
||||
"chain": kp_graph.chain(kp), "retreat": kp_graph.retreat(kp)}
|
||||
|
||||
|
||||
@route("GET", "/api/report/weekly", auth="parent")
|
||||
def weekly(ctx: Ctx, **kw):
|
||||
return svc.weekly_report(ctx.conn, ctx.gid, ctx.q("child_id"),
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""迷你先修图:讲不清的时候,往前退一层。
|
||||
|
||||
为什么要有它:现在的闭环里,一道题讲不清 → 换个说法再讲 → 还不过 → 7 天后再来。
|
||||
但如果孩子讲不清的原因是**前置知识缺了**(比如「两位数乘两位数」讲不清,其实是
|
||||
「表内乘法」不熟),再讲十遍这道题也不会过,闭环就在这儿空转。
|
||||
|
||||
这个模块只回答三个问题:
|
||||
1. 这道题的知识点,前置是什么?(`parents`)
|
||||
2. 讲不清时该退到哪?(`retreat` → 标 hard 的前置里,年级最高的那个)
|
||||
3. 为什么是它?(每条边都写了 `reason`,家长点开能看到人话)
|
||||
|
||||
数据:`data/kp_graph.json`(小学 1–3 年级数学,id 与工作台 kpt.json 一致)。
|
||||
只做「退一层」,不做自适应诊断、不做全学段——错了的边只会影响建议,
|
||||
不影响判分和毕业,所以不需要教师逐条审核就能上线。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
GRAPH_PATH = Path(__file__).resolve().parent.parent / "data" / "kp_graph.json"
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def _load() -> tuple[dict, dict]:
|
||||
raw = json.loads(GRAPH_PATH.read_text(encoding="utf-8"))
|
||||
topics = {t["id"]: t for t in raw["topics"]}
|
||||
parents: dict[str, list[dict]] = {}
|
||||
for e in raw["edges"]:
|
||||
parents.setdefault(e["topicId"], []).append({
|
||||
"id": e["prerequisiteId"],
|
||||
"strength": e["strength"],
|
||||
"reason": e["reason"],
|
||||
})
|
||||
for lst in parents.values():
|
||||
lst.sort(key=lambda x: (x["strength"] != "hard", -topics.get(x["id"], {}).get("grade", 0)))
|
||||
return topics, parents
|
||||
|
||||
|
||||
def topic(kp: str | None) -> dict | None:
|
||||
"""知识点本身(没有就 None)。"""
|
||||
if not kp:
|
||||
return None
|
||||
t = _load()[0].get(kp)
|
||||
return dict(t) if t else None
|
||||
|
||||
|
||||
def parents(kp: str, strength: str | None = None) -> list[dict]:
|
||||
"""直接前置,hard 在前;每条带 name / grade / reason。"""
|
||||
topics, par = _load()
|
||||
out = []
|
||||
for p in par.get(kp or "", []):
|
||||
if strength and p["strength"] != strength:
|
||||
continue
|
||||
t = topics.get(p["id"]) or {}
|
||||
out.append({"id": p["id"], "name": t.get("name", p["id"]), "grade": t.get("grade"),
|
||||
"strength": p["strength"], "reason": p["reason"]})
|
||||
return out
|
||||
|
||||
|
||||
def chain(kp: str, limit: int = 4) -> list[dict]:
|
||||
"""沿 hard 边一路往前退,返回从根到 kp 的顺序(去掉 kp 自己)。"""
|
||||
topics, par = _load()
|
||||
path: list[dict] = []
|
||||
cur, seen = kp, {kp}
|
||||
while cur and len(path) < limit:
|
||||
hard = [p for p in par.get(cur, []) if p["strength"] == "hard"]
|
||||
if not hard:
|
||||
break
|
||||
nxt = hard[0]["id"]
|
||||
if nxt in seen:
|
||||
break
|
||||
seen.add(nxt)
|
||||
t = topics.get(nxt) or {}
|
||||
path.append({"id": nxt, "name": t.get("name", nxt), "grade": t.get("grade")})
|
||||
cur = nxt
|
||||
return list(reversed(path))
|
||||
|
||||
|
||||
def retreat(kp: str | None) -> dict | None:
|
||||
"""讲不清时该退到哪。没有知识点、或没有 hard 前置 → None(不给空建议)。"""
|
||||
t = topic(kp)
|
||||
if not t:
|
||||
return None
|
||||
hard = parents(kp, "hard")
|
||||
if not hard:
|
||||
return None
|
||||
first = hard[0]
|
||||
return {
|
||||
"kp": kp,
|
||||
"name": t["name"],
|
||||
"step": {"id": first["id"], "name": first["name"], "grade": first["grade"]},
|
||||
"reason": first["reason"],
|
||||
"chain": chain(kp),
|
||||
"tip": f"这道题讲不清,可能不是这道题的问题——先退到「{first['name']}」,"
|
||||
f"做对两道再回来讲。",
|
||||
}
|
||||
|
||||
|
||||
def validate() -> list[str]:
|
||||
"""自检:未知 id、环、前置年级比本节点还高。测试用它,别让图悄悄坏掉。"""
|
||||
topics, par = _load()
|
||||
errs: list[str] = []
|
||||
for tid, lst in par.items():
|
||||
if tid not in topics:
|
||||
errs.append(f"边指向了不存在的知识点:{tid}")
|
||||
for p in lst:
|
||||
if p["id"] not in topics:
|
||||
errs.append(f"{tid} 的前置 {p['id']} 不在 topics 里")
|
||||
elif topics[p["id"]]["grade"] > topics[tid]["grade"]:
|
||||
errs.append(f"{tid}({topics[tid]['grade']} 年级)的前置 {p['id']}"
|
||||
f"({topics[p['id']]['grade']} 年级)年级更高")
|
||||
# 环检测(沿 hard 边)
|
||||
state: dict[str, int] = {}
|
||||
|
||||
def walk(node: str, stack: list[str]) -> None:
|
||||
if state.get(node) == 1:
|
||||
errs.append("成环:" + " → ".join(stack + [node]))
|
||||
return
|
||||
if state.get(node) == 2:
|
||||
return
|
||||
state[node] = 1
|
||||
for p in par.get(node, []):
|
||||
if p["strength"] == "hard":
|
||||
walk(p["id"], stack + [node])
|
||||
state[node] = 2
|
||||
|
||||
for tid in topics:
|
||||
walk(tid, [])
|
||||
return errs
|
||||
+4
-1
@@ -19,7 +19,7 @@ from contextlib import contextmanager
|
||||
from datetime import date, datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from . import content, cut, judging, ocr, practice, scheduler, tencent_ocr, wechat
|
||||
from . import content, cut, judging, kp_graph, ocr, practice, scheduler, tencent_ocr, wechat
|
||||
from .db import TZ, add_days, connect, log_event, new_id, now, row_to_dict, rows_to_list, today
|
||||
|
||||
CONSENT_VERSION = "v1"
|
||||
@@ -994,6 +994,8 @@ def explain(conn, gid: str, cid: str, mid: str, channel: str, text: str) -> dict
|
||||
score["rubric_next_time"], int(score["passed"]), now()))
|
||||
_apply(conn, mid, state)
|
||||
log_event(conn, "explain", cid, passed=score["passed"], channel=channel)
|
||||
# 没过 → 给一条「退一层」建议:讲不清常常不是这道题的问题,是前置没打牢
|
||||
retreat = None if score["passed"] else kp_graph.retreat(dict(m).get("kp"))
|
||||
return {
|
||||
"mistake_id": mid,
|
||||
"channel": channel,
|
||||
@@ -1002,6 +1004,7 @@ def explain(conn, gid: str, cid: str, mid: str, channel: str, text: str) -> dict
|
||||
"status": state["status"],
|
||||
"status_zh": scheduler.STATUS_ZH.get(state["status"], state["status"]),
|
||||
"hint": "过了就毕业;没过就换一条路,7 天内还有机会" if not score["passed"] else "这题你不用再做了",
|
||||
"retreat": retreat,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"scope": "小学数学 1–3 年级(人教版顺序)",
|
||||
"note": "只做「退一层」用的迷你先修图:讲不清楚时,往前退到前一个知识点。不做全学段,不做自适应诊断。id 与 prototype/workbench/kpt.json 一致,前端能直接取名字。",
|
||||
"topics": [
|
||||
{ "id": "M001", "grade": 1, "name": "10以内数的认识与比较" },
|
||||
{ "id": "M002", "grade": 1, "name": "10以内加减法" },
|
||||
{ "id": "M003", "grade": 1, "name": "20以内进位加法" },
|
||||
{ "id": "M004", "grade": 1, "name": "20以内退位减法" },
|
||||
{ "id": "M005", "grade": 1, "name": "20以内连加连减" },
|
||||
{ "id": "M007", "grade": 1, "name": "100以内数的认识" },
|
||||
{ "id": "M008", "grade": 1, "name": "100以内不进位加法" },
|
||||
{ "id": "M009", "grade": 1, "name": "100以内不退位减法" },
|
||||
{ "id": "M010", "grade": 1, "name": "认识人民币" },
|
||||
{ "id": "M019", "grade": 1, "name": "100以内进位加法" },
|
||||
{ "id": "M020", "grade": 1, "name": "100以内退位减法" },
|
||||
{ "id": "M021", "grade": 1, "name": "100以内连加连减" },
|
||||
{ "id": "M022", "grade": 2, "name": "表内乘法" },
|
||||
{ "id": "M023", "grade": 2, "name": "表内除法" },
|
||||
{ "id": "M024", "grade": 2, "name": "有余数除法" },
|
||||
{ "id": "M025", "grade": 2, "name": "万以内数的认识" },
|
||||
{ "id": "M026", "grade": 2, "name": "万以内加减法" },
|
||||
{ "id": "M027", "grade": 2, "name": "乘加乘减" },
|
||||
{ "id": "M029", "grade": 2, "name": "长度单位(厘米、米)" },
|
||||
{ "id": "M037", "grade": 2, "name": "万以内连续进位加法" },
|
||||
{ "id": "M038", "grade": 2, "name": "万以内连续退位减法" },
|
||||
{ "id": "M039", "grade": 2, "name": "多位数乘一位数" },
|
||||
{ "id": "M040", "grade": 2, "name": "除数是一位数的除法" },
|
||||
{ "id": "M042", "grade": 2, "name": "分数的初步认识" },
|
||||
{ "id": "M044", "grade": 2, "name": "小数的初步认识" },
|
||||
{ "id": "M045", "grade": 2, "name": "时分秒" },
|
||||
{ "id": "M046", "grade": 2, "name": "质量单位(克、千克、吨)" },
|
||||
{ "id": "M047", "grade": 2, "name": "年月日" },
|
||||
{ "id": "M041", "grade": 3, "name": "两位数乘两位数" },
|
||||
{ "id": "M049", "grade": 3, "name": "长方形正方形周长" },
|
||||
{ "id": "M050", "grade": 3, "name": "面积与面积单位" },
|
||||
{ "id": "M051", "grade": 3, "name": "长方形正方形面积" },
|
||||
{ "id": "M055", "grade": 3, "name": "连乘连除" },
|
||||
{ "id": "M059", "grade": 3, "name": "三位数乘两位数" },
|
||||
{ "id": "M060", "grade": 3, "name": "除数是两位数的除法" },
|
||||
{ "id": "M061", "grade": 3, "name": "四则运算顺序" },
|
||||
{ "id": "M063", "grade": 3, "name": "小数的意义与性质" },
|
||||
{ "id": "M064", "grade": 3, "name": "小数加减法" },
|
||||
{ "id": "M066", "grade": 3, "name": "单位换算(小数)" }
|
||||
],
|
||||
"edges": [
|
||||
{ "topicId": "M002", "prerequisiteId": "M001", "strength": "hard", "reason": "不会数、不会比大小,加减法就没有实物意义" },
|
||||
{ "topicId": "M003", "prerequisiteId": "M002", "strength": "hard", "reason": "进位加法是「凑十」,前提是 10 以内加减能算准" },
|
||||
{ "topicId": "M004", "prerequisiteId": "M002", "strength": "hard", "reason": "退位减法同样是凑十,反向用" },
|
||||
{ "topicId": "M005", "prerequisiteId": "M003", "strength": "hard", "reason": "连加连减一步一步算,第一步就要进位加法" },
|
||||
{ "topicId": "M005", "prerequisiteId": "M004", "strength": "hard", "reason": "连减中间要退位,退位不准后面全错" },
|
||||
{ "topicId": "M007", "prerequisiteId": "M001", "strength": "hard", "reason": "100 以内数是 10 以内数的扩展,数位概念从那里来" },
|
||||
{ "topicId": "M008", "prerequisiteId": "M007", "strength": "hard", "reason": "竖式加法要对齐数位,先得认十位个位" },
|
||||
{ "topicId": "M008", "prerequisiteId": "M002", "strength": "hard", "reason": "每一位上算的仍是 10 以内加减" },
|
||||
{ "topicId": "M009", "prerequisiteId": "M007", "strength": "hard", "reason": "不退位减法同样靠数位对齐" },
|
||||
{ "topicId": "M009", "prerequisiteId": "M002", "strength": "hard", "reason": "每一位上的减法还是 10 以内" },
|
||||
{ "topicId": "M019", "prerequisiteId": "M003", "strength": "hard", "reason": "100 以内进位和 20 以内进位是同一件事,只是位数更多" },
|
||||
{ "topicId": "M019", "prerequisiteId": "M008", "strength": "hard", "reason": "先会不进位竖式,才知道多出来的 1 记在哪" },
|
||||
{ "topicId": "M020", "prerequisiteId": "M004", "strength": "hard", "reason": "退位减法的方法与 20 以内一致" },
|
||||
{ "topicId": "M020", "prerequisiteId": "M009", "strength": "hard", "reason": "先会不退位,再看借位怎么标" },
|
||||
{ "topicId": "M021", "prerequisiteId": "M019", "strength": "hard", "reason": "连加连减中间结果要用进位加法" },
|
||||
{ "topicId": "M021", "prerequisiteId": "M020", "strength": "hard", "reason": "连减中间结果要用退位减法" },
|
||||
{ "topicId": "M010", "prerequisiteId": "M007", "strength": "soft", "reason": "元角分是 100 以内数的应用" },
|
||||
{ "topicId": "M022", "prerequisiteId": "M005", "strength": "hard", "reason": "乘法是相同加数连加的简写,连加不熟就看不懂口诀" },
|
||||
{ "topicId": "M027", "prerequisiteId": "M022", "strength": "hard", "reason": "乘加乘减要先算乘法,乘法口诀得背熟" },
|
||||
{ "topicId": "M023", "prerequisiteId": "M022", "strength": "hard", "reason": "除法是乘法的逆运算,口诀不熟就试不出商" },
|
||||
{ "topicId": "M024", "prerequisiteId": "M023", "strength": "hard", "reason": "有余数除法是表内除法加余数,先会整除" },
|
||||
{ "topicId": "M024", "prerequisiteId": "M022", "strength": "soft", "reason": "试商仍然靠乘法口诀" },
|
||||
{ "topicId": "M025", "prerequisiteId": "M007", "strength": "hard", "reason": "万以内数是数位概念的再一次扩展" },
|
||||
{ "topicId": "M026", "prerequisiteId": "M025", "strength": "hard", "reason": "万以内加减要先认数位和数级" },
|
||||
{ "topicId": "M026", "prerequisiteId": "M021", "strength": "hard", "reason": "竖式加减的每一步仍是 100 以内的进位/退位" },
|
||||
{ "topicId": "M029", "prerequisiteId": "M007", "strength": "soft", "reason": "量长度要先会读数" },
|
||||
{ "topicId": "M029", "prerequisiteId": "M010", "strength": "soft", "reason": "单位换算的直觉最早来自元角分" },
|
||||
{ "topicId": "M037", "prerequisiteId": "M019", "strength": "hard", "reason": "连续进位 = 连续两次进位加法" },
|
||||
{ "topicId": "M037", "prerequisiteId": "M008", "strength": "hard", "reason": "多位竖式的对齐规则来自不进位加法" },
|
||||
{ "topicId": "M038", "prerequisiteId": "M020", "strength": "hard", "reason": "连续退位 = 连续两次退位减法" },
|
||||
{ "topicId": "M038", "prerequisiteId": "M009", "strength": "hard", "reason": "对齐规则同样来自不退位减法" },
|
||||
{ "topicId": "M039", "prerequisiteId": "M022", "strength": "hard", "reason": "多位数乘一位数,每一步都是口诀 + 进位" },
|
||||
{ "topicId": "M039", "prerequisiteId": "M037", "strength": "soft", "reason": "乘完要把各层积加起来,进位加法不熟就会错在最后一步" },
|
||||
{ "topicId": "M040", "prerequisiteId": "M023", "strength": "hard", "reason": "除数是一位数的除法,试商仍靠乘法口诀" },
|
||||
{ "topicId": "M040", "prerequisiteId": "M024", "strength": "soft", "reason": "有余数的处理方式与有余数除法一致" },
|
||||
{ "topicId": "M042", "prerequisiteId": "M023", "strength": "hard", "reason": "分数是「平均分」,不理解为啥分就只会背" },
|
||||
{ "topicId": "M044", "prerequisiteId": "M010", "strength": "soft", "reason": "小数最早从元角分(0.5 元)认识" },
|
||||
{ "topicId": "M044", "prerequisiteId": "M042", "strength": "soft", "reason": "十分之几写成一位小数,靠分数的初步认识" },
|
||||
{ "topicId": "M045", "prerequisiteId": "M007", "strength": "hard", "reason": "看钟面要读 60 以内的数" },
|
||||
{ "topicId": "M045", "prerequisiteId": "M010", "strength": "soft", "reason": "60 进制换算的直觉与元角分同类" },
|
||||
{ "topicId": "M046", "prerequisiteId": "M010", "strength": "soft", "reason": "质量单位换算与人民币换算同一个思路" },
|
||||
{ "topicId": "M047", "prerequisiteId": "M025", "strength": "soft", "reason": "年月的天数要数到 31,先认大数" },
|
||||
{ "topicId": "M041", "prerequisiteId": "M039", "strength": "hard", "reason": "两位数乘两位数就是两次多位数乘一位数再相加" },
|
||||
{ "topicId": "M041", "prerequisiteId": "M022", "strength": "hard", "reason": "每一位上都是口诀" },
|
||||
{ "topicId": "M049", "prerequisiteId": "M026", "strength": "hard", "reason": "算周长就是各边相加,万以内加减要熟" },
|
||||
{ "topicId": "M050", "prerequisiteId": "M029", "strength": "soft", "reason": "面积单位从长度单位推出来(厘米→平方厘米)" },
|
||||
{ "topicId": "M051", "prerequisiteId": "M050", "strength": "hard", "reason": "不会面积单位,套公式也只是背" },
|
||||
{ "topicId": "M051", "prerequisiteId": "M041", "strength": "hard", "reason": "长×宽通常是两位数乘法" },
|
||||
{ "topicId": "M055", "prerequisiteId": "M039", "strength": "soft", "reason": "连乘连除每一步都是乘一位数或除一位数" },
|
||||
{ "topicId": "M055", "prerequisiteId": "M040", "strength": "soft", "reason": "连除靠除法的熟练度" },
|
||||
{ "topicId": "M059", "prerequisiteId": "M041", "strength": "hard", "reason": "三位数乘两位数与两位数乘两位数同一套层积法" },
|
||||
{ "topicId": "M059", "prerequisiteId": "M039", "strength": "hard", "reason": "每一层仍是多位数乘一位数" },
|
||||
{ "topicId": "M060", "prerequisiteId": "M040", "strength": "hard", "reason": "除数是两位数,只是试商更难,方法一样" },
|
||||
{ "topicId": "M061", "prerequisiteId": "M021", "strength": "hard", "reason": "规定运算顺序之前,先得会按顺序算连加连减" },
|
||||
{ "topicId": "M061", "prerequisiteId": "M055", "strength": "soft", "reason": "同级从左往右的规则,从连乘连除开始熟悉" },
|
||||
{ "topicId": "M063", "prerequisiteId": "M044", "strength": "hard", "reason": "小数的意义是初步认识的加深,跳不过去" },
|
||||
{ "topicId": "M064", "prerequisiteId": "M063", "strength": "hard", "reason": "不认小数位值,加减就没法对齐" },
|
||||
{ "topicId": "M064", "prerequisiteId": "M044", "strength": "hard", "reason": "小数加减靠初步认识里的「元角分」直觉" },
|
||||
{ "topicId": "M066", "prerequisiteId": "M050", "strength": "hard", "reason": "小数单位换算大多发生在面积、长度这类单位上" },
|
||||
{ "topicId": "M066", "prerequisiteId": "M063", "strength": "hard", "reason": "换算就是小数点移位,靠小数的意义" }
|
||||
]
|
||||
}
|
||||
@@ -167,3 +167,22 @@ prototype/workbench/index.html ← 全部代码都在这一个文件里
|
||||
|
||||
- 解析:`1/4×3/5` 这类会走分数专线(分子乘分子 / 分母乘分母 / 约分),不再是「先看个位」。
|
||||
- 判分:孩子写 `3/20`、`0.15`、`0.150` 都算对;写 `0.1` 会提示「应为 3/20,你写的是 1/10」。
|
||||
|
||||
## 十一、讲一遍,讲不清就退一层
|
||||
|
||||
两个入口,同一张弹窗:
|
||||
|
||||
- 错题本里状态是「待讲清」的题,行尾有「讲一遍」
|
||||
- 今日训练连对两次后,结果框里就地出现「现在讲一遍」(不用回去翻错题本)
|
||||
|
||||
弹窗里三件事:这道题(原题)、讲的方式(说步骤 / 找出错处 / 自己出一道)、
|
||||
一段话。提交后走 `POST /api/mistakes/<id>/explain`,回来的是 rubric 与过没过。
|
||||
|
||||
**没过的时候多一张卡片「退一层」**:这不是安慰话,是判断——讲不清常常不是这道题的问题,
|
||||
是前置知识没打牢(`36 × 24` 讲不清,往往是 `表内乘法` 或 `多位数乘一位数` 不熟)。
|
||||
卡片上写清三样:退到哪个知识点(几年级)、为什么退到这(一句人话)、
|
||||
从根到它的那条路(`20以内连加连减 → 表内乘法 → 多位数乘一位数`)。
|
||||
数据与边界见 `backend/README.md` 四点二十四。
|
||||
|
||||
演示模式(`file://` 直接打开)不联网,用一个假批改:说够 12 个字算过,不够就出「退一层」卡片,
|
||||
方便看界面。真正接后端时,卡片内容全部来自接口的 `retreat`,前端不带任何知识点数据。
|
||||
|
||||
@@ -398,6 +398,36 @@ td .t{font-family:"Consolas",monospace;font-size:13.5px}
|
||||
.scan-box i { position: absolute; top: -9px; left: -9px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 1.5px solid rgba(228,99,74,.55); color: #B4482F; font-style: normal; font-size: 11px; line-height: 17px; text-align: center; font-weight: 700; }
|
||||
.scan-box.on i { background: var(--brand); border-color: var(--brand-d); color: #fff; }
|
||||
.scan-legend { margin-top: 12px; font-size: 12px; color: var(--muted); }
|
||||
|
||||
/* ---- 讲一遍 ---- */
|
||||
.exdlg { position: relative; width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto;
|
||||
background: #FFFDF8; border-radius: 18px; padding: 24px 26px 22px; box-shadow: 0 24px 60px rgba(70,50,28,.28); }
|
||||
.exdlg h3 { margin: 0 0 6px; font-size: 18px; }
|
||||
.ex-sub { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
|
||||
.ex-x { position: absolute; right: 14px; top: 12px; border: 0; background: none; font-size: 22px;
|
||||
line-height: 1; color: #B5A99A; cursor: pointer; }
|
||||
.ex-stem { font-family: Consolas, monospace; font-size: 15px; background: #FFF6E6; border: 1px solid #F1E3CB;
|
||||
border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; word-break: break-all; }
|
||||
.ex-ch { margin-bottom: 10px; }
|
||||
.exdlg textarea { width: 100%; box-sizing: border-box; min-height: 96px; resize: vertical; font-size: 14px;
|
||||
line-height: 1.7; padding: 12px 14px; border: 1px solid #E8DCC8; border-radius: 12px; background: #fff;
|
||||
font-family: inherit; color: var(--ink); }
|
||||
.exdlg textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(228,99,74,.12); }
|
||||
.ex-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
|
||||
.ex-hint { font-size: 12px; color: var(--muted); }
|
||||
.ex-result { margin-top: 14px; font-size: 13px; line-height: 1.8; border-radius: 12px; padding: 12px 14px; }
|
||||
.ex-result.ok { background: var(--green-soft); border: 1px solid #CFE4D3; color: #2E5B3C; }
|
||||
.ex-result.no { background: #FDECE8; border: 1px solid #F6D5CC; color: #8C3A25; }
|
||||
.ex-result b { display: block; margin-bottom: 4px; }
|
||||
.ex-result .rub { margin-top: 8px; font-size: 12.5px; color: #6B6157; }
|
||||
.retreat { margin-top: 12px; background: #FFF7E8; border: 1px solid #EFDCAE; border-radius: 12px;
|
||||
padding: 13px 15px; font-size: 13px; line-height: 1.8; color: #7A5410; }
|
||||
.retreat .rt-h { font-weight: 700; margin-bottom: 4px; }
|
||||
.retreat .rt-step { display: inline-block; background: #fff; border: 1px solid #E9D3A2; border-radius: 8px;
|
||||
padding: 2px 9px; font-weight: 700; margin: 2px 0; }
|
||||
.retreat .rt-why { color: #8A6A3E; font-size: 12.5px; }
|
||||
.retreat .rt-chain { color: #A07C46; font-size: 12px; margin-top: 6px; }
|
||||
.retreat .rt-go { margin-top: 10px; }
|
||||
.toast { position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%) translateY(12px);
|
||||
background: #2B2622; color: #fff; font-size: 13.5px; padding: 10px 18px; border-radius: 999px;
|
||||
box-shadow: 0 8px 22px rgba(0,0,0,.18); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 90; }
|
||||
@@ -872,6 +902,27 @@ td .t{font-family:"Consolas",monospace;font-size:13.5px}
|
||||
<p class="lg-note">用微信扫一扫 → 小程序里点「确认登录」。<br />孩子不用注册,这里登录的是家长,账户和小程序是同一个。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mask" id="explainMask">
|
||||
<div class="exdlg">
|
||||
<button class="ex-x" id="exClose" aria-label="关闭">×</button>
|
||||
<h3>讲一遍</h3>
|
||||
<p class="ex-sub">不用讲得像老师。三句话说清:错在哪、正确怎么走、下次怎么防。</p>
|
||||
<div class="ex-stem" id="exStem"></div>
|
||||
<div class="chips ex-ch" id="exChannels">
|
||||
<button class="on" data-c="steps">说步骤</button>
|
||||
<button data-c="find_error">找出错处</button>
|
||||
<button data-c="make_question">自己出一道</button>
|
||||
</div>
|
||||
<textarea id="exText" placeholder="例:我进位忘了加 1,应该先算个位 6+7=13,写 3 记 1……"></textarea>
|
||||
<div class="ex-row">
|
||||
<button class="btn" id="exGo">就讲这些</button>
|
||||
<span class="ex-hint" id="exHint">讲清楚就行,不用长</span>
|
||||
</div>
|
||||
<div class="ex-result" id="exResult" hidden></div>
|
||||
<div class="retreat" id="exRetreat" hidden></div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
/* ================= 数据层 ================= */
|
||||
const API = (location.protocol === "file:") ? "http://127.0.0.1:8000" : "";
|
||||
@@ -904,7 +955,8 @@ const DEMO = {
|
||||
mistakes: [
|
||||
{ id: "m1", stem: "36 + 47 =", subject: "math", status: "queued", status_zh: "待复习", wrong_code: "E3", next_due: "今天" },
|
||||
{ id: "m2", stem: "82 - 35 =", subject: "math", status: "queued", status_zh: "待复习", wrong_code: "E4", next_due: "今天" },
|
||||
{ id: "m3", stem: "看拼音写词:xióng māo", subject: "chinese", status: "to_explain", status_zh: "待讲清", wrong_code: "E2", next_due: "今天" },
|
||||
{ id: "m3", stem: "看拼音写词:xióng māo", subject: "chinese", status: "to_explain", status_zh: "待讲清", wrong_code: "E2", next_due: "今天", kp: "M042" },
|
||||
{ id: "m12", stem: "36 × 24 =", subject: "math", status: "to_explain", status_zh: "待讲清", wrong_code: "E2", next_due: "今天", kp: "M041" },
|
||||
{ id: "m6", stem: "45 ÷ 5 =", subject: "math", status: "graduated", status_zh: "已毕业", wrong_code: "E3", next_due: "—" },
|
||||
{ id: "m7", stem: "600 - 247 =", subject: "math", status: "graduated", status_zh: "已毕业", wrong_code: "E4", next_due: "—" },
|
||||
{ id: "m8", stem: "填量词:一( )书", subject: "chinese", status: "careless", status_zh: "粗心小记", wrong_code: "E4", next_due: "—" },
|
||||
@@ -1604,7 +1656,7 @@ async function submit() {
|
||||
else document.getElementById("qInput").focus();
|
||||
return;
|
||||
}
|
||||
let correct = null, detail = "", unstableHint = null;
|
||||
let correct = null, detail = "", unstableHint = null, nextStatus = "";
|
||||
if (S.demo) {
|
||||
if (isChoice) {
|
||||
correct = String(q.answer || "").toUpperCase() === val;
|
||||
@@ -1618,6 +1670,7 @@ async function submit() {
|
||||
const r = await api(`/api/mistakes/${q.id}/attempt`, { method: "POST", body: { child_id: S.cid, answer: val } });
|
||||
correct = r.correct; detail = r.detail || "";
|
||||
unstableHint = r.unstable_hint || null;
|
||||
nextStatus = r.status || "";
|
||||
q.status_zh = r.status_zh;
|
||||
if (r.answer != null) q.answer = String(r.answer);
|
||||
if (r.judge_type) q.judge_type = r.judge_type;
|
||||
@@ -1641,6 +1694,11 @@ async function submit() {
|
||||
// 当天错了又对:不装作过了,也不打击——说清楚「明天再来一次」
|
||||
box.className = "result mid";
|
||||
box.innerHTML = `<b>会了,但还不稳</b><br>${esc(unstableHint)}`;
|
||||
} else if (nextStatus === "to_explain") {
|
||||
// 连对两次,到了「讲一遍」这一步——就地把入口放在结果里,不用回去翻错题本
|
||||
box.className = "result mid";
|
||||
box.innerHTML = `<b>连对两次,该讲一遍了</b><br>用三句话说清错因,讲清才算毕业。
|
||||
<div style="margin-top:10px"><button class="btn ex-now" data-id="${esc(q.id)}">现在讲一遍</button></div>`;
|
||||
} else {
|
||||
box.innerHTML = `<b>对了</b><br>${esc(detail || "连续两次做对,就进「讲清」。")}`;
|
||||
}
|
||||
@@ -1733,16 +1791,106 @@ function norm(s) { return String(s).replace(/\s/g, "").replace(/[。,,.]/g, ""
|
||||
function renderWrong() {
|
||||
const rows = S.mistakes.filter(m => !S.wrongFilter || m.status === S.wrongFilter);
|
||||
document.getElementById("wrongTable").innerHTML = `
|
||||
<tr><th>题目</th><th>科目</th><th>错因</th><th>状态</th><th>下次复习</th></tr>` +
|
||||
<tr><th>题目</th><th>科目</th><th>错因</th><th>状态</th><th>下次复习</th><th></th></tr>` +
|
||||
rows.map(m => `<tr>
|
||||
<td class="t">${esc(m.stem)}</td>
|
||||
<td>${SUBJ[m.subject] || "数学"}</td>
|
||||
<td>${m.wrong_code ? `<span class="pill gray">${m.wrong_code}</span>` : "—"}</td>
|
||||
<td><span class="pill ${STATUS_CLS[m.status] || ""}">${m.status_zh || m.status}</span></td>
|
||||
<td style="color:var(--muted)">${m.next_due || "—"}</td>
|
||||
<td>${m.status === "to_explain" ? `<button class="lnk ex-open" data-id="${esc(m.id)}">讲一遍</button>` : ""}</td>
|
||||
</tr>`).join("");
|
||||
}
|
||||
|
||||
/* ---- 讲一遍(讲清才算毕业;讲不清就给「退一层」) ---- */
|
||||
let EX = { mid: null, channel: "steps" };
|
||||
|
||||
function openExplain(mid) {
|
||||
const m = S.mistakes.find(x => x.id === mid) || S.queue.find(x => x.id === mid);
|
||||
if (!m) return;
|
||||
EX = { mid, channel: "steps" };
|
||||
document.getElementById("exStem").textContent = m.stem || "";
|
||||
document.getElementById("exText").value = "";
|
||||
document.getElementById("exHint").textContent = "讲清楚就行,不用长";
|
||||
document.getElementById("exResult").hidden = true;
|
||||
document.getElementById("exRetreat").hidden = true;
|
||||
document.querySelectorAll("#exChannels button").forEach(b => b.classList.toggle("on", b.dataset.c === "steps"));
|
||||
document.getElementById("explainMask").classList.add("show");
|
||||
setTimeout(() => document.getElementById("exText").focus(), 30);
|
||||
}
|
||||
|
||||
function closeExplain() {
|
||||
document.getElementById("explainMask").classList.remove("show");
|
||||
}
|
||||
|
||||
/* 演示模式下的假批改:说够 12 个字算过;不够就给「退一层」看效果 */
|
||||
const DEMO_RETREAT = {
|
||||
M041: { step: { id: "M039", name: "多位数乘一位数", grade: 2 },
|
||||
reason: "两位数乘两位数就是两次多位数乘一位数再相加",
|
||||
chain: [{ id: "M005", name: "20以内连加连减", grade: 1 },
|
||||
{ id: "M022", name: "表内乘法", grade: 2 },
|
||||
{ id: "M039", name: "多位数乘一位数", grade: 2 }],
|
||||
tip: "这道题讲不清,可能不是这道题的问题——先退到「多位数乘一位数」,做对两道再回来讲。" },
|
||||
M042: { step: { id: "M023", name: "表内除法", grade: 2 },
|
||||
reason: "分数是「平均分」,不理解为啥分就只会背",
|
||||
chain: [{ id: "M022", name: "表内乘法", grade: 2 }],
|
||||
tip: "这道题讲不清,可能不是这道题的问题——先退到「表内除法」,做对两道再回来讲。" },
|
||||
};
|
||||
|
||||
async function submitExplain() {
|
||||
const text = document.getElementById("exText").value.trim();
|
||||
const go = document.getElementById("exGo");
|
||||
if (!text) { document.getElementById("exHint").textContent = "先写两句,讲讲错在哪"; return; }
|
||||
go.disabled = true; go.textContent = "批改中…";
|
||||
try {
|
||||
let r;
|
||||
if (S.demo) {
|
||||
const passed = text.length >= 12;
|
||||
const m = S.mistakes.find(x => x.id === EX.mid) || {};
|
||||
r = { passed, status: passed ? "graduated" : "to_explain",
|
||||
rubric: { wrong_reason: "没说清错在哪", key_steps: "先算个位再算十位,进位别忘", next_time: "下次先圈进位" },
|
||||
hint: passed ? "这题你不用再做了" : "没过就换个说法,7 天内还有机会",
|
||||
retreat: passed ? null : (DEMO_RETREAT[m.kp] || null) };
|
||||
} else {
|
||||
r = await api(`/api/mistakes/${encodeURIComponent(EX.mid)}/explain`,
|
||||
{ method: "POST", body: { channel: EX.channel, text } });
|
||||
}
|
||||
renderExplain(r);
|
||||
} catch (e) {
|
||||
document.getElementById("exHint").textContent = "没发出去:" + e.message;
|
||||
} finally {
|
||||
go.disabled = false; go.textContent = "就讲这些";
|
||||
}
|
||||
}
|
||||
|
||||
function renderExplain(r) {
|
||||
const box = document.getElementById("exResult");
|
||||
box.hidden = false;
|
||||
box.className = "ex-result " + (r.passed ? "ok" : "no");
|
||||
const rub = r.rubric || {};
|
||||
const next = String(rub.next_time || "做完回头对一遍");
|
||||
box.innerHTML = r.passed
|
||||
? `<b>过了,这题毕业</b>${esc(r.hint || "")}`
|
||||
: `<b>还差一点</b>${esc(r.hint || "")}
|
||||
<div class="rub">差在:${esc(rub.wrong_reason || "没说清错因")}<br>
|
||||
该有的一步:${esc(rub.key_steps || "先算哪一步、再算哪一步")}<br>
|
||||
${/^下次/.test(next) ? "" : "下次:"}${esc(next)}</div>`;
|
||||
// 讲不清 → 退一层:问的不是这道题,是这道题背后的前置
|
||||
const rt = document.getElementById("exRetreat");
|
||||
const q = r.retreat;
|
||||
if (!q) { rt.hidden = true; return; }
|
||||
rt.hidden = false;
|
||||
const chain = (q.chain || []).map(c => esc(c.name)).join(" → ");
|
||||
rt.innerHTML = `
|
||||
<div class="rt-h">退一层:先补「${esc(q.step.name)}」</div>
|
||||
<div class="rt-step">${esc(q.step.name)}${q.step.grade ? ` ${q.step.grade} 年级` : ""}</div>
|
||||
<div class="rt-why">为什么退到这:${esc(q.reason || "")}</div>
|
||||
${chain ? `<div class="rt-chain">这条路:${chain}</div>` : ""}
|
||||
<div class="rt-go"><span style="font-size:12.5px">${esc(q.tip || "")}</span></div>`;
|
||||
if (S.demo) return;
|
||||
document.getElementById("exRetreat").dataset.kp = q.step.id;
|
||||
}
|
||||
|
||||
function renderPlan() {
|
||||
const byDay = {};
|
||||
S.mistakes.filter(m => m.status !== "graduated" && m.status !== "careless").forEach(m => {
|
||||
@@ -1864,6 +2012,24 @@ document.getElementById("wrongChips").addEventListener("click", (e) => {
|
||||
document.querySelectorAll("#wrongChips button").forEach(x => x.classList.toggle("on", x === b));
|
||||
S.wrongFilter = b.dataset.s; renderWrong();
|
||||
});
|
||||
document.getElementById("wrongTable").addEventListener("click", (e) => {
|
||||
const b = e.target.closest(".ex-open"); if (!b) return;
|
||||
openExplain(b.dataset.id);
|
||||
});
|
||||
document.getElementById("qResult").addEventListener("click", (e) => {
|
||||
const b = e.target.closest(".ex-now"); if (!b) return;
|
||||
openExplain(b.dataset.id);
|
||||
});
|
||||
document.getElementById("exClose").addEventListener("click", closeExplain);
|
||||
document.getElementById("explainMask").addEventListener("click", (e) => {
|
||||
if (e.target.id === "explainMask") closeExplain();
|
||||
});
|
||||
document.getElementById("exChannels").addEventListener("click", (e) => {
|
||||
const b = e.target.closest("button"); if (!b) return;
|
||||
EX.channel = b.dataset.c;
|
||||
document.querySelectorAll("#exChannels button").forEach(x => x.classList.toggle("on", x === b));
|
||||
});
|
||||
document.getElementById("exGo").addEventListener("click", submitExplain);
|
||||
document.getElementById("kidsList").addEventListener("click", async (e) => {
|
||||
const b = e.target.closest("[data-kid]"); if (!b) return;
|
||||
S.cid = b.dataset.kid; localStorage.setItem("ql_child", S.cid);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
@@ -6,10 +6,15 @@
|
||||
|
||||
挑法:先看 QINGLING_TEST_TMP,再试系统临时目录,最后才退到仓库内;
|
||||
每个候选都真建一次 sqlite 文件,确认「能读能写能建库」才采用。
|
||||
|
||||
退到仓库内(沙箱不许写系统临时目录时)会先把 `tests/_tmp` 清空:那里的库是
|
||||
上一次跑的,里面**体验授权早就过期**,留着会让 `require_active` 报
|
||||
`ENTITLEMENT_EXPIRED`,看起来像代码坏了,其实是旧数据。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sqlite3
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
@@ -50,6 +55,8 @@ def workdir(name: str = "shared") -> Path:
|
||||
break
|
||||
else: # pragma: no cover
|
||||
raise RuntimeError("找不到可写的测试目录,请设置 QINGLING_TEST_TMP")
|
||||
if _PICKED == Path(__file__).resolve().parent / "_tmp":
|
||||
shutil.rmtree(_PICKED, ignore_errors=True) # 清掉上一次的旧库(授权会过期)
|
||||
p = _PICKED / name
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
return p
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""端到端核对:网页登录(手机号 + 验证码)+ 通知列表(临时库、临时端口)。"""
|
||||
"""端到端核对:网页登录(手机号 + 验证码)+ 通知列表(临时库、临时端口)。"""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@@ -64,7 +64,7 @@ try:
|
||||
|
||||
st, r = call("GET", "/api/health")
|
||||
check("health 200", st == 200, r)
|
||||
check("routes=58", r["data"]["routes"] == 58, r["data"].get("routes"))
|
||||
check("routes=59", r["data"]["routes"] == 59, r["data"].get("routes"))
|
||||
|
||||
st, r = call("POST", "/api/auth/sms-code", {"phone": "13800138000"})
|
||||
check("发码 200", st == 200 and r["data"]["sent"] is True, r)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""端到端核对:手输一道题 + 删号冷静期(跑在临时库和临时端口上,不碰演示数据)。"""
|
||||
"""端到端核对:手输一道题 + 删号冷静期(跑在临时库和临时端口上,不碰演示数据)。"""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@@ -63,7 +63,7 @@ try:
|
||||
|
||||
st, r = call("GET", "/api/health")
|
||||
check("health 200", st == 200, r)
|
||||
check("routes=58", r["data"]["routes"] == 58, r["data"].get("routes"))
|
||||
check("routes=59", r["data"]["routes"] == 59, r["data"].get("routes"))
|
||||
|
||||
st, r = call("POST", "/api/auth/wx-login", {"code": "demo"})
|
||||
tok = r["data"]["token"]
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""迷你先修图:图别坏、退一层别退错、没有前置就别瞎给建议。
|
||||
|
||||
跑:python -m unittest tests.test_kp_graph -v
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from _tmpdir import workdir as _workdir # noqa: E402
|
||||
|
||||
from backend import db as dbm # noqa: E402
|
||||
from backend import kp_graph # noqa: E402
|
||||
from backend import services as svc # noqa: E402
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
class GraphShapeTest(unittest.TestCase):
|
||||
def test_validate_is_clean(self):
|
||||
"""自检要干净:没有未知 id、没有环、前置不比本节点年级高。"""
|
||||
self.assertEqual(kp_graph.validate(), [])
|
||||
|
||||
def test_every_node_exists_in_kpt(self):
|
||||
"""图里的 id 必须在工作台知识点表里,否则前端取不到名字。"""
|
||||
kpt = json.loads((ROOT / "prototype" / "workbench" / "kpt.json").read_text(encoding="utf-8"))
|
||||
topics, _ = kp_graph._load()
|
||||
missing = sorted(set(topics) - set(kpt))
|
||||
self.assertEqual(missing, [], f"这些知识点在 kpt.json 里找不到:{missing}")
|
||||
|
||||
def test_size_is_mini(self):
|
||||
"""迷你图就该迷你:30–60 个点、40–90 条边。"""
|
||||
topics, par = kp_graph._load()
|
||||
self.assertTrue(30 <= len(topics) <= 60, len(topics))
|
||||
self.assertTrue(40 <= sum(len(v) for v in par.values()) <= 90)
|
||||
|
||||
def test_every_edge_has_reason(self):
|
||||
"""每条边都要写人话理由——家长点开要能看懂「为什么退到这」。"""
|
||||
_, par = kp_graph._load()
|
||||
for tid, lst in par.items():
|
||||
for p in lst:
|
||||
self.assertTrue(p["reason"].strip(), f"{tid}←{p['id']} 没写理由")
|
||||
|
||||
|
||||
class ParentsTest(unittest.TestCase):
|
||||
def test_hard_first(self):
|
||||
ps = kp_graph.parents("M041") # 两位数乘两位数
|
||||
self.assertEqual(ps[0]["id"], "M039") # 多位数乘一位数
|
||||
self.assertEqual(ps[0]["strength"], "hard")
|
||||
|
||||
def test_filter_by_strength(self):
|
||||
soft = kp_graph.parents("M044", "soft") # 小数的初步认识
|
||||
self.assertTrue(soft)
|
||||
self.assertTrue(all(p["strength"] == "soft" for p in soft))
|
||||
|
||||
def test_no_parents_for_root(self):
|
||||
self.assertEqual(kp_graph.parents("M001"), [])
|
||||
|
||||
def test_unknown_kp_is_empty(self):
|
||||
self.assertEqual(kp_graph.parents("NOPE"), [])
|
||||
self.assertIsNone(kp_graph.topic("NOPE"))
|
||||
|
||||
|
||||
class RetreatTest(unittest.TestCase):
|
||||
def test_retreat_points_to_prerequisite(self):
|
||||
r = kp_graph.retreat("M041")
|
||||
self.assertEqual(r["step"]["id"], "M039")
|
||||
self.assertEqual(r["step"]["name"], "多位数乘一位数")
|
||||
self.assertEqual(r["name"], "两位数乘两位数")
|
||||
self.assertIn("多位数乘一位数", r["tip"])
|
||||
self.assertIn("讲不清", r["tip"])
|
||||
|
||||
def test_root_has_no_retreat(self):
|
||||
"""最底层的知识点没有前置,就别给建议(给了也是空话)。"""
|
||||
self.assertIsNone(kp_graph.retreat("M001"))
|
||||
self.assertIsNone(kp_graph.retreat(None))
|
||||
self.assertIsNone(kp_graph.retreat("NOPE"))
|
||||
|
||||
def test_chain_is_ordered_from_root(self):
|
||||
ch = kp_graph.chain("M059") # 三位数乘两位数
|
||||
self.assertEqual([c["id"] for c in ch], ["M005", "M022", "M039", "M041"])
|
||||
grades = [c["grade"] for c in ch]
|
||||
self.assertEqual(grades, sorted(grades))
|
||||
|
||||
def test_chain_respects_limit(self):
|
||||
self.assertLessEqual(len(kp_graph.chain("M059", limit=2)), 2)
|
||||
|
||||
|
||||
class ExplainRetreatTest(unittest.TestCase):
|
||||
"""讲不清时接口要把「退一层」带出来;讲清了就别带。"""
|
||||
|
||||
def setUp(self):
|
||||
tmp = _workdir("shared")
|
||||
tmp.mkdir(exist_ok=True)
|
||||
self.path = tmp / f"kpg_{id(self)}.db"
|
||||
self.conn = dbm.connect(self.path)
|
||||
dbm.init_db(self.conn)
|
||||
self.gid = svc.login(self.conn, "demo")["guardian_id"]
|
||||
svc.give_consent(self.conn, self.gid)
|
||||
self.cid = svc.create_child(self.conn, self.gid, "皮皮", 3)["id"]
|
||||
svc.add_manual_mistake(self.conn, self.gid, self.cid, "math",
|
||||
"36 × 24 =", answer="864", kp="M041")
|
||||
|
||||
def tearDown(self):
|
||||
self.conn.close()
|
||||
for suffix in ("", "-wal", "-shm"):
|
||||
f = Path(str(self.path) + suffix)
|
||||
if f.exists():
|
||||
try:
|
||||
f.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _ready(self):
|
||||
"""连错三次 → 入库;再模拟两天各做对一次 → 到「讲清」。"""
|
||||
mid = self.conn.execute("SELECT id FROM mistakes WHERE child_id=?", (self.cid,)).fetchone()["id"]
|
||||
for _ in range(3):
|
||||
svc.attempt(self.conn, self.gid, self.cid, mid, "800")
|
||||
for _ in range(2):
|
||||
self.conn.execute("UPDATE attempts SET created_at=? WHERE mistake_id=?",
|
||||
(dbm.add_days(-2) + "T20:00:00", mid))
|
||||
svc.attempt(self.conn, self.gid, self.cid, mid, "864")
|
||||
svc.dev_advance(self.conn, 2)
|
||||
row = self.conn.execute("SELECT * FROM mistakes WHERE id=?", (mid,)).fetchone()
|
||||
return mid, row
|
||||
|
||||
def test_failed_explain_carries_retreat(self):
|
||||
mid, row = self._ready()
|
||||
self.assertEqual(row["status"], "to_explain")
|
||||
self.assertEqual(row["kp"], "M041")
|
||||
r = svc.explain(self.conn, self.gid, self.cid, mid, "steps", "我不会")
|
||||
self.assertFalse(r["passed"])
|
||||
self.assertIsNotNone(r["retreat"])
|
||||
self.assertEqual(r["retreat"]["step"]["id"], "M039")
|
||||
|
||||
def test_no_kp_means_no_retreat(self):
|
||||
"""没有知识点归类的题,不给退一层——宁可不说,也别乱指。"""
|
||||
svc.add_manual_mistake(self.conn, self.gid, self.cid, "math", "涂一涂", answer="略")
|
||||
mid = self.conn.execute("SELECT id FROM mistakes WHERE stem=?", ("涂一涂",)).fetchone()["id"]
|
||||
self.conn.execute("UPDATE mistakes SET status='to_explain', stage=2 WHERE id=?", (mid,))
|
||||
r = svc.explain(self.conn, self.gid, self.cid, mid, "steps", "我不会")
|
||||
self.assertFalse(r["passed"])
|
||||
self.assertIsNone(r["retreat"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user