feat(replay): execute periodic diagnosis and hydraulic checks

This commit is contained in:
2026-11-16 15:13:22 +08:00
parent 4c441fcbf2
commit 389892cb3f
22 changed files with 1934 additions and 12 deletions
+10 -2
View File
@@ -42,6 +42,9 @@ def snapshot(document: dict) -> ScadaReplaySnapshot:
"virtual_now", "created_at", "updated_at",
)},
delivered_until=document.get("delivered_until"), processed_until=document.get("processed_until"),
scheduled_tasks_enabled=document.get("config", {}).get("scheduled_tasks_enabled", False),
periodic_pending=(document.get("last_scheduled_simulation") or {}).get("status") in {"pending", "running"},
periodic_error=(document.get("last_scheduled_simulation") or {}).get("error"),
processed_count=document.get("processed_count", 0), anomaly_count=document.get("anomaly_count", 0),
devices=document["devices"], rules=document["config"]["rules"],
latest=list(document.get("latest", {}).values()),
@@ -132,6 +135,11 @@ class ScadaReplayService:
return snapshot(document)
if command.expected_revision != document["revision"]:
raise HTTPException(409, "回放控制状态已更新,请刷新后重试")
if document["config"].get("scheduled_tasks_enabled") and command.action in {"step", "monitor"}:
from app.services.periodic_tasks import project_periodic_state
document = await project_periodic_state(self.repo, document)
if snapshot(document).periodic_pending:
raise HTTPException(409, "本周期水力计算尚未完成,请等待后继续播放")
action, status = command.action, document["status"]
if (action in {"step", "monitor", "retry"} and document.get("warmed")
and weighted_diagnosis(document)
@@ -332,7 +340,7 @@ class ScadaReplayService:
monitoring["anomaly_signals"] = list(signals.values())
if signals and monitoring["status"] == "normal":
monitoring["status"] = "attention"
monitoring["detail"] = "本周期曾检出测点异常,进入异常调查与爆管诊断"
monitoring["detail"] = "本周期曾检出测点异常,进入运行异常与潜在事件诊断"
result["monitoring_count"] = result.get("monitoring_count", 0) + 1
if not result["step_pending"]:
result.pop("step_target", None)
@@ -565,7 +573,7 @@ class ScadaReplayService:
trigger=TaskTrigger(
kind="event",
occurred_at=monitoring["period_end"],
detail="SCADA 任一指标异常启动调查,核验数据后进行爆管诊断;异常不等于已确诊爆管",
detail="SCADA 任一指标异常启动调查,核验爆管或污染等潜在事件;异常不等于现场确诊",
),
)
task = await tasks.create(command)