证据面板加数字推演:指标步骤上「推演」,改输入、勾掉查询结果里的行,看这个数和报告怎么变

- run/WhatIf.tsx:推演区。顶上醒目横幅「推演,非出具:不会写进运行记录,也不会改动报告」,运行未封存另行提示;
  旧值 → 新值和变化量(比率、百分数写「个百分点」)、推演代入式、输入(数值可改:停顿 450 毫秒或回车、失焦才提交,
  写的不是数提示并保留上次的结果,Esc 退回)、不支持推演的输入和原因、报告中会变的地方(可定位)、可能受影响的
  下游口径卡、恢复原值;加载、失败(可重试)、空态都有。新改动来了旧请求直接丢掉,答复按请求体缓存
- EvidencePanel.tsx:MetricPart 挂「推演」开关和推演区;QueryPart 只在推演时把结果窗口换成带勾选框的表(WhatIfRows),
  勾掉的行划掉、遮罩列照旧写「已遮罩」。草稿按(运行、报告、口径卡、指标)认,同一个指标的几处引用之间来回切不清空
- 接口 api.whatif.run、推演相关类型(types.ts 末尾独立一段)、WHATIF_TEXT 文案
- 预览用例 ?syn=whatif / whatif-rail 和 check-whatif.mjs(54 项,用 page.route 假接口):请求体、防抖、回车、排除行、
  恢复原值、收起、不支持的输入、遮罩列、加载 / 失败 / 未封存、390px 与 360px 右栏不横向溢出、深浅色横幅对比度
This commit is contained in:
ThearchyHelios
2026-10-05 04:04:30 +08:00
parent 9852e4d33a
commit cf038c95f5
8 changed files with 1133 additions and 20 deletions
+113
View File
@@ -3020,3 +3020,116 @@ export interface SqlCheckItem {
relation_id?: string
sql_excerpt?: string
}
// ===========================================================================
// 数字推演(后端 app/api/whatif.py、app/engine/recompute.py):在一次运行的口径卡上改输入、排除查询快照里的行,
// 看指标和报告里引用它的地方会变成多少。推演不是出具:不写运行记录、不改报告
// ===========================================================================
/** 推演的改动:输入路径 → 新值;查询快照的工件 id → 要排除的行号(快照里的行号,从 0 数) */
export interface WhatIfOverrides {
inputs: Record<string, number>
exclude_rows: Record<string, number[]>
}
/** POST /runs/{id}/evidence/whatif 的请求体 */
export interface WhatIfRequest {
/** 报告撰写节点 id:只列这份报告里引用的地方 */
report?: string
/** 口径卡节点 id */
card: string
/** 只推演这一个指标 */
metric?: string
overrides: WhatIfOverrides
}
/** 一个输入在推演里的样子 */
export interface WhatIfInput {
path: string
via?: string | null
node_id?: string | null
/** 落在哪份查询快照上(cell() 取的格、agent 字段、整份查询结果):排除这份快照里的行会影响它 */
artifact?: string
locator?: EvidenceLocator
kind: 'number' | 'text' | 'bool' | 'missing' | 'container' | (string & {})
/** 数值(或原本缺失)的标量、不是遮罩列、不决定取哪一格:可以改 */
editable: boolean
/** 原值、推演用的值。容器写大概(「[12 项]」);遮罩列的一律是 null */
old?: unknown
new?: unknown
changed?: boolean
/** 起了作用的被排除行(快照里的行号,从 0 数) */
excluded_rows?: number[]
masked?: boolean
}
/**
* unchanged:没碰到改动,原值原样交回;ok:重算了;excluded:排除行后缺了输入,算不出来;error:新值让计算出错(除以零……);
* unsupported:有输入的完整值找不回来,推演不了;masked:用到了遮罩列,不推演
*/
export type WhatIfStatus = 'unchanged' | 'ok' | 'excluded' | 'error' | 'unsupported' | 'masked'
export interface WhatIfMetric {
id: string
name: string
unit: string
decimals?: number | null
format?: string
old: unknown
new: unknown
delta: number | null
/** 按口径卡的格式渲染(和报告里的字同一套规则) */
rendered_old: string
/** unsupported、masked 时为 null:不知道会变成什么 */
rendered_new: string | null
/** 带正负号;比率、百分数写「个百分点」。没变化、不是数时为 null */
rendered_delta: string | null
changed: boolean | null
status: WhatIfStatus | (string & {})
reason: string | null
/** 推演用的代入式(重算了才有;没碰到改动的是卡上原来的代入式) */
substituted: string | null
inputs: WhatIfInput[]
}
/** 报告里引用这个指标的一处,推演之后会写成什么 */
export interface WhatIfSegment {
report: string
unit: string
sid: string
metric: string
rendered_old: string
rendered_new: string | null
changed: boolean | null
}
export interface WhatIfUnsupported {
metric: string
/** null:整个指标都推演不了(口径卡没记输入) */
input: string | null
reason: string
}
/** 引用了这张口径卡的下游口径卡:只标可能受影响,不重算 */
export interface WhatIfAffectedCard {
node_id: string
artifact: string
caliber: string
version: string
metrics: string[]
/** 直接引用(false 是经别的卡间接引用) */
direct: boolean
}
export interface WhatIfResult {
run_id: string
card: { node_id: string; artifact: string; caliber: string; version: string }
report: string | null
/** 运行已封存且封存核对一致:推演依据的数据不会再变 */
sealed: boolean
seal: { sealed: boolean; ok: boolean | null }
metrics: WhatIfMetric[]
segments: WhatIfSegment[]
unsupported: WhatIfUnsupported[]
affected_cards: WhatIfAffectedCard[]
}