Files
Aislo/resources/tester/helper_349_0j_draft_vs_saved.cjs
T
eomsangdonandClaude Opus 5.5 bdd6255763 fix(계산묶음): 349-0r cross 입력에 암 경계 기본값 — 초안 새 측점도 서버 config 값(화면이 문맥에서 기억)
- design_pipeline_cross pipelineCrossSource 입력에 rockBoundaryDefaultM: readRockBoundaryDefault(projectId)
- 그 모듈을 가짜로 갈음하는 도움 파일 10개 가짜에 readRockBoundaryDefault: () => -0.5
- 검증_sub2b 같은 끌기(진짜 cross 입력 길): 미리보기 1,184.7 대 정본 1,184.0
- 시험: 바뀐 도움 파일 시험 10 + 349-0n · 0p = 77 통과 · typecheck 0

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

276 lines
10 KiB
JavaScript

/* PLAN 349-0j 헬퍼 — 노선 초안 미리보기(계산 묶음 cross) 대 [저장] 정본: 미교차 넓힘.
* 진짜 TS(`design_pipeline_page` · 단계 파일 전부)를 트랜스파일해 Node 로 돌림 · 서버 창구만 가짜(틀 =
* `helper_346_2_pipeline_cross_page.cjs`). cross 단계에 설계 지형 격자를 넘김(묶음이 넘길 몫 — 넘기기 전/뒤 둘 다 셈).
* 입력 argv[2] JSON · argv[3] 격자 이진. 결과 = 표준출력 JSON. 짝 = `test_349_0j_draft_vs_saved.py`. */
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const CATALOG = require("./helper_322_catalog_module.cjs");
const ROOT = path.join(__dirname, "..", "..");
const job = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
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 = {
sessionStorage: memoryStorage(),
localStorage: memoryStorage(),
setTimeout,
clearTimeout,
};
// 흙 배분 서버 — 늦게 답함 · 끊기면 버림
const haul = { calls: 0, aborted: 0, answered: 0 };
globalThis.fetch = (url, init) =>
new Promise((resolve, reject) => {
haul.calls += 1;
const timer = setTimeout(() => {
haul.answered += 1;
resolve({ ok: true, json: async () => ({ haul_plan: { blocks: [], url } }) });
}, job.haulDelayMs);
init.signal.addEventListener("abort", () => {
clearTimeout(timer);
haul.aborted += 1;
reject(new Error("aborted"));
});
});
const STUBS = {};
const cache = new Map();
function loadTs(full) {
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 (CATALOG.isCatalogRequest(request)) return CATALOG;
const key = Object.keys(STUBS).find((name) => request.endsWith(name));
if (key) return STUBS[key];
if (request.startsWith("@config/")) return { API_BASE_URL: "http://fake" };
if (request.startsWith("@util/"))
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.ts`));
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);
return box.exports;
}
const load = (...parts) => loadTs(path.join(ROOT, ...parts));
const sampler = load("common_util", "common_util_surface_sampler.ts");
const bytes = fs.readFileSync(process.argv[3]);
const grid = sampler.parseDtmGrid(
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.length),
);
const local = { grid, design: "las" };
STUBS["B05_Profile_Api_Replan"] = {
analysisTerrain: () => "las",
fetchRoutePlan: async () => ({
planned: job.line,
curves: [],
min_radius_m: job.minRadius,
station_snap: false,
}),
};
STUBS["B05_Profile_Api_Structures"] = {
fetchStructures: async () => ({ structures: [] }),
fetchStructureTypes: async () => job.types,
};
STUBS["B05_Profile_Api_TerrainGrid"] = {
loadDesignTerrainGrid: async () => local,
groundStageDeps: () => ({ grid: () => local, remote: async () => [] }),
};
STUBS["B04_PreProcess_Api_Fetch"] = {
fetchDetailPipePoints: async () => ({
pipe_points: job.pipes.map((pipe) => ({ ...pipe, lonlat: [0, 0] })),
}),
};
STUBS["B06_Section_UI_Standard_Panel"] = {
effectiveStandardCross: () => job.standard,
readRockBoundaryDefault: () => -0.5,
};
STUBS["B06_Section_Cross_Refresh"] = {
holdScreenAlignment: () => () => undefined,
refreshCrossDesigns: async () => [],
};
STUBS["B06_Section_UI_Section_Common"] = {
staleChainages: (key) => (key ? key.split("|").map((entry) => Number(entry.split(":")[0])) : []),
};
// 묶음이 cross 단계에 설계 지형 격자를 넘김(ground 단계와 같은 `groundStageDeps(projectId).grid`)
let withGrid = false;
const realCross = load("B06_Section", "logic", "B06_Section_Cross_Stage.ts");
STUBS["B06_Section_Cross_Stage"] = {
...realCross,
createCrossStage: () => realCross.createCrossStage(withGrid ? { grid: () => local } : {}),
};
const pipeMod = load("A00_Common", "design", "logic", "design_pipeline.ts");
const pageMod = load("A00_Common", "design", "design_pipeline_page.ts");
const stationsMod = load("A00_Common", "design", "logic", "design_pipeline_stations.ts");
const routeGround = load("B05_Profile", "logic", "B05_Profile_Pipeline_RouteGround.ts");
const grade = load("B05_Profile", "logic", "B05_Profile_Pipeline_Grade.ts");
const gradeGround = load("B05_Profile", "logic", "B05_Profile_Grade_Ground.ts");
const detailMod = load("B05_Profile", "logic", "B05_Profile_Pipeline_Detail.ts");
const alignment = load("B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.ts");
const editMod = load("B05_Profile", "B05_Profile_UI_Profile_Edit.ts");
const page = load("A00_Common", "b_page_state.ts");
const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
const runs = () => globalThis.__aisloPipeline?.runs ?? [];
async function settle(count) {
for (let i = 0; i < 400; i += 1) {
const last = runs()[runs().length - 1];
if (runs().length >= count && last && last.outcome !== "running") return last;
await tick(5);
}
throw new Error("묶음이 끝나지 않음");
}
const n = job.nodes.length;
const draftOf = (nodes) => ({
nodes,
curveOn: Array(n).fill(true),
curveRadius: Array(n).fill(null),
curveLock: Array(n).fill(null),
curveArc: Array(n).fill(null),
stationSnap: false,
});
const shift = (index, dx, dy) =>
job.nodes.map((node, i) => (i === index ? [node[0] + dx, node[1] + dy] : node));
/** 저장 기준 — 저장 노선 지반 첫 계획선(관 측점 포함 · 서버 정책 그대로). */
async function savedBaseOf() {
const seed = pipeMod.createDesignPipeline({
stages: {
route: routeGround.createRouteStage({
minRadiusM: () => job.minRadius,
savedLine: () => ({ line: job.line, curves: [] }),
}),
stations: stationsMod.createStationsStage({
intervalM: job.interval,
types: () => job.types,
}),
ground: routeGround.createGroundStage({ grid: () => local, remote: async () => [] }),
},
});
await seed.start({ route: null, alignment: null, cross: null, pipes: job.pipes, structures: [] });
const ground = seed.output("ground");
seed.dispose();
const samples = ground.longitudinal.chainageM.map((c, i) => ({
chainage_m: c,
elevation_m: ground.longitudinal.z[i],
}));
const profile = gradeGround.groundProfile(samples);
return {
policy: job.policy,
onlyExplicitCurves: false,
basePvi: gradeGround.groundFollowingBasePvi({
samples,
stations: ground.stations.map((s) => s.chainageM),
policy: job.policy,
}),
chainage: profile.chainage,
ground: profile.ground,
stations: ground.stations.map((s) => ({
station_id: grade.stationIdOf(s.chainageM),
chainage_m: s.chainageM,
})),
};
}
async function draftRun(P, grid) {
withGrid = grid;
window.localStorage.setItem("frd_current_project_id", P);
const savedBase = await savedBaseOf();
const seedRuns = runs().length;
const link = {
pipelineSource: () => ({
base: savedBase,
edits: alignment.emptyEdits(),
detail: job.detail,
routeId: 7,
}),
adoptPipeline: () => undefined,
redraw: () => undefined,
};
const bridge = pageMod.routeDraftBridge(P, link, { stationIntervalM: job.interval });
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
const pipe = pageMod.pagePipeline(P);
await settle(seedRuns + 1);
const [a] = job.drags;
const moved = job.nodes.map((node, i) =>
i === a.index ? [node[0] + a.dx, node[1] + a.dy] : node,
);
bridge.edited(draftOf(moved));
const run = await settle(runs().length + 1);
await tick(job.haulDelayMs + 20);
const profile = pipe.output("profile");
const cross = pipe.output("cross");
const shown = pageMod.pipelineDetail(P);
const stations = pipe.output("ground").stations.map((s) => {
const design = cross.byKey[s.key]?.detail ?? null;
const line = design?.design_line ?? [];
return {
key: s.key,
chainage: s.chainageM,
elevation: alignment.planElevationAt(profile, s.chainageM),
cut: design?.cut_area_m2 ?? null,
fill: design?.fill_area_m2 ?? null,
unclosed: design?.slope_unclosed ?? null,
lineEnds: line.length ? [line[0].offset_m, line[line.length - 1].offset_m] : null,
};
});
const copied = shown.cross_sections.every(
(section, i) =>
!section.design ||
section.design !== cross.byKey[pipe.output("ground").stations[i].key]?.detail,
);
// 상세 표본 = cross 단계가 넓힌 표본(349-0n) — 구조물 면적이 넓힌 지반으로 닫힘
const keys = pipe.output("ground").stations.map((s) => s.key);
const shownWide = shown.cross_sections.filter((section, i) => {
const samples = cross.byKey[keys[i]]?.samples;
return samples && JSON.stringify(section.samples) === JSON.stringify(samples);
}).length;
const out = {
outcome: run.outcome,
shownWide,
totalMs: run.totalMs,
line: pipe.output("route").line,
curves: pipe.output("route").curves,
final: pipe.output("masshaul")?.haulInput?.final_cumulative_m3 ?? null,
stations,
copied,
};
pageMod.disposePagePipeline(P);
page.clearDrafts(P);
return out;
}
async function run() {
const plain = await draftRun("proj-3490j-a", false);
const wide = await draftRun("proj-3490j-b", true);
return { plain, wide };
}
run()
.then((out) => {
process.stdout.write(JSON.stringify(out));
process.exit(0);
})
.catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});