- 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
235 lines
8.2 KiB
JavaScript
235 lines
8.2 KiB
JavaScript
/* PLAN 349-0g sub7 헬퍼 — 노선 초안을 둔 채 횡단 보기(B06)가 묶음 새 노선 상세를 종단도에 그려도 묶음이 다시
|
|
* 안 돎(고리 없음) · 누가토량 그대로. B06 흉내 = 묶음 profile · cross 알림마다 새 상세를 종단도에 render
|
|
* (`design_profile.render` → 처음부터 다시 · 유토곡선 설정 → 횡단 입력)과 같은 부름.
|
|
* 진짜 TS 를 트랜스파일해 Node 로 · 서버 창구만 가짜(`helper_349_pipeline_once` 와 같은 틀).
|
|
* 입력 argv[2] JSON · argv[3] 격자 이진. 결과 = 표준출력 JSON. 짝 = `test_349_0g_draft_b06_loop.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,
|
|
};
|
|
|
|
// 흙 배분 서버 — 늦게 답함 · 끊기면 버림
|
|
globalThis.fetch = (url, init) =>
|
|
new Promise((resolve, reject) => {
|
|
const timer = setTimeout(
|
|
() => resolve({ ok: true, json: async () => ({ haul_plan: { blocks: [], url } }) }),
|
|
20,
|
|
);
|
|
init.signal.addEventListener("abort", () => {
|
|
clearTimeout(timer);
|
|
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: job.curves,
|
|
min_radius_m: job.minRadius,
|
|
station_snap: job.stationSnap,
|
|
}),
|
|
};
|
|
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,
|
|
};
|
|
|
|
const pageMod = load("A00_Common", "design", "design_pipeline_page.ts");
|
|
const storeMod = load("A00_Common", "design", "design_store.ts");
|
|
const alignment = load("B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.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 quiet() {
|
|
let seen = -1;
|
|
for (let i = 0; i < 400; i += 1) {
|
|
await tick(15);
|
|
const last = runs()[runs().length - 1];
|
|
const count = runs().length;
|
|
if (count === seen && (!last || last.outcome !== "running")) return;
|
|
seen = count;
|
|
}
|
|
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: job.stationSnap,
|
|
});
|
|
const shift = (index, dx, dy) =>
|
|
job.nodes.map((node, i) => (i === index ? [node[0] + dx, node[1] + dy] : node));
|
|
const chainagesOf = (stations) => (stations ?? []).map((s) => s.chainageM);
|
|
|
|
const P = "proj-3490g";
|
|
|
|
async function run() {
|
|
window.localStorage.setItem("frd_current_project_id", P);
|
|
const savedAlignment = job.detail.longitudinal.profile_alignment;
|
|
const savedBase = alignment.toAlignmentBase(savedAlignment);
|
|
let detail = job.detail; // 종단도가 지금 그린 상세
|
|
let b06 = false;
|
|
const link = {
|
|
pipelineSource: () => ({ base: savedBase, edits: savedAlignment.edits, detail, routeId: 7 }),
|
|
adoptPipeline: (base, edits, draft) =>
|
|
pageMod.pipelineGrade(P, draft ? edits : savedAlignment.edits),
|
|
redraw: () => undefined,
|
|
side: null,
|
|
};
|
|
const bridge = pageMod.routeDraftBridge(P, link, { stationIntervalM: job.interval });
|
|
/** 횡단 보기 render — 카드 상세(새 노선 상세 ?? 저장)를 종단도에 · 유토곡선 설정. */
|
|
const renderB06 = () => {
|
|
detail = pageMod.pipelineDetail(P) ?? job.detail;
|
|
pageMod.restartPagePipeline(P);
|
|
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
|
|
};
|
|
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
|
|
await quiet();
|
|
const pipe = pageMod.pagePipeline(P);
|
|
let drawn = pageMod.pipelineDetail(P);
|
|
pipe.subscribe((event) => {
|
|
if (!b06 || event.kind !== "stage" || (event.stage !== "profile" && event.stage !== "cross"))
|
|
return;
|
|
const next = pageMod.pipelineDetail(P);
|
|
if (next === drawn) return;
|
|
drawn = next;
|
|
void Promise.resolve().then(renderB06);
|
|
});
|
|
const final = () => pipe.output("masshaul")?.haulInput?.final_cumulative_m3 ?? null;
|
|
const cut = () =>
|
|
Object.values(pipe.output("cross")?.byKey ?? {}).reduce((s, c) => s + (c.cutAreaM2 ?? 0), 0);
|
|
|
|
// B05 — 꼭짓점 한 번 끌어 놓기
|
|
let mark = runs().length;
|
|
bridge.edited(draftOf(shift(1, -8, 0)));
|
|
await quiet();
|
|
const b05 = {
|
|
runs: runs()
|
|
.slice(mark)
|
|
.map((r) => r.sources),
|
|
final: final(),
|
|
cut: cut(),
|
|
};
|
|
|
|
// B06 로 — 그리기 여러 번
|
|
b06 = true;
|
|
mark = runs().length;
|
|
for (let i = 0; i < 5; i += 1) {
|
|
renderB06();
|
|
await quiet();
|
|
}
|
|
const inB06 = {
|
|
runs: runs().slice(mark).length,
|
|
final: final(),
|
|
cut: cut(),
|
|
drawnIsDraft: detail === pageMod.pipelineDetail(P),
|
|
};
|
|
|
|
// B06 에서 조작 하나(계획고) = 한 번
|
|
mark = runs().length;
|
|
const edits = {
|
|
station_offsets: { [alignment.chainageKey(savedBase.stations[4].chainage_m)]: 0.3 },
|
|
curve_radii: {},
|
|
};
|
|
pageMod.pipelineGrade(P, edits);
|
|
await quiet();
|
|
const grade = {
|
|
runs: runs()
|
|
.slice(mark)
|
|
.map((r) => r.sources),
|
|
};
|
|
|
|
// B05 로 돌아옴
|
|
b06 = false;
|
|
mark = runs().length;
|
|
detail = job.detail;
|
|
pageMod.restartPagePipeline(P);
|
|
await quiet();
|
|
const back = { runs: runs().slice(mark).length, blocked: pipe.blockedWrites };
|
|
pageMod.disposePagePipeline(P);
|
|
page.clearDrafts(P);
|
|
return { b05, inB06, grade, back };
|
|
}
|
|
|
|
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);
|
|
});
|