diff --git a/B09_Estimation/B09_Estimation_Bill_Library.py b/B09_Estimation/B09_Estimation_Bill_Library.py index a37e44a3f..f8c89b2a9 100644 --- a/B09_Estimation/B09_Estimation_Bill_Library.py +++ b/B09_Estimation/B09_Estimation_Bill_Library.py @@ -40,7 +40,6 @@ from B08_Quantity.B08_Quantity_Haul_Cycle import FILL, cycle_inputs, cycle_time from B09_Estimation.B09_Estimation_Store import folder as store_folder from B09_Estimation.B09_Estimation_Store import ref_rows from common_util.common_util_json import atomic_write_json -from M01_MasterData import M01_MasterData_Store as m01 from M02_MasterTemplete import M02_Doc_B09 as doc_b09 from M02_MasterTemplete import M02_Labor_Ref as refs from M02_MasterTemplete.M02_Item_Snapshot import ( @@ -159,10 +158,12 @@ def refresh_copy(project_root: str | Path, one: tuple) -> None: # ── 운반 값 사본(263-2) ──────────────────────────────────────────────── def _logic(code: str) -> dict[str, Any]: - try: - return dict(m01.loaded()[1].logic(code) or {}) - except Exception: # noqa: BLE001 — 없는 로직 = 입력 없음 - return {} + """M01 기초 이름 · 입력 꼴 — 지금 수식 문서(855-F B9-6) · 없는 기초 = 입력 없음.""" + from M02_MasterTemplete import M02_Doc_Copy as dc + from M02_MasterTemplete import M02_Item_Prices as item_prices + + doc = dc.folder().get(str(code)) + return {"이름": doc.get("이름"), "입력": item_prices.doc_specs(doc)} if doc else {} def _line_at(labor: Any, lid: str) -> dict[str, Any] | None: diff --git a/B09_Estimation/B09_Estimation_Doc_Run.py b/B09_Estimation/B09_Estimation_Doc_Run.py index 61e4c9580..e75b4a36e 100644 --- a/B09_Estimation/B09_Estimation_Doc_Run.py +++ b/B09_Estimation/B09_Estimation_Doc_Run.py @@ -144,7 +144,7 @@ class Answer: out.append({**x, "단위": items[n].get("단위") or x["단위"]}) else: pct = self.pct(n) - out.append({**x, "율": pct[0]} if pct else x) + out.append({**x, "율": pct[0], "밑": pct[1]} if pct else x) return out def pct(self, n: int) -> tuple[Decimal, str] | None: @@ -209,6 +209,69 @@ class Answer: return mc._settle(self.doc, self.rules, sums) +def doc(whole: Any, docs: dict[str, dict], code: str) -> dict | None: + """키 하나의 수식 문서 — `docs`(사본 수식 문서) › 그 자리 닫힌 묶음(받은 묶음에 더함) · + 없음 = None.""" + code = str(code) + if code not in docs: + docs.update(dc.closure(whole, [code], docs)) + return docs.get(code) + + +def row_of(doc: dict) -> dict[str, Any]: + """수식 문서 → B09 풀이가 읽는 줄 꼴(855-F B9-6 · 옛 로직 줄 대신 문서에서) — 이름 · + 결과단위 · 출처 · 입력(변수 열쇠) · 중간(식 변수 열쇠) · 호표 = 수량 있는 금액 줄(종류 = 단가 + 연결: 단가산출 → 로직 「로직(키)」 · 노임 요소 → 인력 · 그 밖 → 재료) · 덧줄 = 수량 없는 금액 줄 + (식 = 단가 글 · 늘 끝) · 단계.""" + ids = {md.var_id(v): v for v in doc.get("변수") or []} + heads: list[dict] = [] + extras: list[dict] = [] + for line in doc.get("금액") or []: + keep = {k: line[k] for k in ("이름", "단위", "비목", "자리", "번지", "합밖") if k in line} + if "수량" not in line: + extras.append({**keep, "식": str(line.get("단가") or "")}) + continue + link = (ids.get(str(line.get("단가"))) or {}).get("연결") or {} + key = str(link.get("키") or "") + frozen = link.get("갈래") == "숫자" and isinstance( + link.get("값"), dict + ) # 굳은 기계 묶음(847-1) + kind = ( + "로직" + if link.get("갈래") == "단가산출" or frozen + else "인력" + if key[:2] == "LB" + else "재료" + ) + elem = ( + f"로직({key})" if kind == "로직" and key else key + ) # 노임 · 요소 키(줄 정체 · 덮개 cid) + heads.append({**keep, "종류": kind, **({"요소": elem} if elem else {})}) + out = { + **{k: doc.get(k) for k in ("키", "이름", "결과단위", "출처")}, + "입력": [ + {"이름": str(v["열쇠"])} for v in ids.values() if _kind(v) in INPUTS and v.get("열쇠") + ], + "중간": [ + {"이름": str(v["열쇠"])} for v in ids.values() if _kind(v) == "식" and v.get("열쇠") + ], + "호표": heads, + "덧줄": extras, + **({"단계": doc["단계"]} if doc.get("단계") else {}), + } + return {**out, "결과": doc["결과"]} if "결과" in doc else out + + +def _kind(var: dict) -> str: + return str((var.get("연결") or {}).get("갈래") or "") + + +def row(whole: Any, docs: dict[str, dict], code: str) -> dict[str, Any] | None: + """키 하나의 B09 풀이 줄 꼴(`row_of`) — 문서 없음 = None.""" + got = doc(whole, docs, code) + return None if got is None else row_of(got) + + def solve( whole: Any, docs: dict[str, dict], diff --git a/B09_Estimation/B09_Estimation_Labor_Source.py b/B09_Estimation/B09_Estimation_Labor_Source.py index 8f3013c2f..b547f173a 100644 --- a/B09_Estimation/B09_Estimation_Labor_Source.py +++ b/B09_Estimation/B09_Estimation_Labor_Source.py @@ -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: diff --git a/B09_Estimation/B09_Estimation_Sangeun.py b/B09_Estimation/B09_Estimation_Sangeun.py index 4de233051..1544dbb57 100644 --- a/B09_Estimation/B09_Estimation_Sangeun.py +++ b/B09_Estimation/B09_Estimation_Sangeun.py @@ -10,7 +10,8 @@ 로직 줄이 부르는 다른 돈 로직(기계경비 밖) = 하위 산근(그 산근도 목록에 · 산근 → 산근). 풀이 = 사본 수식 문서(`수식.json`)를 M02 와 같은 계산기로 셈한 답 + 셈 기록(`B09_Estimation_Doc_Run` · 855-F B9-3)에서 줄마다 수량 · 단가 · 자원 키 · 하위 산근 · % 줄 율 · 끝수를 읽음(옛 엔진 안 부름) · - 줄 이름 · 단위 · 종류 = 사본 로직 줄 글(B9-5 에서 문서로) · 산출근거 글 = 풀이 블록 + 문서 셈 답(B9-4) · + 줄 이름 · 단위 · 종류 = 수식 문서(`Doc_Run.row_of` · B9-6) · 산출근거 글 = 풀이 블록 + 문서 + 셈 답(B9-4) · 단가 = B09 프로젝트 한 벌 굳힌 단가(144 · `compute_base` 표) — 노무 = 노무비목록표 · 중기 = 중기목록표 노 · 재 · 경 · 재료 = 자재단가대비표 적용 단가 · % 줄(덧줄) = 엔진 식에 B09 비목 합. @@ -46,10 +47,10 @@ from B08_Quantity.B08_Quantity_Haul_Cycle import fill_given from B09_Estimation import B09_Estimation_Doc_Run as dr from B09_Estimation import B09_Estimation_Sangeun_Sum as ss from B09_Estimation import B09_Estimation_Sangeun_Text as st +from B09_Estimation import B09_Estimation_Sheet as sheet from B09_Estimation.B09_Estimation_Calc_Base import SUPPLY, gap, num, rounddown, total from B09_Estimation.B09_Estimation_Copy_Prices import bundle from B09_Estimation.B09_Estimation_Store import ref_rows -from M01_MasterData import M01_MasterData_Store as m01 from M01_MasterData import M01_MasterData_Store_Combo as combo_store from M02_MasterTemplete import M02_Item_Prices as item_prices from M02_MasterTemplete import M02_Labor_Inputs as labor_inputs @@ -62,7 +63,6 @@ from M02_MasterTemplete.M02_Item_Snapshot import ( from M02_MasterTemplete.M02_Item_Source import LABOR_FILE, read_json mf = item_prices.mf -import master_sheet_line as msl # noqa: E402 — 계산서 줄 덧칸(714-1) · scripts 길은 `m01` 이 둠 PARTS = ("labor", "material", "expense") COST_PART = {"노무비": "labor", "재료비": "material", "경비": "expense"} @@ -122,7 +122,7 @@ def rows_of(folder: Path, whole: Any = None, docs: dict | None = None) -> list[d out: list[dict[str, Any]] = [] def logic_line(code: str, given: Any, rate: Any, chosen: Any, promoted: bool) -> None: - if not is_money(whole, code): + if not is_money(whole, code, docs): return if not promoted: out.append({"code": code, "given": _clean_given(given), "rate": rate, "picks": chosen}) @@ -181,21 +181,16 @@ def _unit(row: dict) -> tuple[str, Decimal]: return unit, Decimal(per[0][0]) if len(per) == 1 else Decimal(1) -def unit_of(whole: Any, code: str) -> str: - """산근 1 단위 이름(「원/10㎡」 = ㎡) — `whole` = 사본 단가 묶음.""" - try: - return _unit(whole.logic(code))[0] - except mf.FormulaError: - return "" +def unit_of(whole: Any, code: str, docs: dict | None = None) -> str: + """산근 1 단위 이름(「원/10㎡」 = ㎡) — 수식 문서 결과단위(`docs` = 사본 수식 문서).""" + row = dr.row(whole, {} if docs is None else docs, code) + return _unit(row)[0] if row else "" -def is_money(whole: Any, code: str) -> bool: - """돈 로직(호표 줄 꼴)인지 — 없는 로직 · 흐름 · 결과 로직 = 아님.""" - try: - row = whole.logic(code) - except mf.FormulaError: - return False - return not (isinstance(row.get("흐름"), dict) or "결과" in row) +def is_money(whole: Any, code: str, docs: dict | None = None) -> bool: + """돈 문서(금액 줄 꼴)인지 — 없는 문서 · 결과 문서 = 아님(수식 문서 · 855-F B9-6).""" + row = dr.row(whole, {} if docs is None else docs, code) + return row is not None and "결과" not in row def call_of(line: dict) -> dict[str, Any] | None: @@ -236,11 +231,10 @@ def line_calls( ) -> dict[int, dict | None]: """로직 하나의 로직 호표 줄마다 `call_of`(호표 차례 n → 부른 것) — 못 셈 줄 = None · 셈 = 문서 셈 답(`Doc_Run` · `docs` = 사본 수식 문서 · 없으면 그 자리 닫힌 묶음).""" - try: - row = whole.logic(code) - except mf.FormulaError: - return {} docs = {} if docs is None else docs + row = dr.row(whole, docs, code) + if row is None: + return {} got = dr.solve( whole, docs, @@ -311,18 +305,18 @@ class Solver: def _solve(self, whole: Any, src: dict[str, Any], depth: int) -> dict[str, Any]: code = src["code"] - try: - row = whole.logic(code) - except mf.FormulaError as e: - return self._stop(code, code, f"로직 없음 — {e}") + docs = self.shelf.of(whole) + doc = dr.doc(whole, docs, code) # 수식 문서(855-F B9-6 · 옛 로직 줄 안 읽음) + if doc is None: + return self._stop(code, code, f"수식 문서 없음 「{code}」") + row = dr.row_of(doc) name = str(row.get("이름") or code) - if isinstance(row.get("흐름"), dict) or "결과" in row: + if "결과" in row: return self._stop(code, name, "돈 로직 아님(흐름 · 결과 로직) — 산근 풀이 꼴 없음") unit, times = _unit(row) rate = Decimal(str(src["rate"])) / 100 if src.get("rate") not in (None, 100) else None lines: list[dict[str, Any]] = [] # 841-1 단가 = M02 셈(문서 셈) 줄 금액 ÷ 수량(켜쌓기율 없이 · 날 값 · B09 단가 책 안 읽음) - docs = self.shelf.of(whole) shown = ss.doc_shown(row) # 작업량 Q = ROUND 2(엑셀 자리) eng = dr.solve(whole, docs, code, src["given"], src.get("picks"), None, shown) if eng is None: @@ -340,7 +334,7 @@ class Solver: self._extras(row, per or eng, lines) head = self._text(whole, eng, lines, times, src.get("rate")) self._aside(lines) - _annotate(whole, row, eng.env, lines) + sheet.annotate(whole, doc, lines) # 계산서 줄 덧칸(719-4) = 문서 except (ArithmeticError, KeyError, TypeError, ValueError) as e: return self._stop(code, name, str(e) or type(e).__name__) sums = ss.doc_totals(eng, lines) # 끝수 · 끝전 · 조정 = 문서 답 끝수(792-3) @@ -362,7 +356,7 @@ class Solver: "why": why, "head": head, "foot": foot, - "기준단위": msl._per_text(msl.mbs.result_per(row.get("결과단위"))) or None, + "기준단위": sheet.base_unit(doc), } @staticmethod @@ -488,31 +482,15 @@ class Solver: lines.append({**line, "price": {part: value}, part: money, "why": None}) -def _annotate(whole: Any, row: dict, env: dict, lines: list[dict[str, Any]]) -> None: - """719-4 계산서 줄 덧칸 `sheet`{쓰는입력 · 기준단위 · 환산근거} — `master_sheet_line` 한 벌 - (M01 `/text` · M02 `/logic-lib/sheet` 와 같은 뜻) · 묶음 · 장비 = 줄 `kind` 로 화면이 가름.""" - per = msl.mbs.result_per(row.get("결과단위")) - items = [*row.get("호표", []), *row.get("덧줄", [])] - for item, ln in zip(items, lines): - goods = ln.pop("_goods", None) or {} - exprs = [item["식"]] if "식" in item else [item.get("수량"), item.get("요소")] - seen = {"품목": goods, "단위": item.get("단위")} - try: - got = msl._fields(whole, row, exprs, dict(env), per, seen, None) - except (mf.FormulaError, ArithmeticError, KeyError, TypeError, ValueError): - got = {} - ln["sheet"] = got - - # ── 모음 ────────────────────────────────────────────────────────────── LISTED = ("no", "key", "logic", "name", "spec", "spec_raw", "unit", "sum", *PARTS, "uses") def _input_names(code: str) -> list[str]: - try: - return [str(i.get("이름")) for i in m01.loaded()[1].logic(code).get("입력") or []] - except mf.FormulaError: - return [] + """M01 기초 입력 이름 — 지금 수식 문서(855-F B9-6).""" + from M02_MasterTemplete import M02_Doc_Copy as dc + + return item_prices.doc_inputs(dc.folder().get(str(code))) def hand_sources(user: dict[str, Any] | None) -> list[tuple[str, str, dict[str, Any]]]: diff --git a/B09_Estimation/B09_Estimation_Sheet.py b/B09_Estimation/B09_Estimation_Sheet.py new file mode 100644 index 000000000..7d99817f0 --- /dev/null +++ b/B09_Estimation/B09_Estimation_Sheet.py @@ -0,0 +1,115 @@ +"""B09 산근 계산서 줄 덧칸 `sheet`{쓰는입력 · 기준단위 · 환산근거}(719-4) — 수식 문서에서 +(855-F B9-6) · 서버 단독(짝 없음). + +옛 `master_sheet_line._fields`(옛 로직 줄 식 풀이)와 같은 뜻: +- `쓰는입력` = 그 줄 값(수량 · 단가 식)이 쓰는 문서 입력 변수 열쇠 — 식 변수 · 표 조건 · + 단가산출 넘긴 입력 · 요소 키 틀 · 재료 조건 글 구멍을 거슬러 감 · 문서 변수 차례. +- `기준단위` = 그 줄이 찾는 표의 기준(「10㎡」 · `master_basis.basis`) · 없으면 None. +- `환산근거` = 표 기준배 ↔ 결과단위 배 · 재료 품목 단위 ↔ 줄 단위(`master_unit.note`) · 없으면 「」. +""" + +from __future__ import annotations + +import re +from decimal import Decimal +from typing import Any + +import master_basis as mbs # noqa: E402 +import master_doc as md # noqa: E402 +import master_unit as mu # noqa: E402 + +from B09_Estimation import B09_Estimation_Doc_Run as dr +from M01_MasterData import M01_MasterData_Store as _m01 # noqa: F401 — scripts 길을 둠 + +_HOLE = re.compile(r"\{([^{}]+)\}") + + +def _times(x: Decimal) -> str: + return format(x.normalize(), "f") + + +def per_text(per: list[tuple[Decimal, str]]) -> str: + """결과단위 분모 글(「10㎡」 · 여럿 = 「㎡ · ㎥」).""" + return " · ".join(dict.fromkeys(f"{_times(n) if n != 1 else ''}{u}" for n, u in per)) + + +def base_unit(doc: dict) -> str | None: + """답 머리 `기준단위` = 결과단위 분모.""" + return per_text(mbs.result_per(doc.get("결과단위"))) or None + + +def _reach(doc: dict, texts: list) -> tuple[list[str], list[str]]: + """식들이 쓰는 (입력 열쇠 · 표 키) — 식 변수 · 표 조건 · 단가산출 넘긴 입력을 거슬러 감.""" + ids = {md.var_id(v): v for v in doc.get("변수") or []} + steps = {md.var_id(x): x.get("식") for x in doc.get("식") or []} + seen: set[str] = set() + tables: list[str] = [] + todo = [t for t in texts if t not in (None, "")] + while todo: + try: + names = set(md.names(md.parse(todo.pop()))) + except md.DocError: + continue + for name in names - seen: + seen.add(name) + link = (ids.get(name) or {}).get("연결") or {} + if name in steps: + todo.append(steps[name]) + if link.get("갈래") == "표": + tables += [str(link["표"])] if link.get("표") and link["표"] not in tables else [] + todo += [str(x) for x in (link.get("조건") or {}).values()] + elif link.get("갈래") == "단가산출": + todo += [str(x) for x in (link.get("입력") or {}).values()] + elif ( + link.get("갈래") == "요소" + ): # 키 틀 · 재료 조건 글 구멍(「LB:{S_직종}」 · 「{D_관}」) + cond = link.get("재료") if isinstance(link.get("재료"), dict) else {} + for text in [str(link.get("키") or ""), *(str(x) for x in cond.values())]: + todo += _HOLE.findall(text) + inputs = [ + str(v["열쇠"]) + for vid, v in ids.items() + if vid in seen and dr._kind(v) in dr.INPUTS and v.get("열쇠") + ] + return inputs, tables + + +def _basis(whole: Any, tables: list[str]) -> dict | None: + for ref in tables: + try: + got = mbs.basis(whole.get(ref)) + except Exception: # noqa: BLE001 — 없는 표 · 기준 없음 = 다음 + continue + if got["갈래"] == "단위": + return got + return None + + +def _note(basis: dict | None, per: list, line: dict) -> str: + notes = [] + if basis and len(per) == 1: + times, one = per[0] + if mu.plain(basis["기준단위"]) == mu.plain(mbs.unit(one)) and basis["기준배"] != times: + ratio = basis["기준배"] / times + how = f"÷{_times(ratio)}" if ratio > 1 else f"×{_times(1 / ratio)}" + notes.append( + f"{_times(basis['기준배'])}{basis['기준단위']}당 → {_times(times)}{one}당 {how}" + ) + goods = line.get("품목") or {} + if goods.get("단위") and line.get("단위"): + notes.append(mu.note(goods["단위"], line["단위"])) + return " · ".join(n for n in notes if n) + + +def annotate(whole: Any, doc: dict, lines: list[dict[str, Any]]) -> None: + """블록 줄마다 `sheet` — 줄 차례 = 문서 금액 줄 차례(호표 · 뒤 덧줄) · 제자리.""" + per = mbs.result_per(doc.get("결과단위")) + for dl, ln in zip(doc.get("금액") or [], lines): + goods = ln.pop("_goods", None) or {} + inputs, tables = _reach(doc, [dl.get("수량"), dl.get("단가")]) + basis = _basis(whole, tables) + unit = None + if basis: + unit = f"{_times(basis['기준배']) if basis['기준배'] != 1 else ''}{basis['기준단위']}" + seen = {"품목": goods, "단위": dl.get("단위")} + ln["sheet"] = {"쓰는입력": inputs, "기준단위": unit, "환산근거": _note(basis, per, seen)} diff --git a/M02_MasterTemplete/M02_Item_Prices.py b/M02_MasterTemplete/M02_Item_Prices.py index 0ad7bf1f4..83bd69728 100644 --- a/M02_MasterTemplete/M02_Item_Prices.py +++ b/M02_MasterTemplete/M02_Item_Prices.py @@ -316,6 +316,19 @@ def doc_inputs(doc: Any) -> list[str]: ] +def doc_specs(doc: Any) -> list[dict[str, Any]]: + """수식 문서 입력 꼴(옛 로직 줄 `입력` 자리) — {이름(열쇠), 단위, 설명, 출처, 고르기, 범위}.""" + out = [] + for v in (doc or {}).get("변수") or []: + link = v.get("연결") or {} + if link.get("갈래") not in ("입력", "선택") or not v.get("열쇠"): + continue + spec = {"이름": str(v["열쇠"]), **{k: v[k] for k in ("단위", "설명", "출처") if v.get(k)}} + spec |= {"고르기": list(link["목록"])} if link.get("목록") else {} + out.append(spec | ({"범위": list(link["범위"])} if link.get("범위") else {})) + return out + + def missing_inputs( docs: dict[str, dict], labor: dict[str, Any], values: dict[str, Any] ) -> list[dict]: diff --git a/resources/tester/golden_855_b09.json b/resources/tester/golden_855_b09.json index 9e0b87e5f..9ba1b5615 100644 --- a/resources/tester/golden_855_b09.json +++ b/resources/tester/golden_855_b09.json @@ -5,15 +5,15 @@ "calc_user": "6d74551273d6735f", "daega_inputs": "8b605fa95c5b9db4", "수요": "23b0132a8a7f46f7", - "산근 값": "38455c2edce885ff", + "산근 값": "6072e1180a1b81e7", "산근 글": "f5b884a2c49c91c6", - "산근 관급 값": "d154925ee64c985c", + "산근 관급 값": "6568e5cf9322b81c", "산근 관급 글": "9397c1d1a5fe0dcd", "미리보기 hand:rate 값": "091690571b7dc54b", "미리보기 hand:rate 글": "d17615784f25e4f5", "미리보기 hand:pick 값": "6c7f426d37e31998", "미리보기 hand:pick 글": "7836022de46b3072", - "미리보기 hand:net 값": "b1c2c650567a14ae", + "미리보기 hand:net 값": "e2809bd3259438b0", "미리보기 hand:net 글": "0254ea22d7a23e43", "B08 단위수량": "896710398b04b4fd" }