Files
Aislo/B09_Estimation/B09_Estimation_Sangeun_Sum.py
T
eomsangdonandClaude Opus 5.5 063549df54 refactor(855-E 2-E4): B09 블록 줄 꼴 읽기를 master_formula_sum 대신 B09 안에
- B09_Estimation_Labor_Rule: `ms`(items · uses · _cover · skipped · ADDR · STEP — 줄 꼴만 읽는 작은 함수 · 셈 몸 없음)를
  이 파일로 옮김 · master_formula_sum import 0 · B09_Estimation_Sangeun_Sum 도 이것을 씀
- 검증: 묶음 ① 커밋 글과 같음(B09 골든 · 792_3 · 실제 B09 해시 같음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 09:37:53 +09:00

73 lines
3.5 KiB
Python

"""B09 산근 풀이 셈 의미(PLAN 792-3 · 855-F B9-3) — 줄 자리 · 합밖 · 블록 끝전 · 결과 조정 = 문서 셈 답의
`끝수` · `합밖`(새 계산기 `master_doc_calc.cut` · `_settle`) · 기본 = 줄 ROUNDDOWN 1 · 총계 비목마다
ROUNDDOWN 0 · 중간값 표시 자리(`표시` · 옛 로직 작업량 Q = ROUND 2 · 엑셀 자리) = 문서 식에 반올림.
쓰는 곳 = `B09_Estimation_Sangeun.Solver` · 지킴 시험 = `test_792_3_engine_paths.py`(엔진 · M02 SK ·
SC · B09 산근 네 길 같은 금액).
"""
from __future__ import annotations
import importlib
import re
from decimal import Decimal
from typing import Any
from B09_Estimation.B09_Estimation_Calc_Base import rounddown, total
from M01_MasterData import M01_MasterData_Store as _m01 # noqa: F401 — scripts 길을 둠
mc = importlib.import_module("master_doc_calc")
PARTS = ("labor", "material", "expense")
COST_PART = {"노무비": "labor", "재료비": "material", "경비": "expense"}
_Q = re.compile(r"Q\d*") # 작업량 중간값 이름(산림품셈 09장 토공 · 07장 집재 …)
def doc_cut(value: float, rule: dict | None) -> float:
"""줄 끝수 — 줄 `자리` 면 그 규칙(새 계산기 `master_doc_calc.cut`) · 없으면 ROUNDDOWN 1."""
return float(mc.cut(Decimal(str(value)), rule)) if rule else rounddown(value, 1)
def doc_places(row: dict, lines: list[dict]) -> None:
"""호표 줄 `자리`(줄 자리) — 그 줄 금액만 단가 × 수량을 그 규칙으로 다시 버림(제자리)."""
for item, ln in zip(row.get("호표", []), lines):
rule = item.get("자리")
if not rule or ln.get("qty") is None:
continue
for part, price in (ln.get("price") or {}).items():
if part in PARTS and price is not None:
ln[part] = doc_cut(price * ln["qty"], rule)
def doc_sums(skip: set[int], lines: list[dict]) -> dict[str, float | None]:
"""덧줄 밑 비목 합 — 합밖 · 제외 단계 줄(문서 셈 답 `합밖`)을 뺌."""
kept = [ln for n, ln in enumerate(lines) if n not in skip]
return {name: total([ln[p] for ln in kept]) for name, p in COST_PART.items()}
def doc_totals(answer: Any, lines: list[dict]) -> dict[str, float | None]:
"""총계 — 합밖 · 제외 줄 빼고 B09 줄 금액 비목 합 → 문서 답 `끝수`(끝전 · 계 · 조정 · 새 계산기
`settle`) · 빈칸 비목 있으면 그 비목 · 합계 빈칸(옛 `block_totals`)."""
skip = {n for n, x in enumerate(answer.lines) if x.get("합밖")}
got = doc_sums(skip, lines)
if any(v is None for v in got.values()):
out = {COST_PART[k]: None if v is None else rounddown(v, 0) for k, v in got.items()}
return {**out, "sum": total(list(out.values()))}
costs = answer.settle({k: Decimal(str(v)) for k, v in got.items()})
out = {COST_PART[k]: float(v) for k, v in costs.items()}
return {**out, "sum": sum(out.values())}
def doc_shown(row: dict) -> dict[str, int]:
"""중간값 표시 자리 {이름: 자리} — `shown` 과 같은 뜻(`표시` · 옛 로직 작업량 Q = ROUND 2 · 엑셀 자리) ·
문서 셈에 그 식 줄을 반올림으로 씌워 셈(`Doc_Run.solve` `shown`)."""
from B09_Estimation.B09_Estimation_Labor_Rule import ms # 줄 꼴 읽기(855-E 2-E4)
new = ms.uses(row)
out: dict[str, int] = {}
for step in row.get("중간", []):
if step.get("표시") is not None:
out[step["이름"]] = int(step["표시"])
elif not new and _Q.fullmatch(step["이름"]):
out[step["이름"]] = 2
return out