Files
Aislo/resources/tester/test_155_5_sangeun_text.py
T
eomsangdonandClaude Opus 5.5 efc881ad12 refactor(855-F B9-4): B09 산출근거 글이 옛 엔진 · master_text 대신 풀이 블록 + 문서 셈 답으로
- Sangeun_Text 새 render · foot — 풀이 블록 줄 값(B09 수량 · 단가 · 금액) + 문서 셈 답(입력 · 공식 · 표 값 · 단위) · 수 꼴 · 단위 · 금액 줄 꼴 = master_doc_text(화면 줄 쌓기 산출근거 규칙)
- Sangeun _env · _captured · _Prices · price_of 지움 · Solver._text = render 한 번(못 지으면 빈 글 · 값 그대로)
- Sangeun_Sum 옛 shown · _cut · places · sums · scope · extra · totals 지움(doc_* 만)
- helper_855_engine 옛 대조 기준 _old_env · _old_captured(test_855_trace)
- test_155_5 · test_157_1 · test_155_b09_sources — 엑셀 꼴 글자 대신 새 규칙 결과(글 금액 = 블록 · 계 · Q 공식 줄 · 값 넣은 수량 식 · ÷ 배 · 원)
- 골든 855_b09 글 5 갈래 다시 뜸(전 → 후 견본 tmp 표) · 값 10 갈래 같음 · 옛 글이 블록 값과 어긋나던 자리(옛 키 단가 0) 바로잡힘
- B09 옛 엔진 부름 37 → 0

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

125 lines
5.6 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 _whole(edit=None):
"""사본 단가 묶음 — `edit(로직 줄)` 로 GF000218 을 엑셀 견본 꼴로 바꿈(수량 · 중간 · 덧줄)."""
files = copy.deepcopy(item_prices.to_json(item_prices.collect([BASE])))
if edit:
for data in files.values():
for row in data.get("줄") or []:
if isinstance(row, dict) and row.get("키") == BASE:
edit(row)
return item_prices.load_prices(files)
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 = item_prices.load_prices(item_prices.to_json(item_prices.collect([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 = item_prices.load_prices(item_prices.to_json(item_prices.collect(["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("잡품 (재료비의 %) : ")