feat(sense): T-G3 标签+校准(labeler 四规则推导 + split-conformal + last-good)

- labeler.py:derive_true_tier 纯函数(规则0 人工优先 / plan_multi->T3 /
  失败->下一档(T3保持) / 成功->executed / 空结果跳过)+ derive_true_tiers
  批量回填 + 180d 留存清理
- calibrate.py:compute_thresholds(τ1/τ3 分组扫描——并列分数整组判定,
  精度 >= 1-α 的最大覆盖阈值;<min_labels -> ok=False 沿用 last-good);
  save_thresholds 工件落盘+登记;load_active 回退链 active->同kind扫描->last-good->保守值
- store:all_observations/list_artifacts 支撑方法
- 测试 +9(四规则/批量清理/覆盖达标/标签不足/工件往返与回退),全量 395 passed
This commit is contained in:
tzt
2026-09-05 13:53:45 +08:00
parent 51f1de2154
commit 324c419c35
5 changed files with 321 additions and 1 deletions
+16
View File
@@ -116,6 +116,14 @@ class SenseStore:
" WHERE true_tier != ''").fetchone()
return int(row["c"])
def all_observations(self, limit: int = 200000) -> List[Dict[str, Any]]:
"""全量遍历(labeler 夜间推导输入;量大时可分页)。"""
with self._lock, self._connect() as conn:
rows = conn.execute(
"SELECT * FROM tier_observations ORDER BY id LIMIT ?",
(limit,)).fetchall()
return [dict(r) for r in rows]
def purge_older_than(self, ts: float) -> int:
"""留存清理(D-G6:默认 180 天,夜间任务顺带)。"""
with self._lock, self._connect() as conn:
@@ -154,6 +162,14 @@ class SenseStore:
" ORDER BY created_ts DESC LIMIT 1", (kind,)).fetchone()
return dict(row) if row else None
def list_artifacts(self, kind: str) -> List[Dict[str, Any]]:
"""同 kind 工件按时间倒序(load_active 的 last-good 扫描用)。"""
with self._lock, self._connect() as conn:
rows = conn.execute(
"SELECT * FROM sense_artifacts WHERE kind = ?"
" ORDER BY created_ts DESC", (kind,)).fetchall()
return [dict(r) for r in rows]
# ---------- 自省 ----------
def table_names(self) -> List[str]:
with self._lock, self._connect() as conn: