refactor(backend)!: separate algorithm and data layers

Reorganize algorithm packages by business responsibility, move orchestration into services, and keep database access behind pooled repositories.

Harden analysis API validation, remove unsafe legacy simulation endpoints, and add regression and architecture boundary coverage.

BREAKING CHANGE: legacy algorithm module paths and obsolete simulation endpoints are removed.
This commit is contained in:
2026-09-04 17:30:55 +08:00
parent 9b095c7439
commit 5966d039de
91 changed files with 1418 additions and 4020 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Application workflows for demand allocation."""
from app.algorithms.demand_allocation import allocate_demand_by_pipe_length
from app.native.wndb.gis.region_geometry import Topology, get_nodes_in_region
from app.native.wndb.model.elements import get_nodes
def calculate_demand_to_nodes(
project_code: str,
demand: float,
node_ids: list[str],
) -> dict[str, float]:
if not node_ids or demand == 0.0:
return {}
topology = Topology(project_code, node_ids)
return allocate_demand_by_pipe_length(
demand,
topology.nodes(),
topology.links(),
)
def calculate_demand_to_region(
project_code: str,
demand: float,
region_id: str,
) -> dict[str, float]:
node_ids = get_nodes_in_region(project_code, region_id)
return calculate_demand_to_nodes(project_code, demand, node_ids)
def calculate_demand_to_network(
project_code: str,
demand: float,
) -> dict[str, float]:
node_ids = get_nodes(project_code)
return calculate_demand_to_nodes(project_code, demand, node_ids)