데스크탑 메인이 구조물 터파기·되메우기·잔토를 인계에 실었는데, **잔토 126.625㎥ 가
어디에도 안 실렸다**. 사토로 실어 내는 몫이라 유토곡선이 세야 겹치지 않는다.
구조물 잔토는 사토에 한 번만 더한다.
B08 은 소요량(structure_spoil_m3, ㎥ 양수)을 내기만 하고,
더하는 자리는 유토곡선의 사토뿐이다.
- ⚠ **잔량 하나하나를 늘린다** — 총량만 늘리면 사토는 늘고 운반이 안 는다(공제 때와 같은 자리).
- ⚠ 나누는 법: 지금은 총량 하나만 오므로 **남은 사토 잔량 크기에 비례**해 나눈다.
한 곳에 몰면 운반거리가 틀린다. 측점별 값이 오면 이 함수만 고치면 된다.
- ⚠ 자연방토·지반유형 안분은 안 건드린다 — 실어 내는 흙이고, 어느 지반에서 나온지 모른다.
- `null`(아직 안 옴) ≠ `0`(없음), 받은 값과 **실제로 더한 값**을 따로 싣는다.
시험 5건(더해짐·잔량 동반 증가·자연방토 불변·토취 불변·공제와 함께 와도 한 번씩).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
94 lines
4.9 KiB
TypeScript
94 lines
4.9 KiB
TypeScript
/* =============================================================================
|
|
* B06_Section_Server_Calc_Node.ts
|
|
* 브라우저에서만 돌던 횡단 계산을 **서버가 한 번 돌리는** 진입점 — 구조물 폐회로
|
|
* 절·성토 면적 + 그것을 쌓아 만든 유토곡선.
|
|
*
|
|
* 왜 있나(2026-09-06, CLAUDE.md 5장 「계산 자리」) — 이 두 값은 지금까지 브라우저에서만
|
|
* 나왔다. 사용자가 B06 을 한 번도 안 열면 값이 없고, 저장·확정 뒤 서버가 다시 계산하면
|
|
* 구조물을 모르는 표준값으로 되돌아갔다. 코리도(`B05_Profile_Corridor_Node.ts`)와 같은
|
|
* 방식으로 **브라우저가 쓰는 코드를 서버가 그대로 실행**한다 — 계산을 두 벌로 짜지 않는다.
|
|
*
|
|
* 순서가 중요하다: 면적 보정을 **먼저** 얹고 그 위에서 유토곡선을 쌓는다. 화면도 같은
|
|
* 순서다(카드를 그리며 면적을 고친 뒤 유토곡선을 낸다).
|
|
*
|
|
* 실행: node <번들> <입력.json> <출력.json>
|
|
* 입력 { detail: 종횡단 상세(API와 같은 꼴), context: { earthwork_conversion,
|
|
* natural_spoil_min_ground_slope, haul_equipment_limits } }
|
|
* 출력 { areas: [{ chainage_m, cut_area_m2, … }], mass_haul: {…} | null }
|
|
* — areas 는 **구조물 트림이 있는 측점만**. 나머지는 표준 계산값이 이미 맞다.
|
|
* 끝 코드: 0 성공 / 2 인자 오류
|
|
* ========================================================================== */
|
|
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { computeMassHaul, massHaulPayload } from "@util/common_util_mass_haul";
|
|
import { computeHaulPlan, haulPlanPayload } from "@util/common_util_mass_haul_balance";
|
|
import type { CrossSection, SectionDetailResponse } from "./B06_Section_Api_Fetch";
|
|
import { applyStructureAreaRows, structureAreaRows } from "./B06_Section_Structure_Layouts";
|
|
|
|
interface ServerCalcInput {
|
|
detail?: SectionDetailResponse;
|
|
/**
|
|
* 유토 **배분만** 낼 때 쓰는 입력 — 브라우저가 누가토량(`computeMassHaul`)까지 내고
|
|
* 그 결과를 보내면 여기서 배분·운반거리만 얹어 돌려준다(2026-09-06).
|
|
* 배분 코드를 브라우저 번들에서 빼기 위한 길이라, 이 갈래는 `detail` 을 안 받는다.
|
|
*/
|
|
haul_plan_for?: Parameters<typeof computeHaulPlan>[0];
|
|
context?: {
|
|
earthwork_conversion?: Parameters<typeof computeMassHaul>[1];
|
|
natural_spoil_min_ground_slope?: number | null;
|
|
haul_equipment_limits?: Parameters<typeof computeHaulPlan>[1];
|
|
/** 채집석 공제(㎥, 양수) — B08 이 낸다. `null`/없음은 「아직 안 옴」이다. */
|
|
collected_stone_deduction_m3?: number | null;
|
|
/** 구조물 터파기 잔토(㎥, 양수) — B08 이 낸다. 사토에 **더한다**. */
|
|
structure_spoil_m3?: number | null;
|
|
};
|
|
}
|
|
|
|
const [inputPath, outputPath] = process.argv.slice(2);
|
|
if (!inputPath || !outputPath) {
|
|
console.error("사용법: node <번들> <입력.json> <출력.json>");
|
|
process.exit(2);
|
|
}
|
|
|
|
const input = JSON.parse(readFileSync(inputPath, "utf8")) as ServerCalcInput;
|
|
|
|
// 배분만 내는 갈래 — 화면이 편집을 멈추면 조용히 물어보는 자리(유토곡선 배경 선반입).
|
|
if (input.haul_plan_for) {
|
|
// **화면이 쓰는 꼴 그대로** 내보낸다(직렬화 형태 `haulPlanPayload` 가 아니다) — 그래야
|
|
// 그리기 코드가 손대지 않고 그대로 받는다. 전부 숫자·문자열이라 JSON 으로 오간다.
|
|
const plan = computeHaulPlan(input.haul_plan_for, input.context?.haul_equipment_limits, {
|
|
collected_stone_deduction_m3: input.context?.collected_stone_deduction_m3 ?? null,
|
|
structure_spoil_m3: input.context?.structure_spoil_m3 ?? null,
|
|
});
|
|
writeFileSync(outputPath, JSON.stringify({ haul_plan: plan ?? null }));
|
|
process.exit(0);
|
|
}
|
|
|
|
const sections: CrossSection[] = input.detail?.cross_sections ?? [];
|
|
|
|
const areas = structureAreaRows(sections);
|
|
// 보정값을 **자리에서** 얹는다 — 유토곡선이 고쳐진 면적 위에서 쌓이게 한다.
|
|
applyStructureAreaRows(sections, areas);
|
|
|
|
// 유토곡선 — balloon 위치는 사용자 화면값이라 서버가 만들지 않는다(파이썬이 보존).
|
|
const conversion = input.context?.earthwork_conversion;
|
|
const result = conversion
|
|
? computeMassHaul(
|
|
sections,
|
|
conversion,
|
|
input.context?.natural_spoil_min_ground_slope ?? undefined,
|
|
)
|
|
: null;
|
|
// 배분은 **서버만** 만든다 — 그래야 그 코드가 브라우저 번들에서 빠진다(2026-09-06).
|
|
const plan = result
|
|
? computeHaulPlan(result, input.context?.haul_equipment_limits, {
|
|
collected_stone_deduction_m3: input.context?.collected_stone_deduction_m3 ?? null,
|
|
structure_spoil_m3: input.context?.structure_spoil_m3 ?? null,
|
|
})
|
|
: null;
|
|
const massHaul = result
|
|
? massHaulPayload(result, plan ? { haul_plan: haulPlanPayload(plan) } : null)
|
|
: null;
|
|
|
|
writeFileSync(outputPath, JSON.stringify({ areas, mass_haul: massHaul }));
|