refactor(855-F B9-6): B09 산근 · 대가 · 계산서 덧칸 · 서고 운반 입력이 옛 로직 줄 대신 수식 문서를 읽음

- B09_Estimation_Doc_Run: doc · row · row_of 더함 — 수식 문서 → B09 풀이 줄 꼴(이름 · 결과단위 · 출처 · 입력 · 중간 =
  변수 열쇠 · 호표 = 수량 있는 금액 줄(종류 = 단가 연결: 단가산출 · 굳은 기계 묶음 → 로직 · 노임 요소 → 인력 · 그 밖 → 재료 ·
  요소 = 연결 키) · 덧줄 = 수량 없는 금액 줄(1,456 돈 문서 전부 끝) · 단계) · engine 덧줄에 % 밑 이름
- B09_Estimation_Sangeun: unit_of · is_money · line_calls · Solver._solve 가 whole.logic 대신 문서 ·
  계산서 줄 덧칸 = 새 B09_Estimation_Sheet(문서에서 쓰는입력 · 기준단위 · 환산근거 · master_sheet_line 안 부름) ·
  _input_names = 지금 수식 문서
- B09_Estimation_Labor_Source._poomsem: 문서 줄 꼴 · % 밑 = 문서 셈 밑 이름(옛 덧줄 식 글 정규식 걷음) ·
  키 모르는 굳은 기계 묶음 줄 = M02 값 고정 줄
- B09_Estimation_Bill_Library._logic(운반 값 입력) = 지금 수식 문서(Item_Prices.doc_specs)
- 골든 test_855_b09_golden 다시 뜸 — 산근 값 · 산근 관급 값 · 미리보기 hand:net 값 세 갈래 = 재료 줄 단위 글 kg → ㎏(문서 단위)뿐
- 실제 B09 프로젝트(손 줄 6): 산근 답 = 옛 코드 답과 같음(계산서 덧칸 쓰는입력까지) · 해시 같음
- 검증: 관련 + 핵심 + 855_golden · 855_trace · 795_4 549 통과 · typecheck 0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 05:48:05 +09:00
co-authored by Claude Opus 5.5
parent 70d058492d
commit 4ad80c02ae
7 changed files with 244 additions and 81 deletions
+16 -23
View File
@@ -28,7 +28,6 @@ from __future__ import annotations
import hashlib
import json
import re
from decimal import Decimal
from pathlib import Path
from typing import Any
@@ -61,10 +60,6 @@ mf = item_prices.mf
#: 엔진 비목 → 블록 비목
PART = {"노무비": "labor", "재료비": "material", "경비": "expense"}
GROUP = {"인력": "labor", "재료": "material", "장비": "machine"} # 율 기준 묶음(778-4)
#: % 덧줄 밑수 — `노무비 * …` · `줄.'이름' * …` · `(석공 * LB… + …) * …`(인력 줄)
BASE_PART = re.compile(r"^\s*(노무비|재료비|경비)\s*\*")
BASE_LINE = re.compile(r"^\s*줄\.'([^']+)'\s*\*")
BASE_LABOR = re.compile(r"^\s*\(.*\*\s*LB\d+")
AREA_FILE = "면적.json"
ASK = "수량 없음 — 이 공사에서 입력" # 723-4 SC 안 줄 수량 빈칸(펼침 품 · 수량 칸)
@@ -140,9 +135,8 @@ class Builder:
(금액 줄 차례 · 단가산출 블록이 씀)."""
code = str(one.get("로직") or "")
given, rate, picks = one.get("입력값") or {}, one.get("켜쌓기율"), one.get("고름")
try:
logic = whole.logic(code)
except mf.FormulaError:
logic = dr.row(whole, self.shelf.of(whole), code) # 수식 문서 줄 꼴(855-F B9-6)
if logic is None:
return None
got = dr.solve(
whole, self.shelf.of(whole), code, given, picks, rate
@@ -228,9 +222,9 @@ class Builder:
out["place"] = dict(place) # 줄 자리(792-4) = 문서 금액 줄 칸
if pct := got.pct(n):
word = pct[1].removesuffix("의 %")
base = {"노무비": "part:labor", "재료비": "part:material", "경비": "part:expense",
"인건비": "lines:labor"}.get(word, f"line:{word}") # fmt: skip
base = base if word else _doc_base(got.doc, n) # 번지 · 단계 밑(792-4)
base = (
_BASE.get(word, f"line:{word}") if word else _doc_base(got.doc, n)
) # 번지 · 단계 밑(792-4)
if base is None: # 밑을 모르는 덧줄 — 옛 길과 같게 빈 줄
why = "덧줄 — 대가 단가로 못 셈"
return {**head, **out, "kind": "blank", "qty": qty, "why": why}
@@ -265,7 +259,8 @@ class Builder:
goods = x.get("품목") or {}
if item is None: # 덧줄 — 밑수 × % / 100(% = 엔진 값 ÷ 엔진 밑수)
add = (logic.get("덧줄") or [])[extra]
base, label = _base_of(str(add.get("식") or ""))
label = str(x.get("밑") or "").removesuffix("의 %") # 문서 셈 % 밑 이름(855-F B9-6)
base = _BASE.get(label, f"line:{label}") if label else None
value, under = _f(x.get("금액")), bases.get(base) if base else None
if value is None or not under:
# ponytail: 밑수 없는 덧줄(손료 식 등)은 B09 단가로 못 셈 — 줄만 두고 빈칸
@@ -288,6 +283,10 @@ class Builder:
if call and call.get("code"):
key = sg.sangeun_key(call["code"], call["given"])
return {**head, "kind": "sangeun", "key": key, "qty": qty}
if (
call is not None and "machine" in call and own is not None
): # 키 모르는 굳은 기계 = M02 값
return {**head, "kind": "fixed", "qty": qty, "own": own, "link": {}}
return {**head, "kind": "blank", "qty": qty, "why": "하위 로직 줄 — 못 펼침"}
# ── 조합 · 사전조합 줄 ──────────────────────────────────────────────
@@ -347,11 +346,11 @@ class Builder:
"unit": doc.get("단위") or "", "qty": each} # fmt: skip
code = str(one.get("로직") or "")
if one.get("승격") is not True: # 단가산출 줄 = 산근
if not sg.is_money(whole, code):
if not sg.is_money(whole, code, self.shelf.of(whole)):
return {"kind": "blank", "name": name or code, "qty": q, "why": "돈 아닌 로직"}
key = sangeun_ref(code, one.get("입력값"), one.get("켜쌓기율"), one.get("고름"))
return {"kind": "sangeun", "key": key, "name": name or code,
"unit": sg.unit_of(whole, code), "qty": q} # fmt: skip
"unit": sg.unit_of(whole, code, self.shelf.of(whole)), "qty": q} # fmt: skip
bid = self.poomsem(whole, one, str(one.get("별칭") or "") or name)
if bid is None:
return {
@@ -624,15 +623,9 @@ def _engine_bases(engine: list[dict], items: list[dict]) -> dict[str, float]:
return out
def _base_of(formula: str) -> tuple[str | None, str]:
"""덧줄 식 → (밑수 갈래, 이름) — 모르는 꼴이면 (None, "")."""
if hit := BASE_PART.match(formula):
return f"part:{PART[hit.group(1)]}", hit.group(1)
if hit := BASE_LINE.match(formula):
return f"line:{hit.group(1)}", hit.group(1)
if BASE_LABOR.match(formula):
return "lines:labor", "인건비"
return None, ""
#: % 밑 이름(`Doc_Run.Answer.pct`) → 밑수 갈래(옛 덧줄 식 글 풀이 대신 · 855-F B9-6)
_BASE = {"노무비": "part:labor", "재료비": "part:material", "경비": "part:expense",
"인건비": "lines:labor"} # fmt: skip
def _plain(value: Any) -> Any: