feat(investigations): refine report authoring and replay flushing
This commit is contained in:
@@ -10,6 +10,12 @@ SCENARIO_TOOLS = frozenset({
|
||||
})
|
||||
|
||||
|
||||
def flushing_valve_controls(parameters: dict[str, Any]) -> dict[str, dict[str, str]]:
|
||||
"""Apply explicit states without changing regulating-valve settings."""
|
||||
return {**{valve: {"status": "CLOSED"} for valve in parameters.get("closed_valves", [])},
|
||||
**{valve: {"status": "OPEN"} for valve in parameters.get("opened_valves", [])}}
|
||||
|
||||
|
||||
def calculate_scenario(name: str, parameters: dict[str, Any], *, network: str, username: str,
|
||||
model_only: bool = False) -> dict[str, Any]:
|
||||
from app.services import simulation_scenarios as scenarios
|
||||
@@ -60,9 +66,16 @@ def calculate_scenario(name: str, parameters: dict[str, Any], *, network: str, u
|
||||
from app.native.wndb.model.options import get_option
|
||||
if get_option(network).get("UNITS") not in {"LPS", "CMH"}:
|
||||
raise ValueError("Flushing currently supports LPS or CMH models only")
|
||||
boundary = {}
|
||||
if model_only:
|
||||
from app.infra.db.postgresql.scada import ScadaElementMappings
|
||||
boundary["scada_mappings"] = ScadaElementMappings(
|
||||
reservoirs={}, tanks={}, fixed_pumps={}, variable_pumps={},
|
||||
pressure={}, demand={}, quality={},
|
||||
)
|
||||
result = scenarios.flushing_analysis(**common, username=username,
|
||||
drainage_node_ID=parameters["drainage_node_id"], flushing_flow=parameters["flushing_flow_m3h"],
|
||||
modify_valve_opening={valve: 0.0 for valve in parameters["closed_valves"]})
|
||||
valve_control=flushing_valve_controls(parameters), **boundary)
|
||||
elif name == "analyze_pressure_regulation":
|
||||
from app.services.simulation import query_corresponding_element_id_and_query_id
|
||||
mappings = query_corresponding_element_id_and_query_id(network)
|
||||
@@ -102,4 +115,17 @@ def calculate_scenario(name: str, parameters: dict[str, Any], *, network: str, u
|
||||
threshold_mg_l=impact_threshold, model_only=model_only)
|
||||
impact["coverage"] = {**output["coverage"], **impact.get("coverage", {})}
|
||||
output.update(impact)
|
||||
if name == "analyze_flushing":
|
||||
output["flushing_plan"] = {
|
||||
"opened_valves": parameters.get("opened_valves", []),
|
||||
"closed_valves": parameters.get("closed_valves", []),
|
||||
"drainage_node_id": parameters["drainage_node_id"],
|
||||
"flushing_flow_m3h": parameters["flushing_flow_m3h"],
|
||||
"estimated_discharge_volume_m3": parameters["flushing_flow_m3h"] * duration / 3600,
|
||||
"state_basis": "independent_current_model_scenario",
|
||||
"boundary_source": "model_only_no_live_scada" if model_only else "model_with_start_time_scada",
|
||||
"result_scope": "hydraulic_only",
|
||||
"field_execution_verified": False,
|
||||
"water_quality_clearance_verified": False,
|
||||
}
|
||||
return output
|
||||
|
||||
Reference in New Issue
Block a user