feat(projects): automate project infrastructure provisioning
This commit is contained in:
@@ -14,7 +14,7 @@ from app.native.wndb.gis.network_views import (
|
||||
get_network_link_nodes,
|
||||
get_network_node_coords,
|
||||
)
|
||||
from app.native.wndb.inp.exporter import dump_inp
|
||||
from app.services.project_inp import temporary_project_inp
|
||||
from app.services.scheme_management import store_analysis_run_with_result
|
||||
from app.domain.time import parse_utc_time, utc_now
|
||||
|
||||
@@ -42,8 +42,6 @@ def run_leakage_identification(
|
||||
sensor_nodes: list[str] | None = None,
|
||||
scheme_name: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
inp_path = _prepare_leakage_inp(network)
|
||||
|
||||
selected_sensor_nodes = (
|
||||
list(dict.fromkeys([node for node in (sensor_nodes or []) if node]))
|
||||
if sensor_nodes
|
||||
@@ -52,7 +50,7 @@ def run_leakage_identification(
|
||||
if not selected_sensor_nodes:
|
||||
raise ValueError("未提供有效传感器节点,且系统未识别到可用压力传感器。")
|
||||
|
||||
area_map, areas, node_coords = _build_area_map_by_topology(
|
||||
area_map, areas, _ = _build_area_map_by_topology(
|
||||
network, selected_sensor_nodes, dma_count
|
||||
)
|
||||
|
||||
@@ -73,26 +71,25 @@ def run_leakage_identification(
|
||||
observed_df = observed_pressure_data
|
||||
|
||||
q_sum_m3s = DmaLeakageOptimizer._flow_to_m3s(q_sum, q_sum_unit)
|
||||
identifier = DmaLeakageOptimizer(
|
||||
inp_path=inp_path,
|
||||
sensor_nodes=selected_sensor_nodes,
|
||||
area_map=area_map,
|
||||
start_time=start_time,
|
||||
duration=duration,
|
||||
timestep=timestep,
|
||||
q_sum=q_sum_m3s,
|
||||
)
|
||||
result_df = identifier.run_identification(
|
||||
observed_pressure_data=observed_df,
|
||||
pop_size=pop_size,
|
||||
max_gen=max_gen,
|
||||
n_workers=n_workers,
|
||||
output_flow_unit=output_flow_unit,
|
||||
save_result=False,
|
||||
)
|
||||
with temporary_project_inp(network, purpose="dma-leakage") as inp_path:
|
||||
identifier = DmaLeakageOptimizer(
|
||||
inp_path=str(inp_path),
|
||||
sensor_nodes=selected_sensor_nodes,
|
||||
area_map=area_map,
|
||||
start_time=start_time,
|
||||
duration=duration,
|
||||
timestep=timestep,
|
||||
q_sum=q_sum_m3s,
|
||||
)
|
||||
result_df = identifier.run_identification(
|
||||
observed_pressure_data=observed_df,
|
||||
pop_size=pop_size,
|
||||
max_gen=max_gen,
|
||||
n_workers=n_workers,
|
||||
output_flow_unit=output_flow_unit,
|
||||
save_result=False,
|
||||
)
|
||||
rows = result_df.to_dict(orient="records")
|
||||
# node_visual_payload = _build_node_visual_payload(area_map, node_coords, rows)
|
||||
# drawing_payload = _build_drawing_payload(node_visual_payload)
|
||||
payload = {
|
||||
"result_path": result_df.attrs.get("result_path"),
|
||||
"sensor_nodes": selected_sensor_nodes,
|
||||
@@ -100,8 +97,6 @@ def run_leakage_identification(
|
||||
"area_count": len(set(area_map.values())),
|
||||
"node_area_map": area_map,
|
||||
"areas": areas,
|
||||
# "node_visual_payload": node_visual_payload,
|
||||
# "drawing_payload": drawing_payload,
|
||||
"rows": rows,
|
||||
}
|
||||
if scheme_name:
|
||||
@@ -326,16 +321,3 @@ def _build_observed_pressure_from_scada(
|
||||
|
||||
def _to_datetime(value: datetime | str) -> datetime:
|
||||
return parse_utc_time(value)
|
||||
|
||||
|
||||
def _prepare_leakage_inp(network: str) -> str:
|
||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
db_inp_dir = os.path.join(project_root, "db_inp")
|
||||
os.makedirs(db_inp_dir, exist_ok=True)
|
||||
inp_path = os.path.join(db_inp_dir, f"{network}.leakage.inp")
|
||||
if os.path.isfile(inp_path) and os.path.getsize(inp_path) > 0:
|
||||
return inp_path
|
||||
dump_inp(network, inp_path, "2")
|
||||
if not os.path.isfile(inp_path) or os.path.getsize(inp_path) <= 0:
|
||||
raise ValueError(f"漏损识别 INP 文件无效: {inp_path}")
|
||||
return inp_path
|
||||
|
||||
Reference in New Issue
Block a user