Files
Aislo/resources/tester/helper_b05_routeedit_initial_apply.cjs
T
eomsangdonandClaude Sonnet 5.5 58ba4545f2 feat(B05): 노선 추천 알약 여덟(영선 · 안전 우선 · 계류 횡단 최소 · 공사비 어림 최소) · 영선 목표 기울기 칸 · 비교값 두 묶음 (PLAN 23-5b)
- 알약: 예상노선 추적 · 영선 노선 · 토공 최소 · 기울기 순한 · 안전 우선 · 계류 횡단 최소 · 공사비 어림 최소 · 비중 계산 — 짧은 노선 · 흙 균형 뺌 · 네 칸 두 줄(좁으면 두 칸 네 줄)
- 영선 노선일 때만 「목표 기울기」 칸(criteria.target_grade_pct · 비우면 상한) · 응답에서 쓴 값을 기준값 줄에 보임
- 비교값 두 묶음: 노선 · 기울기(목표 기울기 편차 · 옆경사) / 흙 · 안전 · 비용(위험 구간 통과 · 계류 횡단 · 이격 · 공사비 어림 상대값)
- 옛 저장값 short · balance 는 예상노선 추적으로 읽음 · 시험: 새 이름 · 비교값 · 목표 기울기 · 옛 값 · 왕복에 새 넷

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 09:24:38 +09:00

100 lines
3.8 KiB
JavaScript

/* 초기노선 갈래 **저장 왕복**(계획서 20) 헬퍼 — 서버 답을 화면 코드 그대로 편다.
*
* 표준입력 JSON `{ jobs: [...] }` 를 받아 일마다 결과 한 줄을 돌려준다.
* - `apply` : `/route/initial` 답(+보낸 `criteria` 겹침) → 편집값(`normalizeRouteInitial`)
* → [확인] 몸통(`_RouteEdit_Apply` 의 vertices 만들기 · `_Initial.current()` 의
* initial{mode, weights, criteria})
* - `reopen` : `/route/plan` 답 → 다시 연 노드(`flattenServerPlan`) · 현재 초기값(`serverBase`)
* · 캐시 초기값과 같은가(`sameBase` — [초기화]가 캐시 노드를 쓸지 서버에 물을지)
*
* ⚠ 확장자가 `.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;
},
};
}
globalThis.window = { localStorage: memoryStorage(), sessionStorage: memoryStorage() };
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 edits = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_RouteEdit_Edits.ts"));
const { jobs } = JSON.parse(fs.readFileSync(0, "utf8"));
const out = jobs.map((job) => {
if (job.kind === "apply") {
const choice = model.normalizeRouteInitial(
job.response,
job.logic,
job.weights ?? null,
job.criteria ?? null,
);
const { planned, curveOn, curveRadius } = choice.snapshot;
return {
choice,
// `_RouteEdit_Apply` [확인] 몸통 그대로.
body: {
vertices: planned.map(([x, y], index) => ({
x,
y,
curve: curveOn[index] !== false,
radius_m: curveRadius[index] ?? null,
})),
initial: {
mode: choice.logic,
weights: choice.weights,
criteria: choice.criteriaOverrides,
},
},
label: model.choiceLabel(choice.logic, choice.weights),
metrics: model.metricsLines(choice.metrics),
violations: model.violationsLine(choice.metrics),
relaxed: model.relaxedLine(choice),
criteria: model.criteriaLine(choice.criteria, 0),
};
}
const flat = edits.flattenServerPlan(job.plan.nodes ?? [], job.plan.curves ?? []);
const base = model.serverBase(job.plan.current_initial);
return {
planned: flat.planned,
base,
label: model.choiceLabel(base.logic, base.weights),
sameAsCache: job.cached ? model.sameBase(job.cached, base) : null,
};
});
process.stdout.write(JSON.stringify(out));