feat(B06): 노면공 카드별 포장 얹기 짝 section.pavement — 서버 · 초안 · 거울 시험(88-1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016PSXsvyDxjNmufteN5bqmt
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
"""노면공(G군) 구조물 정본 → 횡단 측점 포장 제원(`section.pavement`).
|
||||
|
||||
범위(start~end · ±0.02 m) 안 측점마다 `[{type_id, spec, thickness_m, start_m, end_m, widening_on}]`.
|
||||
두께 = `options.height_m` · 무늬 = `options.pave_spec` · 확폭 끈 구간 = `options.widening_off`("s-e,s-e").
|
||||
그림 · 정보만 — 토공 면적 · 포장 켜기(`design.paved`)는 건드리지 않음.
|
||||
|
||||
**짝**: `common_util/common_util_structure_pavement.ts` — 브라우저는 저장 전 목록으로 같은 제원을 얹음.
|
||||
거울 시험 `resources/tester/test_b06_structure_pavement_mirror.py`.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import math
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 구간 경계 측점을 구간 안으로 볼 허용 오차(m) — C군 벽(`common_util_structure_walls`)과 같은 값.
|
||||
_EDGE_TOLERANCE_M = 0.02
|
||||
|
||||
|
||||
def _num(value: Any) -> float | None:
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
||||
return None
|
||||
return value if math.isfinite(value) else None
|
||||
|
||||
|
||||
def widening_off_ranges(text: Any) -> list[tuple[float, float]]:
|
||||
"""「시작-끝,시작-끝」(측점 m) → 구간 목록. 못 읽는 조각은 버림(= 켬)."""
|
||||
ranges: list[tuple[float, float]] = []
|
||||
for part in str(text or "").split(","):
|
||||
bounds = part.split("-")
|
||||
if len(bounds) != 2 or not bounds[0].strip() or not bounds[1].strip():
|
||||
continue
|
||||
try:
|
||||
start, end = float(bounds[0]), float(bounds[1])
|
||||
except ValueError:
|
||||
continue
|
||||
if math.isfinite(start) and math.isfinite(end):
|
||||
ranges.append((min(start, end), max(start, end)))
|
||||
return ranges
|
||||
|
||||
|
||||
def pavement_specs_from(
|
||||
structures: list[dict[str, Any]], type_ids: set[str]
|
||||
) -> list[dict[str, Any]]:
|
||||
"""G군 구조물 → 구간 제원. 범위가 없으면(시작 · 끝 · 기준 모두 빔) 건너뜀."""
|
||||
specs: list[dict[str, Any]] = []
|
||||
for item in structures:
|
||||
if item.get("type_id") not in type_ids:
|
||||
continue
|
||||
anchor = _num(item.get("chainage_m"))
|
||||
start = _num(item.get("start_m"))
|
||||
end = _num(item.get("end_m"))
|
||||
start = anchor if start is None else start
|
||||
end = anchor if end is None else end
|
||||
if start is None or end is None:
|
||||
continue
|
||||
options = item.get("options") or {}
|
||||
spec = options.get("pave_spec")
|
||||
specs.append(
|
||||
{
|
||||
"type_id": item["type_id"],
|
||||
"spec": spec if isinstance(spec, str) and spec else None,
|
||||
"thickness_m": _num(options.get("height_m")),
|
||||
"start_m": min(start, end),
|
||||
"end_m": max(start, end),
|
||||
"widening_off": widening_off_ranges(options.get("widening_off")),
|
||||
}
|
||||
)
|
||||
return specs
|
||||
|
||||
|
||||
def _inside(chainage: float, start: float, end: float) -> bool:
|
||||
return start - _EDGE_TOLERANCE_M <= chainage <= end + _EDGE_TOLERANCE_M
|
||||
|
||||
|
||||
def attach_pavement_specs(sections: list[dict[str, Any]], specs: list[dict[str, Any]]) -> int:
|
||||
"""범위 안 측점에 `pavement` 목록을 얹음. 얹은 측점 수를 돌려줌."""
|
||||
attached = 0
|
||||
for section in sections:
|
||||
chainage = _num(section.get("chainage_m"))
|
||||
if chainage is None:
|
||||
continue
|
||||
found = [
|
||||
{
|
||||
"type_id": spec["type_id"],
|
||||
"spec": spec["spec"],
|
||||
"thickness_m": spec["thickness_m"],
|
||||
"start_m": spec["start_m"],
|
||||
"end_m": spec["end_m"],
|
||||
"widening_on": not any(
|
||||
_inside(chainage, start, end) for start, end in spec["widening_off"]
|
||||
),
|
||||
}
|
||||
for spec in specs
|
||||
if _inside(chainage, spec["start_m"], spec["end_m"])
|
||||
]
|
||||
if found:
|
||||
section["pavement"] = found
|
||||
attached += 1
|
||||
return attached
|
||||
|
||||
|
||||
def attach_pavement_structures(project_root: Path, cross_sections: list[dict[str, Any]]) -> int:
|
||||
"""저장된 구조물 정본으로 `section.pavement` 를 얹음. 정본을 못 읽으면 0(비치명)."""
|
||||
from B05_Profile.B05_Profile_Structures_Repository import load_structures
|
||||
from B05_Profile.B05_Profile_Structures_Schema import structure_type_map
|
||||
|
||||
try:
|
||||
type_ids = {key for key, value in structure_type_map().items() if value.group == "G"}
|
||||
structures = [item.model_dump() for item in load_structures(str(project_root))[1]]
|
||||
except Exception: # noqa: BLE001 — 정본을 못 읽어도 횡단 조회는 이어 감
|
||||
logger.exception("B06 노면공 정본을 읽지 못했습니다 (없는 것으로 본다)")
|
||||
return 0
|
||||
return attach_pavement_specs(cross_sections, pavement_specs_from(structures, type_ids))
|
||||
Reference in New Issue
Block a user