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
+26
View File
@@ -0,0 +1,26 @@
import pytest
from app.algorithms.demand_allocation import allocate_demand_by_pipe_length
def test_allocate_demand_by_incident_pipe_length():
nodes = {
"J1": {"type": "junction", "links": ["P1"]},
"J2": {"type": "junction", "links": ["P1", "P2"]},
"R1": {"type": "reservoir", "links": ["P2"]},
}
links = {"P1": {"length": 100.0}, "P2": {"length": 300.0}}
result = allocate_demand_by_pipe_length(80.0, nodes, links)
assert result == {"J1": pytest.approx(10.0), "J2": pytest.approx(40.0)}
def test_allocate_demand_returns_empty_for_zero_length_topology():
result = allocate_demand_by_pipe_length(
80.0,
{"J1": {"type": "junction", "links": ["P1"]}},
{"P1": {"length": 0.0}},
)
assert result == {}