feat(scada): add calibrated monitoring and incident recovery
This commit is contained in:
@@ -12,14 +12,23 @@ def check_replay_window(context, start, end):
|
||||
raise HTTPException(422, f"回放查询需要明确时间范围,结束不得晚于 {cap.isoformat()}")
|
||||
|
||||
|
||||
def check_snapshot_start(run, start):
|
||||
replay_start = datetime.fromisoformat(run["start_time"])
|
||||
if start < replay_start:
|
||||
baseline = run.get("baseline")
|
||||
if not baseline:
|
||||
raise HTTPException(422, "本轮回放未冻结历史对照,请新建回放后查询历史基线")
|
||||
if start < datetime.fromisoformat(baseline["start_time"]):
|
||||
raise HTTPException(422, "查询起点早于本轮已冻结的历史基线")
|
||||
|
||||
|
||||
async def replay_snapshot_rows(connection, project_id, context, device_ids, start, end, limit, offset=0):
|
||||
check_replay_window(context, start, end)
|
||||
repository = ScadaReplayRepository(connection, project_id)
|
||||
run = await repository.get(context["replay_id"])
|
||||
if not set(device_ids) <= set(run["config"]["device_ids"]):
|
||||
raise HTTPException(403, "设备或回放不属于当前调查")
|
||||
if start < datetime.fromisoformat(run["start_time"]):
|
||||
raise HTTPException(422, "当前调查证据接口仅返回本轮已处理观测,回放前基线已用于后台初始化")
|
||||
check_snapshot_start(run, start)
|
||||
rows = await repository.detected_outputs(
|
||||
context["replay_id"], device_ids, start, end, context["batch_sequence"],
|
||||
limit=limit, offset=offset,
|
||||
@@ -40,9 +49,7 @@ async def replay_burst_location_inputs(connection, project_id, context, args):
|
||||
repository = ScadaReplayRepository(connection, project_id)
|
||||
run = await repository.get(context["replay_id"])
|
||||
if run:
|
||||
replay_start = datetime.fromisoformat(run["start_time"])
|
||||
if args.scada_burst_start < replay_start or args.scada_normal_start < replay_start:
|
||||
raise HTTPException(422, "定位窗口必须位于本轮已处理回放范围内")
|
||||
check_snapshot_start(run, min(args.scada_burst_start, args.scada_normal_start))
|
||||
devices = {item["device_id"]: item for item in run.get("devices", [])}
|
||||
monitoring = run.get("monitoring_config") or {}
|
||||
pressure_devices = monitoring.get("pressure_device_ids", [])
|
||||
|
||||
Reference in New Issue
Block a user