Files
Aislo/resources/tester/test_369_drainage_auto.py
T

66 lines
2.8 KiB
Python

"""369 배수 구조물 자리 — 기본 = 세류선 교차만 · 목록 있으면 그대로 · 낡은 분석은 관 자리만.
- 목록 없음 = 세류선 교차 관만 · 100 m 보충 없음 · 관 자리 후보는 셈.
- 목록 있음 = 그 자리 그대로(보충은 후보만) · [자동 제안] = 510 (`test_510_auto_pipe_propose.py`).
"""
import asyncio
from pathlib import Path
from uuid import uuid4
import numpy as np
from B04_PreProcess import B04_PreProcess_Router_Basins as basins
from B04_PreProcess.B04_PreProcess_Engine_Watershed_Grid import GridSpec
from common_util.common_util_drainage_context import DrainageContext
from common_util.common_util_drainage_detail import RoadRouting, build_detail
from common_util.common_util_route_geometry import RouteVertex, StructureCandidate
VERTICES = [RouteVertex(0.0, 0.0, 100.0, 0.0), RouteVertex(300.0, 0.0, 90.0, 300.0)]
CONTEXT = DrainageContext(stored_path="x", project_root=Path("."), vertices=VERTICES)
def _routing() -> RoadRouting:
spec = GridSpec(x_min=-5.0, y_max=5.0, cell_m=1.0, n_rows=10, n_cols=310)
road_index = np.arange(5 * 310 + 5, 5 * 310 + 305, dtype=np.int32)
road_slot = np.full(spec.size, -1, dtype=np.int32)
road_slot[road_index] = np.arange(road_index.size)
return RoadRouting(
spec=spec,
road_slot=road_slot,
path_length=np.zeros(spec.size, np.float32),
elevation=np.full(spec.size, 95.0, np.float32),
road_cell_index=road_index,
road_chainage=np.arange(road_index.size, dtype=np.float64),
strength=np.ones(road_index.size, np.int64),
base_pipes=[StructureCandidate(chainage_m=150.0, x=150.0, y=0.0, reason="stream")],
)
def _detail(tmp_path, chainages=None):
return build_detail(tmp_path / "없음", VERTICES, chainages, _routing(), [])
def test_기본은_세류선_교차만(tmp_path):
detail = _detail(tmp_path)
assert [(p.chainage_m, p.reason) for p in detail.pipes] == [(150.0, "stream")]
assert len(detail.pipe_candidates) == 2 # 0~150 · 150~300 이 100 m 넘음 — 제안만
def test_목록은_그대로_보충은_후보만(tmp_path):
plain = _detail(tmp_path, [20.0])
assert [p.chainage_m for p in plain.pipes] == [20.0] and len(plain.pipe_candidates) == 2
def test_낡은_분석은_관_자리만_낡음으로(monkeypatch):
async def load(project_id):
return CONTEXT, ""
monkeypatch.setattr(basins, "load_drainage_context", load)
monkeypatch.setattr(basins, "analysis_route_signature", lambda stored: "옛 노선")
points = [{"chainage_m": 20.0}]
kept = asyncio.run(basins._resolve(uuid4(), {"points": points}, use_stored=False))
assert kept[-1] is True # 관 목록 있음 = 관 자리만 낡음으로
none = asyncio.run(basins._resolve(uuid4(), {}, use_stored=False))
assert none.status_code == 409 # 목록 없음 = 낡음 까닭