Files
Aislo/common_util/common_util_station_key.py
T
eomsangdonandClaude Opus 5.5 1c090c0f5e feat(횡단초안): 344-3 측점 열쇠 — 세션 횡단 초안을 측점 열쇠로 · 옛 초안 옮김 · 노선 바뀜 넘김 · 노선 밖 고침 알림
- 열쇠 규칙 한 벌 = common_util_station_key(ts · py 짝 · 거울 시험) — 일반 grid:k · 관 pipe:<id> · 구조물 structure:<id> · 시종점 end:BP/EP · id 모름 at:<0.01 m>
- 세션 칸 다섯(카드 선택 · 노견 확장 · 소단 깊이 · 암 경계 · 암 경사) = 측점 열쇠로 담음 · 부르는 쪽은 그대로 누가거리로 읽고 씀 · 칸마다 쓴 때 자리를 함께 담아 구조물 id 를 아직 모를 때도 그 측점 고침을 읽음
- 옛 초안(누가거리 열쇠)은 읽을 때 측점 열쇠로 옮김 · 지금 측점에 없는 고침은 지우지 않고 남김
- 측점 목록 = 상세가 초안 측점을 얹을 때 · 다시 셈 때 세움(관 id = 관 장부 · 구조물 id = 측점 계획 · 구조물 목록)
- 노선 바뀜 넘김 carryStationDrafts — 카드 선택 넷(지반 유형 · 측구 종류 · 측구 선택 · 2단 경사) · 암 경계 · 암 경사만 · 단면 유형 · 측구 방향은 새 지형이 정함 · 사라진 측점 = 「노선 밖 고침 N 건」 한 줄(부르는 자리 = 3파)
- 옛 시험 셋 새 창구로 맞춤

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfHKQs7J3hQELKMWQMUJEy
2026-10-16 11:45:31 +09:00

53 lines
1.9 KiB
Python

"""측점 열쇠 한 규칙(PLAN 344-3) — 노선이 바뀌어도 같은 측점을 같은 이름으로 부름.
일반 = ``grid:k``(누가거리 ÷ 측점 간격 반올림) · 관 = ``pipe:<id>`` · 구조물 = ``structure:<id>`` ·
시종점 = ``end:BP`` · ``end:EP`` · id 를 모르는 구조물 측점 = ``at:<누가거리 0.01 m>``.
⚠ 파이썬·TS 짝 — ``common_util_station_key.ts`` ``stationKey`` ↔ ``station_key``.
한쪽을 고치면 다른 쪽도 고치고 거울 시험 ``resources/tester/test_344_3_station_key_mirror.py``.
"""
from __future__ import annotations
import math
import re
_LOOSE = re.compile(r"^-?\d+(\.\d+)?$")
def _half_up(value: float) -> int:
"""JS ``Math.round`` 와 같은 반올림(0.5 는 위로)."""
return math.floor(value + 0.5)
def chainage_key(chainage_m: float) -> str:
"""누가거리 0.01 m — 옛 초안 열쇠(``toFixed(2)``)와 같은 자릿수."""
return f"{_half_up(chainage_m * 100) / 100:.2f}"
def station_key(
kind: str,
chainage_m: float,
interval_m: float | None,
station_id: str | None = None,
id_kind: str = "structure",
) -> str:
"""측점 열쇠 — irregular 는 id 가 있으면 pipe: · structure:(``id_kind``) · 없으면 at:."""
if kind == "bp":
return "end:BP"
if kind == "ep":
return "end:EP"
if kind in ("pipe", "structure"):
return f"{kind}:{station_id}" if station_id else f"at:{chainage_key(chainage_m)}"
if kind == "irregular":
return f"{id_kind}:{station_id}" if station_id else f"at:{chainage_key(chainage_m)}"
if interval_m and interval_m > 0:
return f"grid:{_half_up(chainage_m / interval_m)}"
return f"at:{chainage_key(chainage_m)}"
def loose_chainage(key: str) -> float | None:
"""옛 초안 열쇠(누가거리 글) · ``at:`` 열쇠의 누가거리 — 측점 열쇠면 None."""
text = key[3:] if key.startswith("at:") else key
return float(text) if _LOOSE.match(text) else None