import type { ScadaMonitoringCalibration, ScadaMonitoringConfig } from "../api/scada-replay-client"; export function ScadaMonitoringRules({ config, calibration, frozen }: { config: ScadaMonitoringConfig; calibration?: ScadaMonitoringCalibration | null; frozen: boolean; }) { const weighted = config.decision_policy === "weighted"; const currentPolicy = calibration?.version === "scada-monitor-calibration@2" && calibration.diagnostic_policy === "normal-phase-envelope@1"; const usable = currentPolicy ? calibration : null; const ready = usable?.status === "ready"; const indicators = [ { key: "burst_detection", label: "爆管侦测", threshold: ready && usable.burst_detection?.threshold != null ? `得分 ≤ ${usable.burst_detection.threshold.toFixed(4)}` : "由前 15 天正常历史计算" }, { key: "pressure", label: "压力下降", threshold: thresholdLabel(config.pressure_device_ids, usable?.pressure, "下降") }, { key: "outlet_flow", label: "出厂流量", threshold: config.outlet_flow_device_ids.length ? thresholdLabel(config.outlet_flow_device_ids, usable?.outlet_flow, "增加") : "未配置,贡献为 0" } ] as const; return (

SCADA 异常触发规则

压力、流量越过历史同期正常范围,或水质越过已配置上下限,即报警并启动调查。

  1. 数据诊断
  2. 指标异常
  3. 爆管诊断
  4. 报告

{weighted ? "爆管诊断 · 三指标加权" : "爆管诊断 · 三指标联合判定"}

{frozen ? "本轮已固定" : "下一轮使用项目配置"}
{weighted ? ( <>
{indicators.map(({ key, label, threshold }) => (
{label}
权重 {(config.weights[key] * 100).toFixed(0)}%
{threshold}
))}

综合分 ≥ {config.alert_threshold.toFixed(2)} 时标记疑似爆管

加权分用于评估爆管嫌疑,任一指标异常即启动调查。

压力下降与出厂流量增加需同时越过动态变化阈值和历史同期正常范围。正常日的日内波动由同期范围校验。

指标命中后计入对应权重;流量缺数按 0 计,不重新分配权重。压力或侦测数据不足时暂不作出组合判定。

动态阈值 · {ready ? "本轮已冻结" : "等待历史基线"}

{ready ?

历史区间 {dateTime(usable.history_start)} 至 {dateTime(usable.knowledge_cutoff)}(不含结束时刻)

:

{calibration && !currentPolicy ? "旧版校准已停用,请重新开始本轮。" : calibration ? "历史基线不足,动态阈值尚未就绪。" : "开始监测后,以演示开始前 15 天的正常历史逐测点计算阈值,并在本轮固定。"}

}
) : (

本轮使用三指标联合评估爆管嫌疑;任一经历史基线校验的指标异常即启动调查。

)}

同一异常只报警并建单一次,持续异常沿用原工单;连续两个正常周期且相关测点恢复后解除告警。

压力 {config.pressure_device_ids.length} 个测点 · 出厂流量 {config.outlet_flow_device_ids.length} 个测点 · {config.rule_version}

); } function thresholdLabel(ids: string[], profiles: ScadaMonitoringCalibration["pressure"] | undefined, direction: string) { const thresholds = ids.flatMap((id) => profiles?.[id] ? [profiles[id].threshold_percent] : []); if (!thresholds.length) return "逐测点动态计算变化阈值"; const lower = Math.min(...thresholds).toFixed(2); const upper = Math.max(...thresholds).toFixed(2); const range = lower === upper ? `${direction}阈值 ${lower}%` : `${direction}阈值 ${lower}%~${upper}%(逐测点)`; return thresholds.length < ids.length ? `${range} · 已就绪 ${thresholds.length}/${ids.length} 个测点` : range; } function dateTime(value: string) { return new Date(value).toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false }); }