第三态:会但不稳——当天错了又对不算连对,次日再来一次(202 测试 + 41/22/21/29 冒烟)

This commit is contained in:
2026-11-21 16:14:25 +08:00
parent e32598553c
commit 5ffdcce377
12 changed files with 264 additions and 24 deletions
+28 -5
View File
@@ -917,7 +917,11 @@ def attempt(conn, gid: str, cid: str, mid: str, answer_text: str, cost_ms: int |
if correct is None:
return {"mistake_id": mid, "correct": None, "detail": detail, "refused": True,
"hint": "机器不判这类题,标给家长/老师"}
state = scheduler.on_attempt(mdict, correct)
# 今天已经错过一次?那这次做对只能证明「看完解析会了」,不能算连对一次
same_day_wrong = conn.execute(
"SELECT 1 FROM attempts WHERE mistake_id=? AND is_correct=0"
" AND substr(created_at,1,10)=? LIMIT 1", (mid, today())).fetchone() is not None
state = scheduler.on_attempt(mdict, correct, same_day_wrong=same_day_wrong)
with tx(conn):
conn.execute("INSERT INTO attempts (id, mistake_id, child_id, answer_text, is_correct, cost_ms, created_at)"
" VALUES (?,?,?,?,?,?,?)",
@@ -938,6 +942,10 @@ def attempt(conn, gid: str, cid: str, mid: str, answer_text: str, cost_ms: int |
"stage": state.get("stage", mdict["stage"]),
"next_due": state.get("next_due"),
"need_explain": state["status"] == "to_explain",
# 会但不稳:当天错了又对。前端要明说「这次不算」,否则孩子以为过关了
"unstable": state["status"] == "unstable",
"unstable_hint": ("这次算「会但不稳」——明天同一道题再做对一次,才往前算。"
if state["status"] == "unstable" else None),
}
@@ -1062,6 +1070,8 @@ def weekly_report(conn, gid: str, cid: str, week_of: str | None = None) -> dict:
total_mistakes = conn.execute("SELECT COUNT(*) c FROM mistakes WHERE child_id=?", (cid,)).fetchone()["c"]
graduated = conn.execute(
"SELECT COUNT(*) c FROM mistakes WHERE child_id=? AND status='graduated'", (cid,)).fetchone()["c"]
unstable = conn.execute(
"SELECT COUNT(*) c FROM mistakes WHERE child_id=? AND status='unstable'", (cid,)).fetchone()["c"]
return {
"child": {"id": cid, "nickname": child["nickname"], "grade": child["grade"]},
"week": {"start": start, "end": end},
@@ -1071,6 +1081,7 @@ def weekly_report(conn, gid: str, cid: str, week_of: str | None = None) -> dict:
"attempts_this_week": len(attempts),
"review_days": len(daily),
"graduated_total": graduated,
"unstable_total": unstable,
"active_total": total_mistakes - graduated,
"kill_rate": round(graduated / total_mistakes * 100, 1) if total_mistakes else 0.0,
},
@@ -1275,6 +1286,8 @@ def stats(conn, gid: str, cid: str) -> dict:
"mistakes_total": total,
"by_status": by_status,
"graduated": graduated,
# 会但不稳:介于「已毕业」和「没懂」之间的第三态,家长看得懂,也解释了「怎么又错了」
"unstable": by_status.get("unstable", 0),
"kill_rate": round(graduated / total * 100, 1) if total else 0.0,
"attempts_last7d": last7,
"north_star": "月消灭率 ≥ 40%(已毕业 / 全部错题)",
@@ -1282,9 +1295,15 @@ def stats(conn, gid: str, cid: str) -> dict:
def dev_advance(conn, days: int = 1) -> dict:
"""演示用:把「明天到期」提前到今天,方便一条命令看到完整生命周期。"""
conn.execute("UPDATE mistakes SET next_due = date(next_due, ?) WHERE next_due IS NOT NULL",
(f"-{int(days)} days",))
"""演示用:把「明天到期」提前到今天,方便一条命令看到完整生命周期。
做题记录也一起往前挪:不然「今天错了、今天又对了」这条规则在演示里
永远成立,孩子第二天做对也判不成「连对一次」。
"""
shift = f"-{int(days)} days"
conn.execute("UPDATE mistakes SET next_due = date(next_due, ?) WHERE next_due IS NOT NULL", (shift,))
conn.execute("UPDATE attempts SET created_at = datetime(created_at, ?)", (shift,))
conn.execute("UPDATE explain_attempts SET created_at = datetime(created_at, ?)", (shift,))
return {"advanced_days": days, "due_now": conn.execute(
"SELECT COUNT(*) c FROM mistakes WHERE next_due<=?", (today(),)).fetchone()["c"]}
@@ -1562,7 +1581,10 @@ def self_judge(conn, gid: str, cid: str, mid: str, correct: bool, note: str = ""
mdict = dict(m)
if mdict["status"] in ("graduated", "careless"):
raise ApiError(409, "NOT_IN_QUEUE", "这道题已经不在队列里了(已毕业或在粗心小记)")
state = scheduler.on_attempt(mdict, bool(correct))
same_day_wrong = conn.execute(
"SELECT 1 FROM attempts WHERE mistake_id=? AND is_correct=0"
" AND substr(created_at,1,10)=? LIMIT 1", (mid, today())).fetchone() is not None
state = scheduler.on_attempt(mdict, bool(correct), same_day_wrong=same_day_wrong)
with tx(conn):
conn.execute(
"INSERT INTO attempts (id, mistake_id, child_id, answer_text, is_correct, cost_ms, source, created_at)"
@@ -1580,6 +1602,7 @@ def self_judge(conn, gid: str, cid: str, mid: str, correct: bool, note: str = ""
"stage": state.get("stage", mdict["stage"]),
"next_due": state.get("next_due"),
"need_explain": state["status"] == "to_explain",
"unstable": state["status"] == "unstable",
}