diff --git a/backend/README.md b/backend/README.md index e607722..2a5ef33 100644 --- a/backend/README.md +++ b/backend/README.md @@ -84,13 +84,17 @@ tests/ 入库 ──► 观察中 ──(次日复核做对)──► 粗心小记(不进队列) │ └─(复核做错)──► 待复习 ──(做对 1 次)──► 已对 1 次 ──(再对)──► 待讲清 - ▲ │ - │ 讲清通过 │ + ▲ │ │ + │ └─(当天错了又对)──► 会但不稳 ──(次日再对)──┘ + │ │ └──────── 答错/讲不清:间隔归零,明天 ────────┴──► 已毕业 ``` - **只错三次才入库**:第 1 次进「观察中」,第 2 次仍观察,第 3 次才进复习队列(`scheduler.on_import`)。 - **粗心隔离**:24 小时内还能做对 → 判为执行失误,进「粗心小记」,不做重做训练。 +- **会但不稳(第三态)**:同一道题当天先错、看完解析当场又做对 → 不算连对一次,进 `unstable`,明天从头再来; + 做对一次才回到 `passed_once`。理由是「听完会了」不等于「明天还记得」,也是家长最常问的「怎么又错了」的解释。 + `mistakes.unstable_count` 记次数,周报里单独显示「会但不稳 N 道」。 - **连对两次才到「讲清」**:同题第二次靠记忆,所以第二档之后必须讲一遍。 - **间隔**:1 → 3 → 7 → 15 → 30 天;答错或讲不清 → 归零,明天再来。 - **每天最多 5 道**:`DAILY_CAP=5`,服务端截断,第 5 道之后不再追加。 @@ -502,3 +506,22 @@ python tests/smoke_http.py # 39 项 HTTP 冒烟(真起服务 顺带记两个坑:`_LINE_NO` 少写 `(?!\d)` 会把 `1.8+0.6` 的 `1.` 当题号(算成 8.6); `safe_eval` 曾走 `normalize`,那里的 `strip_punct` 会把括号剥掉,`34×(90-46)` 静默变成 `34*90-46`。(见四点二十一) + +### 四点二十三、会但不稳:当天错了又对,不算连对 + +原来的规则是「做对就往前推一档」,于是课堂/家庭场景里最常见的一幕被记成了掌握: +孩子做错 → 看解析 → 当场再写一遍,对了。但那只是「听完会了」,明天还记不记得,没验过。 + +- 新增状态 `unstable`(界面文案「会但不稳」):`mistakes.unstable_count` 记次数,`stage` 不动, + `next_due` = 明天,`is_due` 认它,所以明天还会出现在队列里 +- 判定发生在 `services.attempt()` / `self_judge()`:做题前查 + `attempts` 里有没有**今天**这条错题的错答;有才传 `same_day_wrong=True` +- 次日再做对 → 正常进 `passed_once`,间隔从 1 天重新开始(不是接着原来的 3/7 天) +- 周报 `numbers.unstable_total`、首页「错题消灭率」小字、错题本筛选与橙色状态标签都把它显示出来: + 它既不是「已毕业」,也不是「没懂」,家长需要这个中间答案 +- `dev_advance()` 现在同时挪 `attempts` / `explain_attempts` 的 `created_at`—— + 否则演示脚本里「今天错了今天又对」永远成立,第二天做对也判不成连对(踩过一次) + +初中版(`junior/`)暂不套用这条规则:它用「做对一道变式」替代第二次连对, +「当天再对一次」在那边本来就不算过关,语义已经不同。 + diff --git a/backend/db.py b/backend/db.py index 2797046..db96358 100644 --- a/backend/db.py +++ b/backend/db.py @@ -100,6 +100,7 @@ CREATE TABLE IF NOT EXISTS mistakes ( interval_days INTEGER NOT NULL DEFAULT 1, next_due TEXT, explain_fails INTEGER NOT NULL DEFAULT 0, + unstable_count INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, graduated_at TEXT ); @@ -270,10 +271,15 @@ def init_db(conn: sqlite3.Connection) -> None: def _migrate(conn: sqlite3.Connection) -> None: """老库补列(CREATE TABLE IF NOT EXISTS 不会改已存在的表)。""" - want = {"questions": ["options", "kp"], "mistakes": ["options", "kp"], - "guardians": ["phone"], "papers": ["clean_path", "image_path"]} + want = { + "questions": {"options": "TEXT", "kp": "TEXT"}, + "mistakes": {"options": "TEXT", "kp": "TEXT", + "unstable_count": "INTEGER NOT NULL DEFAULT 0"}, + "guardians": {"phone": "TEXT"}, + "papers": {"clean_path": "TEXT", "image_path": "TEXT"}, + } for table, cols in want.items(): - ensure_columns(conn, table, {c: "TEXT" for c in cols}) + ensure_columns(conn, table, cols) def reset_db(conn: sqlite3.Connection) -> None: diff --git a/backend/scheduler.py b/backend/scheduler.py index 2084b72..dc98053 100644 --- a/backend/scheduler.py +++ b/backend/scheduler.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- """错题状态机与复习调度(SM-2 简化版)。 -状态(6 个): +状态(7 个): observing 观察中 刚入库,错因暂定 E4;不进队列 queued 待复习 到期了就进今日队列 + unstable 会但不稳 今天错过、当天又做对了——不算数,明天从头再来 passed_once 已对 1 次 再做对一次就进「待讲清」 to_explain 待讲清 等孩子讲一遍(不进刷题队列) graduated 已毕业 讲清通过 → 进「已消灭」档案,永不再推 @@ -24,6 +25,7 @@ CLEAR_CARELESS_WINDOW_HOURS = 24 STATUS_ZH = { "observing": "观察中", "queued": "待复习", + "unstable": "会但不稳", "passed_once": "已对 1 次", "to_explain": "待讲清", "graduated": "已毕业", @@ -44,8 +46,9 @@ def is_due(mistake: dict, on: str | None = None) -> bool: """到期 = 该出现在今天列表里。 观察中的题也会在次日回来「复核」一次:做对就是粗心,做错才确认没懂。 + 不稳的题同样回到队列:今天错、今天对的,明天必须再做对一次才算过。 """ - if mistake.get("status") not in ("observing", "queued", "passed_once"): + if mistake.get("status") not in ("observing", "queued", "unstable", "passed_once"): return False due = mistake.get("next_due") return bool(due) and due <= (on or today()) @@ -58,8 +61,14 @@ def due_today(mistakes: list[dict], on: str | None = None, cap: int = DAILY_CAP) return items[:cap] -def on_attempt(mistake: dict, correct: bool, created_at: str | None = None) -> dict: - """做了一次(重做/口答)。返回要写回 mistakes 的字段。""" +def on_attempt(mistake: dict, correct: bool, *, created_at: str | None = None, + same_day_wrong: bool = False) -> dict: + """做了一次(重做/口答)。返回要写回 mistakes 的字段。 + + :param same_day_wrong: 这道题「今天」已经错过一次。看完解析当场再做对, + 只能说明「听完会了」,说明不了「记住了」——所以不推进档位, + 只记一道「会但不稳」,明天再从头做对一次才算第一次。 + """ ts = created_at or now() stage = int(mistake.get("stage") or 0) wrong_count = int(mistake.get("wrong_count") or 1) @@ -74,6 +83,16 @@ def on_attempt(mistake: dict, correct: bool, created_at: str | None = None) -> d # 隔了更久还能做对 → 不是没懂,是「会但不熟」,拉开间隔进队列 return {"status": "queued", "stage": 1, "interval_days": 3, "next_due": add_days(3, base=_date_of(ts)), "wrong_code": "E3"} + if same_day_wrong: + # 当天错了又对:不算数,明天重来;连错两次以上的是「没懂」,不是「不稳」 + return { + "status": "unstable", + "stage": 0, + "interval_days": 1, + "next_due": add_days(1, base=_date_of(ts)), + "unstable_count": int(mistake.get("unstable_count") or 0) + 1, + "wrong_code": mistake.get("wrong_code") or "E4", + } stage += 1 interval = INTERVALS[min(stage - 1, len(INTERVALS) - 1)] if stage >= 2: diff --git a/backend/services.py b/backend/services.py index 598398d..eeace54 100644 --- a/backend/services.py +++ b/backend/services.py @@ -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", } diff --git a/data/_ocrcache_test/4efb2f53091b018c12143673b069c4213e9642ce.json b/data/_ocrcache_test/4efb2f53091b018c12143673b069c4213e9642ce.json deleted file mode 100644 index 69a3dd5..0000000 --- a/data/_ocrcache_test/4efb2f53091b018c12143673b069c4213e9642ce.json +++ /dev/null @@ -1 +0,0 @@ -{"ok": true, "data": {}} \ No newline at end of file diff --git a/prototype/workbench/README.md b/prototype/workbench/README.md index 56bf6d2..2bdd329 100644 --- a/prototype/workbench/README.md +++ b/prototype/workbench/README.md @@ -31,7 +31,7 @@ prototype/workbench/index.html ← 全部代码都在这一个文件里 |---|---|---| | 工作台 | `#home` | 今天几道 / 本周毕业 / 消灭率 + 今日队列 + 这周那张纸 | | 今日训练 | `#train` | 一屏一道 → 判对错 → 解析三 tab → 举一反三 → 答题卡 | -| 错题本 | `#wrong` | 全部错题,按状态筛(待复习 / 待讲清 / 已毕业 / 粗心) | +| 错题本 | `#wrong` | 全部错题,按状态筛(待复习 / 会但不稳 / 待讲清 / 已毕业 / 粗心) | | 复习计划 | `#plan` | 未来 7 天每天要复习几道 | | 学情分析 | `#analysis` | 错因分布(E1–E6)+ 薄弱知识点 + 一周趋势 | | 周报与打印 | `#weekly` | 本周四个数字 + A5 预览 + 打印 | diff --git a/prototype/workbench/index.html b/prototype/workbench/index.html index 5b681eb..c07cbb5 100644 --- a/prototype/workbench/index.html +++ b/prototype/workbench/index.html @@ -112,6 +112,7 @@ h1{font-size:22px;margin:0 0 4px} .pill.c{background:var(--brand-soft);color:var(--brand-d)} .pill.g{background:var(--green-soft);color:var(--green)} .pill.b{background:var(--blue-soft);color:var(--blue)} +.pill.o{background:var(--ochre-soft);color:var(--ochre)} .pill.gray{background:#F2EDE4;color:#7C7166} /* ---------- 训练页 ---------- */ @@ -170,6 +171,7 @@ h1{font-size:22px;margin:0 0 4px} .result{margin-top:16px;border-radius:12px;padding:14px 16px;font-size:14px;line-height:1.7;display:none} .result.ok{display:block;background:var(--green-soft);border:1px solid #CFE3D6;color:#245744} +.result.mid{display:block;background:var(--ochre-soft);border:1px solid #EFDCAE;color:#7A5410} .result.no{display:block;background:var(--red-soft);border:1px solid #F2D3CD;color:#8E2B23} .result b{font-size:15px} @@ -531,7 +533,7 @@ td .t{font-family:"Consolas",monospace;font-size:13.5px}