Files
Aislo/resources/tester/test_349_0d_follow_store.py
T
eomsangdonandClaude Opus 5.5 401c53251b feat(계산묶음): 349-0d 노선을 놓으면 관 · 구조물 새 측점을 가게에 바로 — 목록 · 알약 · 횡단 보기
- 사용자 노선 조작 뒤 follow 가 좌표로 다시 매긴 관 · 구조물 = 가게 초안(pipes · structures) · 놓은 틱 안에 써 되돌리기 한 걸음 · 묶음 다시 돎 0(가게 메아리는 입력으로 안 받음)
- 초안을 버리면(되돌리기 · 버림) 초안 전 가게 값으로 · 열기만 하면 안 씀(349-0c)
- 새 노선에서 20 m 넘게 먼 구조물 = 알림 한 줄(구조물 N건이 새 노선에서 20 m 넘게 멀어짐)
- 종단 보기 왼쪽 목록 · 구조물 알약 · 측점선 = 가게 측점(배수유역도 관 알림을 가게 관 측점으로 · 관 id 옮김) · 따라간 측점은 계획고 편집 안 옮김(follow 몫)
- 시험 test_349_0d_follow_store 5건(검증_sub7 노선 · 관 · 옛 코드 2 실패 재현)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TteK8mfYZetk5P3bEZkyVZ
2026-10-16 15:01:28 +09:00

203 lines
7.5 KiB
Python

"""PLAN 349-0d sub7 — 노선을 놓으면 관 · 구조물 새 측점이 가게에 바로.
· 열기만 = 가게 안 씀(저장값 그대로)
· 꼭짓점 한 번 끌기 = 묶음 한 번 · 가게 관 · 구조물 측점 바뀜
· 사진첩이 찍기 전(setTimeout 0)에 씀(한 걸음)
· 새 노선에서 20 m 넘게 먼 구조물 수 알림
· 되돌리기(사진첩이 세션을 되씀) · 초안만 버림 = 초안 전 값(가게 비움 · 입력 = 저장 관)
· 계산 · 알림 안 입력 쓰기 0
짝: `helper_349_0d_follow_store.cjs`(실제 TS 를 Node 로 · 서버 창구만 가짜 · 검증_sub7 노선 · 관).
"""
from __future__ import annotations
import csv
import json
import math
import subprocess
import sys
import tempfile
from pathlib import Path
import pytest
HERE = Path(__file__).resolve().parent
ROOT = HERE.parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from B05_Profile.B05_Profile_Structures_Schema import structure_type_map # noqa: E402
from common_util.common_util_surface_sampler import dtm_grid_bytes # noqa: E402
from config.config_system_design import STANDARD_CROSS_SECTION # noqa: E402
pytestmark = pytest.mark.skipif(
not (ROOT / "config" / "node_modules" / "typescript").is_dir(),
reason="프론트엔드 의존성 미설치",
)
PROJECT = ROOT / "storage/1/3/6d3b2812-6d5a-4168-a932-40e4ae303d5a" # 검증_sub7
ROUTE = PROJECT / "B05_Profile/route"
SECTION = PROJECT / "B06_Section"
GRID = PROJECT / "B04_PreProcess/models/dtm_classification_smooth.npz"
ONES = {g: {"loose": 1.0, "compacted": 1.0} for g in ("soil", "ripping_rock", "blasting_rock")}
def _csv(path: Path) -> list[list[float]]:
with path.open(encoding="utf-8") as handle:
return [[float(r["x"]), float(r["y"])] for r in csv.DictReader(handle)]
def _json(path: Path):
return json.loads(path.read_text(encoding="utf-8"))
def _structure(sid: str, line: list[list[float]], ratio: float, off: float) -> dict:
"""노선 위(off 0) · 옆(off m) 점 구조물 — 저장 노선 누가거리 · 좌표."""
lengths = [math.dist(a, b) for a, b in zip(line, line[1:])]
at = sum(lengths) * ratio
walked = 0.0
for (a, b), length in zip(zip(line, line[1:]), lengths):
if walked + length >= at:
t = (at - walked) / length
dx, dy = (b[0] - a[0]) / length, (b[1] - a[1]) / length
x, y = a[0] + dx * length * t - dy * off, a[1] + dy * length * t + dx * off
break
walked += length
return {
"structure_id": sid,
"type_id": "erosion_check",
"placement": "point",
"chainage_m": round(at, 2),
"start_m": None,
"end_m": None,
"x": x,
"y": y,
"options": {},
}
@pytest.fixture(scope="module")
def r() -> dict:
if not (GRID.is_file() and (SECTION / "longitudinal/longitudinal.json").is_file()):
pytest.skip("검증_sub7 없음")
curves = _json(ROUTE / "planned_route_curves.json")
sections = sorted(
(_json(p) for p in (SECTION / "cross_sections").glob("cross_*.json")),
key=lambda s: s["chainage_m"],
)
pipes = _json(PROJECT / "B04_PreProcess/drainage/edits/pipe_points.json")["points"]
line = _csv(ROUTE / "planned_route.csv")
structures = [_structure("s-near", line, 0.5, 0.0), _structure("s-far", line, 0.7, 30.0)]
job = {
"line": line,
"structures": structures,
"nodes": _csv(ROUTE / "planned_route_nodes.csv"),
"curves": [
{k: c[k] for k in ("start", "apex", "end", "radius_m")} for c in curves["curves"]
],
"stationSnap": bool(curves.get("station_snap")),
"minRadius": curves["min_radius_m"],
"interval": 20.0,
"types": [
{"type_id": t.type_id, "group": t.group, "placement": t.placement}
for t in structure_type_map().values()
],
"pipes": pipes,
"standard": STANDARD_CROSS_SECTION,
"conversion": ONES,
"detail": {
"longitudinal": _json(SECTION / "longitudinal/longitudinal.json"),
"cross_sections": sections,
},
}
with tempfile.TemporaryDirectory() as folder:
path = Path(folder) / "job.json"
path.write_text(json.dumps(job), encoding="utf-8")
grid = Path(folder) / "grid.bin"
grid.write_bytes(dtm_grid_bytes(GRID))
proc = subprocess.run( # noqa: S603 — 고정 실행 파일
["node", str(HERE / "helper_349_0d_follow_store.cjs"), str(path), str(grid)],
capture_output=True,
text=True,
encoding="utf-8",
timeout=300,
)
assert proc.returncode == 0, proc.stderr
return json.loads(proc.stdout)
def test_열기만_하면_가게_안_씀(r):
o = r["open"]
assert o["storePipes"] is None and o["storeStructures"] is None
assert o["followed"] == []
def test_꼭짓점_끌기_가게에_새_측점_한_번(r):
d = r["drag"]
assert d["runs"] == [["route"]], d["runs"]
assert d["pipes"] == d["inputPipes"]
assert d["pipes"] != r["saved"]
assert len(d["pipes"]) == len(r["saved"]) # 같은 관 그대로(자리만 다시 매김)
assert {i: c for i, c in d["structures"]} != {i: c for i, c in r["savedStructures"]}
assert d["atRecord"] == {"pipes": d["pipes"], "structures": d["structures"]} # 한 걸음 안
assert d["followed"] == [1] # s-far 만 20 m 넘음
assert d["blocked"] == 0
def test_되돌리기_초안_전_값(r):
u = r["undo"]
assert u["runs"] == [["route"]], u["runs"]
assert u["storePipes"] is None and u["storeStructures"] is None
assert u["inputPipes"] == r["saved"]
assert u["followed"] == [1, 0]
def test_초안만_버림_초안_전_값(r):
d = r["drop"]
assert d["second"] != r["saved"]
assert d["storePipes"] is None
assert d["inputPipes"] == r["saved"]
assert d["blocked"] == 0
_REPORTS_JS = r"""
const fs = require("fs");
const ts = require(process.argv[1] + "/config/node_modules/typescript");
const file = process.argv[1] + "/B05_Profile/logic/B05_Profile_Pipeline_Follow.ts";
const src = fs.readFileSync(file, "utf8");
const options = { compilerOptions: { module: ts.ModuleKind.CommonJS } };
const js = ts.transpileModule(src, options).outputText;
const box = { exports: {} };
new Function("exports", "module", js)(box.exports, box);
const f = box.exports.followPipeReports;
const reports = [
{ chainage_m: 86, effective_diameter_mm: 800, start_m: 84, end_m: 88 },
{ chainage_m: 175, effective_diameter_mm: 1000 },
];
const pipes = [{ chainage_m: 179.374 }, { chainage_m: 89.123, start_m: 87.5 }];
process.stdout.write(JSON.stringify({
moved: f(reports, pipes),
saved: f(reports, null),
count: f(reports, pipes.slice(1)),
}));
"""
def test_관_알림_목록_가게_측점으로():
proc = subprocess.run( # noqa: S603 — 고정 실행 파일
["node", "-e", _REPORTS_JS, str(ROOT)],
capture_output=True,
text=True,
encoding="utf-8",
timeout=60,
)
assert proc.returncode == 0, proc.stderr
out = json.loads(proc.stdout)
first, second = out["moved"]
assert (first["chainage_m"], first["effective_diameter_mm"]) == (89.12, 800)
assert first["start_m"] == 87.5 # 가게 구간 그대로
assert abs(first["end_m"] - 91.12) < 1e-9 # 없으면 옮긴 만큼
assert (second["chainage_m"], second["effective_diameter_mm"]) == (179.37, 1000)
assert [p["chainage_m"] for p in out["saved"]] == [86, 175]
assert [p["chainage_m"] for p in out["count"]] == [86, 175] # 관 수 다르면 그대로