Merge remote-tracking branch 'origin/dev' into sub_laptop_3

This commit is contained in:
2026-11-16 23:30:57 +09:00
53 changed files with 2289 additions and 497 deletions
+12 -2
View File
@@ -33,7 +33,7 @@ import {
rowEntry,
type Cover,
} from "./common_util_formula_doc_cover";
import { WORK, lineWork } from "./common_util_formula_doc_work";
import { WORK, hostOf, lineWork } from "./common_util_formula_doc_work";
const EPS = 1e-7; // B09_Estimation_Calc_Base EPS 와 같음
const DEEP = 20;
@@ -460,6 +460,7 @@ function money(run: Run, doc: FormulaDoc, rules: Record<string, Rule>) {
const syms: Record<string, Val> = {};
const outs: (Record<string, unknown> & { 비목: Bundle })[] = [];
let stopped = false;
const raws = new Map<object, [Bundle, Rule]>(); // 848-4 줄 → [끝수 전 비목, 끝수] — 부착 줄 묶음 끝수
lines.forEach((line, i) => {
const places: Record<string, Bundle> = {};
lines.slice(0, outs.length).forEach((l, j) => {
@@ -509,7 +510,16 @@ function money(run: Run, doc: FormulaDoc, rules: Record<string, Rule>) {
else if (!kind && line.합밖 && isNum(price)) bare = qty * price;
else stop(isObj(price) ? "묶음 값 — 칸(.계 · .노무비 …) 필요" : "단가가 수 아님");
const rule = line.자리 ?? rules.줄;
parts = Object.fromEntries(Object.entries(parts).map(([k, v]) => [k, cut(v, rule) as number]));
const raw = { ...parts };
const host = hostOf(run, line);
const held = host ? raws.get(host) : undefined;
// 848-4 부착 줄 = 묶음 한 덩이 끝수 − 주 기계 줄 몫(소수 흔들림 9 자리에서 맞춤)
const one = (k: string, v: number): number =>
held
? Math.round(((cut((held[0][k] ?? 0) + v, rule) as number) - (cut(held[0][k] ?? 0, held[1]) as number)) * 1e9) / 1e9 // prettier-ignore
: (cut(v, rule) as number);
parts = Object.fromEntries(Object.entries(parts).map(([k, v]) => [k, one(k, v)]));
raws.set(line, [raw, rule]);
const keys = Object.keys(parts);
const amount =
bare !== null
+59 -1
View File
@@ -14,6 +14,8 @@
* 굳은 기계(847-1 · 요구 885) = 덮음 `기계`(시간당으로 바꿀 때 그 줄 기계 · 기계 창으로 바꾼 기계) — 그 줄 단가를
* 그 기계(`키` = 기계 식 문서가 다를 때)로 다시 부르고 작업량 식 · 변수도 그 기계 것(옵션이 정하던 기계를 안 읽음) ·
* `이름` = 화면 이름만 · 부착 기계 줄 = 굳힘 없음
* 부착 줄(848-4 · 금액 줄 칸 `부착: true`) = 같은 묶음 앞쪽 주 기계 줄의 수량을 그대로 씀(품셈 일당 · 시간당 식
* 모두 · 그 줄 작업량 덮음은 안 읽음) · 답 칸 꼴 = 주 줄 꼴 + `따름` {기호, 이름, 꼴} · 끝수 = 묶음 한 덩이(계산기)
* 셈 답 기계 줄 칸 `작업량` = {기계, 꼴(일당 · 식 · 시간당), 율, 값, 단위, 식들, 변수?, 까닭?}(산출근거 자료)
* 파이썬 · TS 짝 — 짝 = resources/master_data/scripts/master_doc_work.py · 거울 시험 test_846_1_machine_work.py
* · 계산기(`common_util_formula_doc_calc.ts` money)가 줄마다 `lineWork` 를 부름 · 화면 · DOM · fetch 없음
@@ -57,6 +59,8 @@ export interface WorkCover {
이름?: string;
}
const FIXED = ["기계", "키", "이름"] as const;
export const ATTACH = "부착"; // 848-4 금액 줄 칸
export const FOLLOW = "따름"; // 848-4 부착 줄 답 칸(꼴 = 주 줄 꼴)
/** 셈 답 기계 줄 `작업량` */
export interface WorkInfo {
기계: string;
@@ -71,6 +75,8 @@ export interface WorkInfo {
까닭?: string;
/** 굳은 기계(덮음 `기계`) */
고정?: string;
/** 848-4 부착 줄 — 따르는 주 기계 줄 */
따름?: { 기호: string; 이름: string; 꼴: string };
}
interface Site {
꼴: string;
@@ -391,10 +397,60 @@ export function fixedVar(v: DocVar, want: WorkCover): DocVar {
};
}
type Line = { 이름?: unknown; 수량?: unknown; 단가?: unknown; 묶음?: unknown; 부착?: unknown };
/** 부착 줄 → 같은 묶음 앞쪽 주 기계 줄(부착 아님 · 기계 줄) · 아님 = null */
export function hostOf(
run: { doc: FormulaDoc; vars: Map<string, DocVar> },
line: Line,
): Line | null {
if (!line[ATTACH]) return null;
const lines = (run.doc.금액 ?? []) as Line[];
const at = lines.indexOf(line);
for (let i = at - 1; i >= 0; i--) {
const x = lines[i];
if (!x[ATTACH] && x.묶음 === line.묶음 && machineOf(run.vars, x)) return x;
}
return null;
}
/** 부착 줄 = 주 기계 줄 수량 그대로 · 답 칸 = 주 줄 답 + `따름`(주 기계 줄 작업량 답이 있을 때) */
function follow(
run: WorkRun,
line: Line,
host: Line,
scope: Scope,
kit: WorkKit,
key: string,
sym: string,
): [string | { why: string } | null, Record<string, unknown>, WorkInfo | null] {
const n = run.marks.length;
const seen = new Set(run.values.keys());
let got: ReturnType<typeof lineWork>;
try {
got = lineWork(run, host, scope, kit);
} finally {
run.marks.length = n; // 주 기계 줄 셈의 흔적 = 그 줄이 냄
for (const k of [...run.values.keys()]) if (!seen.has(k)) run.values.delete(k);
}
let [swapped] = got;
const [, more, info] = got;
const where = String(line.이름 ?? "");
if (swapped instanceof kit.Stop)
swapped = new kit.Stop(`${where} 주 기계 줄을 따름 — ${(swapped as { why: string }).why}`, "시간당 거절", where); // prettier-ignore
const text = swapped === null ? host.수량 : swapped;
const mine: WorkInfo | null = info
? { 기계: key, 기호: sym, 꼴: info.꼴 ?? "", 율: info.율 ?? "", 값: info.값, 단위: info.단위 ?? "", 식들: [],
따름: { 기호: info.기호 ?? "", 이름: String(host.이름 ?? ""), 꼴: info.꼴 ?? "" } } // prettier-ignore
: null;
const keep = Q_NEW in more ? { [Q_NEW]: more[Q_NEW] } : {};
return [text === line.수량 ? null : (text as string | { why: string }), keep, mine];
}
/** 기계 줄 하나 → [바꾼 수량 글 | 멈춤(표지는 계산기가 담) | null, 범위 더함, 답 칸 | null] */
export function lineWork(
run: WorkRun,
line: { 이름?: unknown; 수량?: unknown; 단가?: unknown },
line: Line,
scope: Scope,
kit: WorkKit,
): [string | { why: string } | null, Record<string, unknown>, WorkInfo | null] {
@@ -417,6 +473,8 @@ export function lineWork(
if (kit.bad(keyVal)) return [null, {}, null];
const raw = kit.plainText(keyVal).trim();
const key = /^'.*'$/.test(raw) ? raw.slice(1, -1) : raw; // 덮음 기계 열쇠(cover machineKey 와 같음)
const host = hostOf(run, line);
if (host) return follow(run, line, host, scope, kit, key, got.name); // 848-4 부착 줄
const test: Test = (cond) => {
const v = quiet(() => run.ev(cond, scope, where));
return kit.bad(v) ? null : !!v;