分析能力入口(七):按 W1-a 算子库的实际接口对齐。工具参数名以算子为准:差异检验的均值是 mean / sd / n 或 sum / sumsq / n,逐行是 value,可选 pairs / reference;可比性检查另收可选的 measure、grain(不收 label);分析卡的参数校验用同一份定义,运行当天、目录事实、下钻层数由算子自己记,分析项里写了不收。交给算子的输入是工件库里那份查询快照原样(含 SQL 检查结果 checks、「查询区间里这张表没有数据」no_data、查询当时记下的遮罩),加上出处和遮罩列(数据源设的、按 SQL 认出改了名字的、遮罩运行里查询时就遮掉的),合并查询写明 sqlite 方言;agent 的容器在分析前把每份换成完整快照(每份只取回一次)。探查器改用 analysis.make_prober(数据源名 → 按运行固定版本解析出的源,coverage.Cache 一个节点里共用),剖析事实一律用 analysis.probe.profile_facts(查询工具的覆盖检查也改用它,原来那段同样的取法删掉)。分析次数用完交回 analysis.exhausted 的那句;口径卡的可比性写成 {工件, 判定码, 判定语, analysis.comparable_reasons 拆出的原因},删掉自己拆原因的那段。加真算子的端到端测试:agent 变化拆解并下钻(父结论按内容哈希认)、审批恢复重放不再算、分析卡的波动基线和变化拆解(本期完整按现查的表范围判)、口径卡跑真可比性检查(可比、有条件可比带原因),每份结论都按封存的工件复算、逐字段相同

This commit is contained in:
ThearchyHelios
2026-10-21 13:27:12 +08:00
parent 010e74b006
commit 71dc16bc1a
9 changed files with 470 additions and 187 deletions
+3 -4
View File
@@ -63,7 +63,7 @@ async def run_analysis(state: GraphState, ctx: NodeContext) -> dict[str, Any]:
inputs[node_id] = await _load_input(state, ctx, node_id, queries)
context = await context_of(list(inputs.values()), tool_ctx=tool_context(ctx.run, ctx.node.id, ctx.emit))
import app.analysis as analysis_ops # 按模块取 run:测试、合并前的替身都只换模块上的这一个函数
import app.analysis as analysis_ops # 按模块取 run:测试换替身时只换模块上的这一个函数
exec_no = next_exec(state, ctx.node.id)
done: dict[str, AnalysisResult] = {}
@@ -158,9 +158,8 @@ async def _load_input(state: GraphState, ctx: NodeContext, node_id: str,
raise NodeError(ctx.node.id, f"{who}的查询快照与哈希不一致,疑似被修改,不能分析") from None
if not isinstance(content, dict):
raise NodeError(ctx.node.id, f"{who}的查询快照已不存在,无法分析。请重新运行它")
snapshot = input_snapshot(content, ref=node_id, artifact=artifact, node_id=node_id)
snapshot["masked"] = await masked_of(content, artifact)
return snapshot
return input_snapshot(content, ref=node_id, artifact=artifact, node_id=node_id,
masked=await masked_of(content, artifact))
__all__ = ["REFUSED_CODE", "card_view", "run_analysis"]
+7 -25
View File
@@ -539,7 +539,7 @@ class _Skipped(Exception):
async def _check_comparable(pair: tuple[str, str], inputs: list[dict[str, Any]], ctx: NodeContext,
comparing: _Comparing, snapshots: dict[str, Any]) -> dict[str, Any]:
import app.analysis as analysis_ops # 按模块取 run:测试、合并前的替身都只换模块上的这一个函数
import app.analysis as analysis_ops # 按模块取 run:测试换替身时只换模块上的这一个函数
from app.analysis.contract import VERDICTS
from app.data.sql_semantics import normalize_sql
@@ -573,10 +573,9 @@ async def _check_comparable(pair: tuple[str, str], inputs: list[dict[str, Any]],
refs[artifact] = producer if producer and producer not in refs.values() else f"{producer or 'query'}·{role}"
snaps = {}
for artifact in order:
content = snapshots[artifact]
snap = input_snapshot(content, ref=refs[artifact], artifact=artifact, node_id=refs[artifact].split("·")[0])
snap["masked"] = await masked_of(content, artifact)
snaps[refs[artifact]] = snap
snaps[refs[artifact]] = input_snapshot(snapshots[artifact], ref=refs[artifact], artifact=artifact,
node_id=refs[artifact].split("·")[0],
masked=await masked_of(snapshots[artifact], artifact))
settings = await settings_of(run_snapshot(ctx.run))
context = await context_of(list(snaps.values()), tool_ctx=tool_context(ctx.run, ctx.node.id, ctx.emit))
request = {"op": "comparable", "mode": None,
@@ -586,8 +585,9 @@ async def _check_comparable(pair: tuple[str, str], inputs: list[dict[str, Any]],
if result.get("status") != "ok" or verdict not in VERDICTS["comparable"]:
raise _Skipped(str(result.get("reason") or "检查没有给出判定"))
artifact = await store(result, run_id=ctx.run.run_id, node_id=ctx.node.id)
return {"artifact": artifact, "verdict": verdict, "phrase": str(result.get("phrase") or ""),
"reasons": comparability_reasons(result)}
# 原因的拆法只有算子那一处(analysis.comparable_reasons,按检查表的说明拆)
return {"artifact": artifact, "verdict": result["verdict"]["code"], "phrase": result["phrase"],
"reasons": analysis_ops.comparable_reasons(result)}
async def _dialect_of(source: str, comparing: _Comparing) -> str | None:
@@ -625,24 +625,6 @@ def _period_order(a: tuple[str, ...], b: tuple[str, ...]) -> tuple[int, int]:
return 1, 0
def comparability_reasons(result: dict[str, Any]) -> list[str]:
"""可比性结论里 fail、warn 的原因,一句一个(contract.MetricComparability.reasons)。结果表里有 status 一列和一列说明
(reason / text / detail / message)的照表取;没有的按判定语「两期不可比:原因;原因」拆。可比的没有原因。"""
table = result.get("table") or {}
columns = [str(c) for c in table.get("columns") or []]
text_col = next((c for c in ("reason", "text", "detail", "message") if c in columns), None)
if "status" in columns and text_col is not None:
si, ti = columns.index("status"), columns.index(text_col)
found = [str(row[ti]) for row in table.get("rows") or []
if isinstance(row, list) and len(row) > max(si, ti) and row[si] in ("fail", "warn") and row[ti]]
if found:
return found
phrase = str(result.get("phrase") or "")
if (result.get("verdict") or {}).get("code") == "comparable" or ":" not in phrase:
return []
return [part.strip() for part in phrase.split(":", 1)[1].split(";") if part.strip()]
#: 清单里输入取自「查询区间里这张表没有数据」的列的指标后面那句:直接读清单的模型节点不能把 0 当成真的是 0
LISTED_NO_DATA = "(这段时间表里没有数据:不要当成 0 解读)"
#: 指标的 no_data_reason 打头那半句(后面接查询记下的说明)