93 lines
3.4 KiB
Python
93 lines
3.4 KiB
Python
"""STMATE 재현 앱 내역서 줄 금액 — 비목우선/총액우선(CHNNM · OPTNM) · 비율 줄(PR).
|
||
|
||
정답 = 실무 STC 7건 BOQ 저장 줄 금액(M_AMT·L_AMT·S_AMT, 차수별) · 7건 모두 CHNNM=1(비목우선).
|
||
비목우선 = 성분별 단가 × 수량 원 미만 절사 · 비율 줄 = 표시(PRPT) 줄 밑수 × 율 ÷ 100 절사.
|
||
총액우선 = REA 15 OPTIMIZ(산근·일위대가와 같은 규칙) — 실무 표본 없음 · 손셈 대조.
|
||
"""
|
||
|
||
import json
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
sys.path.insert(0, str(ROOT / "tools/stmate-test"))
|
||
sys.path.insert(0, str(Path(__file__).parent))
|
||
import server # noqa: E402
|
||
from test_stmate_kanjub_stc import DOCS, STCS # noqa: E402
|
||
|
||
HELPER = Path(__file__).with_name("helper_stmate_kanjub_boq.cjs")
|
||
|
||
|
||
def _run(state):
|
||
out = subprocess.check_output(
|
||
["node", str(HELPER)],
|
||
input=json.dumps(state, ensure_ascii=False),
|
||
text=True,
|
||
encoding="utf-8",
|
||
)
|
||
return json.loads(out)
|
||
|
||
|
||
def _with_pr(loaded):
|
||
"""비율 줄 칸(PRPT·PRIN·PROUT·차수별 율) — 불러오기가 아직 안 넘기면 BOQ 원행에서 채움."""
|
||
st, rows = loaded["sim_state"], loaded["boq_rows"]
|
||
for it in st["boqItems"]:
|
||
r = rows[int(it["id"].split("_")[1]) - 1]
|
||
for k in ("PRPT", "PRIN", "PROUT"):
|
||
it.setdefault(k, r.get(k))
|
||
it.setdefault("prQtys", [float(r.get(f"QTY{n}") or 0) for n in range(1, 5)])
|
||
return st
|
||
|
||
|
||
@pytest.mark.parametrize("name", list(STCS))
|
||
def test_boq_rows_match_stc_bimok(name):
|
||
loaded = server.api_load(server.LoadReq(source_path=str(DOCS / STCS[name])))
|
||
assert str(loaded["start_ini"].get("CHNNM", "1")) == "1"
|
||
rows = loaded["boq_rows"]
|
||
out = _run(_with_pr(loaded))
|
||
bad = []
|
||
for n, items in out.items():
|
||
for rid, code, m, lab, s in items:
|
||
r = rows[int(rid.split("_")[1]) - 1]
|
||
exp = [float(r.get(f"{c}_AMT{n}") or 0) for c in "MLS"]
|
||
if [m, lab, s] != exp:
|
||
bad.append((n, code, [m, lab, s], exp))
|
||
assert not bad, f"{name} 줄 금액 불일치 {bad[:5]}"
|
||
|
||
|
||
def _one(units, qty, mode, order="SML"):
|
||
state = {
|
||
"sysConfig": {"chnMode": mode, "optOrder": order},
|
||
"kanjubConfig": {},
|
||
"kanjubStages": {1: {}},
|
||
"resources": [],
|
||
"machines": [],
|
||
"sanItems": [],
|
||
"ilwiItems": [],
|
||
"boqItems": [
|
||
{
|
||
"id": "BOQ_1",
|
||
"code": "B1",
|
||
"refId": "B1",
|
||
"qty": qty,
|
||
"fixedUnit": dict(zip("MLS", units)),
|
||
}
|
||
],
|
||
}
|
||
return _run(state)["1"][0][2:]
|
||
|
||
|
||
def test_total_first_optimiz_by_hand():
|
||
# 920·5802·278 × 2.12 = 1950.4 · 12300.24 · 589.36 → 총액 14840 · 성분 절사 합 14839 → 소수부 큰 재료비 +1
|
||
assert _one([920, 5802, 278], 2.12, "bimok") == [1950, 12300, 589]
|
||
assert _one([920, 5802, 278], 2.12, "total") == [1951, 12300, 589]
|
||
# 1741·13033·3528 × 1.6 = 2785.6 · 20852.8 · 5644.8 → 남는 2원 = 노무·경비 동률 0.8 → OPTNM 순서(S 먼저)
|
||
assert _one([1741, 13033, 3528], 1.6, "total") == [2785, 20853, 5645]
|
||
assert _one([1741, 13033, 3528], 1.6, "total", "LMS") == [2785, 20853, 5645]
|
||
# 동률 셋 — 남는 1원은 순서 앞 성분
|
||
assert _one([1, 1, 1], 0.5, "total", "MLS") == [1, 0, 0]
|
||
assert _one([1, 1, 1], 0.5, "total", "LSM") == [0, 1, 0]
|