重构监测逻辑,优化 SCADA 数据处理
This commit is contained in:
@@ -126,8 +126,10 @@ def run_burst_location_by_network(
|
|||||||
)
|
)
|
||||||
observed_source = "simulation_scheme_burst_realtime_normal_timerange"
|
observed_source = "simulation_scheme_burst_realtime_normal_timerange"
|
||||||
else:
|
else:
|
||||||
burst_pressure_series, burst_pressure_samples = (
|
(
|
||||||
_build_observed_series_from_scada(
|
burst_pressure_series,
|
||||||
|
burst_pressure_samples,
|
||||||
|
) = _build_observed_series_from_scada(
|
||||||
network=network,
|
network=network,
|
||||||
sensor_ids=selected_pressure_ids,
|
sensor_ids=selected_pressure_ids,
|
||||||
start_dt=burst_start_dt,
|
start_dt=burst_start_dt,
|
||||||
@@ -135,7 +137,6 @@ def run_burst_location_by_network(
|
|||||||
data_type="pressure",
|
data_type="pressure",
|
||||||
series_name="burst_pressure",
|
series_name="burst_pressure",
|
||||||
)
|
)
|
||||||
)
|
|
||||||
(
|
(
|
||||||
normal_pressure_series,
|
normal_pressure_series,
|
||||||
normal_pressure_samples,
|
normal_pressure_samples,
|
||||||
|
|||||||
@@ -228,3 +228,74 @@ def test_run_burst_location_requires_simulation_scheme_name(monkeypatch, tmp_pat
|
|||||||
scada_burst_start=datetime(2025, 1, 1, 8, 0, 0),
|
scada_burst_start=datetime(2025, 1, 1, 8, 0, 0),
|
||||||
scada_burst_end=datetime(2025, 1, 1, 9, 0, 0),
|
scada_burst_end=datetime(2025, 1, 1, 9, 0, 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_burst_location_monitoring_uses_scada_for_burst_and_realtime_for_normal(
|
||||||
|
monkeypatch, tmp_path
|
||||||
|
):
|
||||||
|
module = _load_burst_location_module()
|
||||||
|
captured = {}
|
||||||
|
scada_calls = []
|
||||||
|
realtime_calls = []
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
module,
|
||||||
|
"get_all_scada_info",
|
||||||
|
lambda network: [
|
||||||
|
{
|
||||||
|
"type": "pressure",
|
||||||
|
"associated_element_id": "J1",
|
||||||
|
"api_query_id": "pressure-query",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(module, "_prepare_burst_inp", lambda network: str(tmp_path / "fake.inp"))
|
||||||
|
monkeypatch.setattr(
|
||||||
|
module,
|
||||||
|
"run_burst_location",
|
||||||
|
lambda **kwargs: captured.update(kwargs) or {"located_pipe": "Pipe-001"},
|
||||||
|
)
|
||||||
|
|
||||||
|
def fake_scada_query(**kwargs):
|
||||||
|
scada_calls.append(kwargs)
|
||||||
|
return {
|
||||||
|
"pressure-query": [
|
||||||
|
{"time": kwargs["start_time"], "value": 20.0},
|
||||||
|
{"time": kwargs["end_time"], "value": 22.0},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def fake_realtime_query(**kwargs):
|
||||||
|
realtime_calls.append(kwargs)
|
||||||
|
return {
|
||||||
|
"J1": [
|
||||||
|
{"time": kwargs["start_time"], "value": 10.0},
|
||||||
|
{"time": kwargs["end_time"], "value": 12.0},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
module.InternalQueries,
|
||||||
|
"query_scada_by_ids_timerange",
|
||||||
|
staticmethod(fake_scada_query),
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
module.InternalQueries,
|
||||||
|
"query_realtime_simulation_by_ids_timerange",
|
||||||
|
staticmethod(fake_realtime_query),
|
||||||
|
)
|
||||||
|
|
||||||
|
result = module.run_burst_location_by_network(
|
||||||
|
network="tjwater",
|
||||||
|
username="testuser",
|
||||||
|
data_source="monitoring",
|
||||||
|
burst_leakage=1.0,
|
||||||
|
scada_burst_start=datetime(2025, 1, 1, 8, 0, 0),
|
||||||
|
scada_burst_end=datetime(2025, 1, 1, 9, 0, 0),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["observed_source"] == "scada_burst_realtime_normal_timerange"
|
||||||
|
assert len(scada_calls) == 1
|
||||||
|
assert len(realtime_calls) == 1
|
||||||
|
assert captured["burst_pressure"]["J1"] == pytest.approx(21.0)
|
||||||
|
assert captured["normal_pressure"]["J1"] == pytest.approx(11.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user