Files
Aislo/resources/tester/test_155_5_sangeun_text.py
T
eomsangdonandClaude Opus 5.5 5522aeab8d refactor(855-E 2-E4): 값 사본 닫힌 묶음 = 수식 문서 묶음 — Item_Prices.collect 옛 식 글 훑기 걷음
- M02_Item_Prices.collect: 로직 키 → `Doc_Copy.closure` 문서 묶음 → `Item_Bundle.collect`(자원 · 표 줄 · 로직 줄 없음) ·
  M01 문서 없는 키 = `_빠진` · `extra`(마스터 밖 로직 줄) 안 받음(부르는 곳 0) · `_Collector` 옛 훑기
  (refs · pick · flow · element · logic · row · `_texts`) 지움 — 옛 엔진 몸 부름 mf.parse · walk · fill · _HOLE · _expand · static 7 → 0
- M02_Item_Bundle: 구멍 값 후보 = 고르기 목록 · 빈 목록 = 끼울 값 없음 · 요소 칸을 읽는 변수(「EQ:{기계}」 의 조종원직종 ·
  주연료종류) = 그 줄 값(옛 `_choices` 와 같은 뜻 · 기계 = 인력 · 잡품 보기)
- 대조: 값 사본(`skc.snap` → 로직 줄 뺀 꼴) 표본 로직 150 옛 = 새 같음(전엔 테이블 통째 20,227 줄 더 담김)
- 시험: test_155_5 견본 = 문서 묶음 색인(고친 로직 줄 = 값 사본 줄 → 그 줄 문서) · test_item_copy_complete
  닫힌 묶음 = 문서 셈 대조(옛 엔진 run 대조 걷음)
- 검증: 묶음 ① 커밋 글과 같음

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

137 lines
6.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""155-5 · 855-F B9-4 산근 산출근거 글(`B09_Estimation_Sangeun_Text.render`) — 풀이 블록 + 문서 셈 답.
- 머리 = 「이름 / 단위」 · 「출처 적용」 · 입력 「이름 : 값 단위」(801-5 단위)
- 줄 = 「이름 : 단가 원/단위 × 수량 단위 = 금액 원」(화면 줄 쌓기 산출근거 꼴 · `master_doc_text`) ·
중기 노 · 재 · 경 세 줄 · 결과단위 배 「÷ 배」 · 켜쌓기율 「× 율 %」 · 글 속 금액 = 풀이 블록 줄 값
- 작업량 Q = ROUND 2 공식 줄 「Q = 21.594 = 21.59」 · 수량 식 = 값 넣은 식 「(1 ÷ 21.59 × 2)」
- % 덧줄 = 「공구손료 (노무비의 %) : 밑수 × 3 % = 금액 원」 · 계 = 블록 합
"""
import copy
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from B09_Estimation import B09_Estimation_Sangeun as sg # noqa: E402
from M02_MasterTemplete import M02_Item_Prices as item_prices # noqa: E402
BASE = "GF000218" # 기초다짐 및 뒷채움(기계) — 보통인부 + 굴착기 0.2㎥ 로직 줄
GIVEN = {"규격": 150, "지역": "전국평균", "보정작업": "해당 없음"}
def _copy(codes, over=None):
"""사본 셈 색인(855-E 2-E4) = 수식 문서 묶음 + 그 문서가 잇는 자원 · 표 줄(`Item_Bundle.load`) ·
`over` = 견본 값 사본 색인(고친 로직 줄 → 그 줄 문서)."""
from M02_MasterTemplete import M02_Doc_Copy as dc
from M02_MasterTemplete import M02_Item_Bundle as item_bundle
docs = dc.closure(over or item_prices.master()[1], codes)
return item_bundle.load(item_prices.to_json(item_bundle.collect(docs)), docs)
def _whole(edit=None):
"""사본 셈 색인 — `edit(로직 줄)` 로 GF000218 을 엑셀 견본 꼴로 바꿈(수량 · 중간 · 덧줄 · 고친 줄 =
값 사본 줄 → 그 줄 문서)."""
from M02_MasterTemplete import M02_Sangeun_Copy as skc
if not edit:
return _copy([BASE])
master = item_prices.master()[1]
row = copy.deepcopy(item_prices.to_json(master.logic(BASE)))
edit(row)
return _copy([BASE], skc.Copy(master, skc._rows({"로직": [row]})))
def _excel(qty_labor: str, qty_eq: str, mids=(), extras=()):
def edit(row):
labor, eq = row["호표"][0], row["호표"][1]
row["호표"] = [{**labor, "수량": qty_labor}, {**eq, "수량": qty_eq}]
row["중간"] = [{"이름": n, "식": f} for n, f in mids]
row["덧줄"] = list(extras)
return edit
def _block(edit, code=BASE, given=GIVEN, **src):
return sg.Solver().add(
_whole(edit) if edit else _whole(), {"code": code, "given": given, **src}, "s1"
)
def _texts(block) -> list[str]:
return [t for ln in block["lines"] for t in ln.get("text") or []]
def _foot(block) -> str:
parts = " + ".join(
f"{n} {block[p]:,.0f}" for p, n in zip(sg.PARTS, ("노무비", "재료비", "경비"))
)
return f"계 : {parts} = {block['sum']:,.0f}"
def test_머리_줄_중기_세_줄_계():
block = _block(_excel("0.018", "0.07"))
assert block["head"][:3] == [
"기초다짐 및 뒷채움(기계) / ㎥",
"산림품셈 13-3-2 적용",
"규격 : 150 ㎜",
]
labor, eq = block["lines"]
assert labor["text"] == [
f"보통인부 : {labor['price']['labor']:,.0f} 원/인 × 0.018 인 = {labor['labor']:,.1f} 원"
]
assert [t.split(" : ")[0] for t in eq["text"]] == [
f"굴착기(무한궤도) 0.2㎥ {n}" for n in ("노무비", "재료비", "경비")
]
assert [t.endswith(f"= {eq[p]:,.1f} 원") for t, p in zip(eq["text"], sg.PARTS)] == [True] * 3
assert block["foot"] == _foot(block)
def test_작업량_Q_공식_줄_값_넣은_수량식():
block = _block(_excel("0", "1 / Q * 2", mids=[("Q", "21.594")]))
assert "Q = 21.594 = 21.59 ㎥/hr" in block["head"] # ROUND(식, 2) 뒤 쓰임
assert all("× (1 ÷ 21.59 × 2) 시간 = " in t for t in block["lines"][1]["text"])
def test_퍼센트_덧줄_노무비의_퍼센트():
tool = {"이름": "공구손료", "식": "노무비 * 3 / 100", "비목": "경비"}
block = _block(_excel("0.018", "0.07", extras=[tool]))
pct = block["lines"][-1]
base = sum(ln["labor"] for ln in block["lines"][:-1]) # 밑수 = 인력 + 중기 노무비
assert pct["text"] == [f"공구손료 (노무비의 %) : {base:,.1f} × 3 % = {pct['expense']:,.1f} 원"]
assert block["foot"] == _foot(block)
def test_켜쌓기율_꼬리():
block = _block(_excel("0.018", "0.07"), rate=90)
assert block["lines"][0]["text"][0].startswith("보통인부 : ")
assert "× 0.018 인 × 90 % = " in block["lines"][0]["text"][0]
assert block["foot"] == _foot(block)
def test_글_속_금액은_산근_풀이_값과_같음():
for code, given in ((BASE, GIVEN), ("GF000288", {})): # 중기 · 노무 · % 덧줄 · 배 1,000
whole = _copy([code])
block = sg.Solver().add(whole, {"code": code, "given": given}, "s1")
assert block["foot"] == _foot(block), code
for ln in block["lines"]:
if ln["kind"] in ("labor", "material"):
part = next(iter(ln["price"]))
assert ln["text"][0].endswith(f"= {ln[part]:,.1f} 원"), (code, ln["text"])
if sg._unit(whole.logic(code))[1] != 1:
assert all(" ÷ 1,000" in t for t in _texts(block)[:2]), code
def test_자재_자리표시_키는_실제_키로():
"""「MO:휘발유:{지역}」 자리표시 = 대비표 키(MO…) · 수집량 공식 줄 · 「× (6.5 × 0.125)」 · % 덧줄."""
whole = _copy(["GF000062"])
block = sg.Solver().add(whole, {"code": "GF000062", "given": {}}, "s1")
fuel = next(ln for ln in block["lines"] if ln["name"].startswith("휘발유"))
assert fuel["ref"]["key"].startswith("MO") and ":" not in fuel["ref"]["key"]
assert "일수 = 1 ÷ 수집량 = 1 ÷ 8 = 0.125 일/㎥" in block["head"]
assert "× (6.5 × 0.125) ℓ = " in fuel["text"][0]
assert block["lines"][3]["text"][0].startswith("잡품 (재료비의 %) : ")