Files
Aislo/resources/tester/helper_b05_routeedit_initial.cjs
T
eomsangdonandClaude Opus 5.5 4366cd3f03 fix(B05): 초기노선 갈래 화면을 서버 길 모양(PLAN 20장 API 줄)에 맞춤
- 요청 { mode, weights?{expected, earthwork, grade} } — logic · slope 가정을 버림
- 비교값 avg_grade_pct · over_limit.total · offset_avg_m, 기준값 pending(비면 확정) 읽기
- [확인] 몸통 initial 도 { mode, weights }
- 시험 test_b05_routeedit_initial.py 를 서버 답 모양으로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015sCeZz8z8YnbovsKgn7HK7
2026-09-29 10:03:38 +09:00

183 lines
5.5 KiB
JavaScript

/* 계획노선 편집 창 **초기노선 갈래**(계획서 20) 셈 단위검증 헬퍼 —
* `B05_Profile_UI_RouteEdit_Initial_Model.ts` 를 그 자리에서 트랜스파일해 Node 로 돌린다.
*
* ⚠ 확장자가 `.cjs` 인 까닭은 `helper_b05_cut_merged_loop.cjs` 머리에 적힌 것과 같다.
* 브라우저 전용인 저장소는 가짜로 채운다 — 셈만 본다.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
const cache = new Map();
function memoryStorage() {
const map = new Map();
return {
getItem: (key) => (map.has(key) ? map.get(key) : null),
setItem: (key, value) => map.set(key, String(value)),
removeItem: (key) => map.delete(key),
key: (index) => [...map.keys()][index] ?? null,
get length() {
return map.size;
},
_map: map,
};
}
const session = memoryStorage();
globalThis.window = { localStorage: memoryStorage(), sessionStorage: session };
globalThis.fetch = () => Promise.resolve({ ok: false });
const STUBS = { "@ui/ui_template_palette": { themeColor: (_name, fallback) => fallback } };
function loadTs(file) {
const full = path.resolve(file);
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
const model = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_RouteEdit_Initial_Model.ts"));
const { DEFAULT_WEIGHTS } = model;
// ① 비중 맞추기 — 하나를 옮기면 나머지 둘이 비율대로 나눠 합 100.
const moves = [
model.rebalanceWeights(DEFAULT_WEIGHTS, "expected", 70),
model.rebalanceWeights(DEFAULT_WEIGHTS, "earthwork", 40),
model.rebalanceWeights({ expected: 100, earthwork: 0, grade: 0 }, "expected", 60),
model.rebalanceWeights({ expected: 20, earthwork: 30, grade: 50 }, "grade", 100),
model.rebalanceWeights({ expected: 33, earthwork: 33, grade: 34 }, "earthwork", 33.4),
model.rebalanceWeights(DEFAULT_WEIGHTS, "grade", -5),
];
// ② 서버 답 펴기 — 노드 목록 꼴과 `/route/plan` 꼴(노드+곡선) 둘 다.
const plain = model.normalizeRouteInitial(
{
nodes: [
{ x: 0, y: 0 },
{ x: 50, y: 10, curve: true, radius_m: 30 },
{ x: 100, y: 0, curve: false },
],
// 계획서 20 「API」 줄 모양.
metrics: {
length_m: 1234.56,
max_grade_pct: 12.34,
avg_grade_pct: 6.1,
cut_m3: 1500.4,
fill_m3: 900,
over_limit: { grade: 1, radius: 0, stream: 1, total: 2 },
offset_avg_m: 3.25,
offset_max_m: 9.8,
},
criteria: {
max_grade_pct: 14,
min_radius_m: 12,
stream_offset_m: 5,
road_width_m: 4,
corridor_m: 100,
pending: ["max_grade_pct", "stream_offset_m"],
},
},
"earthwork",
null,
);
const planShape = model.normalizeRouteInitial(
{
nodes: [
{ x: 0, y: 0, radius_m: null, inner_angle_deg: null, tangent_m: null, violations: [] },
{ x: 40, y: 30, radius_m: 25, inner_angle_deg: 140, tangent_m: 9, violations: [] },
{ x: 90, y: 30, radius_m: null, inner_angle_deg: null, tangent_m: null, violations: [] },
],
curves: [
{
apex: [40, 30],
radius_m: 25,
tangent_m: 9,
inner_angle_deg: 140,
start: [33, 25],
end: [49, 30],
node_first: 1,
node_last: 1,
violations: [],
},
],
},
"weighted",
{ expected: 60, earthwork: 20, grade: 20 },
);
let tooShort = "";
try {
model.normalizeRouteInitial({ nodes: [{ x: 1, y: 1 }] }, "gentle", null);
} catch (error) {
tooShort = error.message;
}
// ③ 글 — 현재 초기값 · 비교값 · 기준값.
const labels = {
follow: model.choiceLabel("follow", null),
weighted: model.choiceLabel("weighted", { expected: 60, earthwork: 20, grade: 20 }),
metrics: model.metricsLine(plain.metrics),
metricsNone: model.metricsLine(null),
criteria: model.criteriaLine(plain.criteria, 0),
criteriaConfirmed: model.criteriaLine({ ...plain.criteria, confirmed: true }, 0),
criteriaFallback: model.criteriaLine(null, 15),
pendingEmpty: model.normalizeRouteInitial(
{
nodes: [
{ x: 0, y: 0 },
{ x: 9, y: 9 },
],
criteria: { pending: [] },
},
"gentle",
null,
).criteria.confirmed,
};
// ④ 캐시 왕복 — 결과 통 프로젝트 칸. 꼴이 틀린 값은 안 읽는다.
model.writeInitialChoice("p-1", plain);
const readBack = model.readInitialChoice("p-1");
const other = model.readInitialChoice("p-2");
const keys = [...session._map.keys()];
session._map.set(
keys[0],
JSON.stringify({
logic: "nope",
snapshot: {
planned: [
[0, 0],
[1, 1],
],
},
}),
);
const badLogic = model.readInitialChoice("p-1");
model.writeInitialChoice("p-1", null);
const cleared = model.readInitialChoice("p-1");
process.stdout.write(
JSON.stringify({
moves,
plain,
planShape,
tooShort,
labels,
readBack,
other,
keys,
badLogic,
cleared,
}),
);