refactor(855-F B9-2): 프로젝트 사본 셈 · B08 자재 집계를 사본 수식 문서 셈 한 길로
- M02_Item_Prices.calc — 로직 줄 = 새 line(사본 수식.json 문서 셈 + master_doc_trace 기록) · formula 인자 · 없으면 그 자리 닫힌 묶음(만들 때와 같은 길) · 재료 줄 = 기록의 고른 품목 · 연결 단위 - M02_Item_Copy.calc — 사본 수식.json 을 실어 넘김 - B08 _folder_units · _ref_mats — 옛 run_line 대신 사본 문서 셈 답의 재료 줄 - M02_Labor_Doc.calc — 로직 줄 셈 갈음 덧칸 logic_line 하나(몸 복사 대신) - test_160_3 — 가짜 부름을 죽은 run_line 에서 item_prices.line 으로(같은 수량 판정) - 골든 855_b09 15 갈래 다시 뜸 없음 · 옛 엔진 부름 B08 1 → 0 · 사본 만드는 길 · B09 산근 · 대가 꼴 그대로(B9-3 · B9-5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -336,7 +336,10 @@ def new_item(
|
||||
|
||||
|
||||
def calc(project_root: str | Path, folder: str) -> dict[str, Any]:
|
||||
"""복사본(입력값 · 고른자재 · 단가 · 일위대가)만으로 계산 — 마스터 현재값을 안 읽음."""
|
||||
"""복사본(입력값 · 고른자재 · 단가 · 일위대가 · 수식)만으로 계산 — 마스터 현재값을 안 읽음 ·
|
||||
로직 줄 = 사본 `수식.json` 문서 셈(855-F B9-2)."""
|
||||
from M02_MasterTemplete.M02_Doc_B09 import FILE as FORMULA_FILE
|
||||
|
||||
target = folder_of(project_root, folder)
|
||||
labor = read_json(target / LABOR_FILE)
|
||||
if not isinstance(labor, dict):
|
||||
@@ -347,6 +350,7 @@ def calc(project_root: str | Path, folder: str) -> dict[str, Any]:
|
||||
read_json(target / VALUES_FILE) or {},
|
||||
read_json(target / PICKS_FILE) or {},
|
||||
read_json(target / KINDS["면적"]),
|
||||
read_json(target / FORMULA_FILE),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -343,20 +343,99 @@ def with_values(doc: dict[str, Any], values: dict[str, Any], picks: dict[str, An
|
||||
return {**doc, "담은로직": lines}
|
||||
|
||||
|
||||
def _mat_lines(doc: dict) -> list[tuple[int, dict, dict]]:
|
||||
"""재료 금액 줄 `[(차례, 줄, 단가 연결)]` — 단가가 재료 요소(재료 조건 · MT · MO · PM 키)인 줄
|
||||
(옛 로직 호표 「재료」 줄 자리 · 차례 = 호표 차례)."""
|
||||
import master_doc as md
|
||||
|
||||
links = {md.var_id(v): v.get("연결") or {} for v in doc.get("변수") or []}
|
||||
out = []
|
||||
for n, line in enumerate(doc.get("금액") or []):
|
||||
link = links.get(str(line.get("단가"))) or {}
|
||||
key = str(link.get("키") or "")
|
||||
if link.get("갈래") == "요소" and (link.get("재료") is not None or key[:2] in MAT_KEYS):
|
||||
out.append((n, line, link))
|
||||
return out
|
||||
|
||||
|
||||
def _mats(doc: dict, ans: dict) -> list[dict[str, Any]]:
|
||||
"""문서 셈 답의 재료 줄(옛 `logic_mats` 자리 · B08 단위수량) — 단위 = 연결 단위(로직 원문 표기) ›
|
||||
줄 단위 · 품목 = 기록의 고른 품목(`master_doc_trace`) › MT · PM 키(고른 재료 = `line_doc` 이
|
||||
키로 바꿈) · MO = 없음."""
|
||||
lines, out = ans.get("줄") or [], []
|
||||
for n, line, link in _mat_lines(doc):
|
||||
got = lines[n] if n < len(lines) else {}
|
||||
calls = [ans["부름"][i] for i in got.get("부름") or []]
|
||||
key = str(link.get("키") or "")
|
||||
goods = next((c["품목"] for c in calls if c.get("품목")), None)
|
||||
goods = goods or (key if key[:2] in ("MT", "PM") else None)
|
||||
out.append(
|
||||
{
|
||||
"차례": n,
|
||||
"이름": line.get("이름") or "",
|
||||
"단위": link.get("단위") or line.get("단위") or "",
|
||||
"수량": got.get("수량"),
|
||||
"품목": {"키": goods} if goods else None,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
#: 재료 요소 키 머리 — 자재품목 · 품셈재료 · 개인 자재
|
||||
MAT_KEYS = ("MT", "MO", "PM")
|
||||
|
||||
|
||||
def line(whole: Any, docs: dict[str, dict] | None, one: dict[str, Any]) -> dict[str, Any]:
|
||||
"""사본 로직 줄 기준 — 사본 `수식.json` 문서 셈 한 길(855-F B9-2 · 층 `M02_Labor_Copy.line` 과 같은
|
||||
줄 규칙 `line_doc` · 입력 = 자동값 › 받은 값) · 값 = 사본 `단가.json` 색인 `whole` · `docs` 에 없는 키 =
|
||||
값 사본 줄에서(`doc_of` · 만들 때와 같은 길 · `docs` 에 더함) · 답 `{기준, 줄, 재료, 까닭}` | 돈 아닌 문서 `{결과}`."""
|
||||
import master_doc_trace as mt
|
||||
|
||||
from M02_MasterTemplete import M02_Doc_Copy as dc
|
||||
|
||||
code, docs = str(one.get("로직") or ""), {} if docs is None else docs
|
||||
if code not in docs: # 사본에 없는 키 — 닫힌 묶음을 그 자리에서(받은 묶음에 더해 다음 줄이 씀)
|
||||
docs.update(dc.closure(whole, [code], docs))
|
||||
base = docs.get(code)
|
||||
if base is None:
|
||||
return {"기준": None, "줄": [], "재료": [], "까닭": f"수식 문서 없음 「{code}」"}
|
||||
apart = dc.apart_of(one.get("자재표시"), [{"차례": n} for n, _, _ in _mat_lines(base)])
|
||||
doc = dc.line_doc(base, one.get("켜쌓기율"), one.get("고름"), apart)
|
||||
given = dc.given_of(whole, code, one.get("입력값"))
|
||||
copy = {"부름": docs}
|
||||
try:
|
||||
ans = mt.calc(doc, mt.Trace(whole, docs), given, dc.cover_of(copy, doc))
|
||||
except Exception as e: # 계산기는 예외 없음이 원칙 — 남은 틈도 금액 「—」 로(`dc.run` 같음)
|
||||
return {"기준": None, "줄": [], "재료": [], "까닭": str(e) or type(e).__name__}
|
||||
if "결과" in ans:
|
||||
return {"결과": ans["결과"], "기준": None, "까닭": None}
|
||||
money = dc.money(ans)
|
||||
got = {k: Decimal(str(v)) for k, v in money.items()} if money else None
|
||||
return {
|
||||
"기준": got,
|
||||
"줄": ans.get("줄") or [],
|
||||
"재료": _mats(doc, ans),
|
||||
"까닭": None if got else dc.why(ans),
|
||||
}
|
||||
|
||||
|
||||
def calc(
|
||||
labor: dict[str, Any],
|
||||
prices: dict[str, Any],
|
||||
values: dict[str, Any],
|
||||
picks: dict[str, Any],
|
||||
area: Any = None,
|
||||
formula: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""복사본만으로 계산 — 층 셈(`M02_Labor_Doc.calc`) 한 벌(142-1) · 단가 = 사본 `단가.json` ·
|
||||
"""복사본만으로 계산 — 층 셈(`M02_Labor_Doc.calc`) 한 벌(142-1) · 로직 줄 = 사본 `수식.json`
|
||||
(`formula`) 문서 셈(`line` · 855-F B9-2) · 단가 = 사본 `단가.json` ·
|
||||
참조 = 굳힌 `참조사본` · 알약 = 가져온 때 것 · 수량 칸 = 사본 `면적.json` · 빈 입력 = 자동값.
|
||||
답 = 층 셈 꼴(`줄` · `자재` · `기준합` · `반영합`) + `알약` + `빠진입력`(「빈 값 n」 표시)."""
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor_doc
|
||||
from M02_MasterTemplete import M02_Labor_Ref as refs
|
||||
|
||||
snapshot = load_prices(prices)
|
||||
docs = dict((formula or {}).get("문서") or {})
|
||||
doc = with_values(labor.get("줄") or {}, values or {}, picks or {})
|
||||
copies = labor.get("참조사본") or {}
|
||||
saved = labor.get("알약")
|
||||
@@ -366,6 +445,7 @@ def calc(
|
||||
whole=snapshot,
|
||||
read=lambda ref: copies.get(refs.ref_id(ref)),
|
||||
pills=[p for p in saved if p.get("로직")] if isinstance(saved, list) else None,
|
||||
logic_line=lambda one: line(snapshot, docs, one),
|
||||
)
|
||||
return {
|
||||
**got,
|
||||
|
||||
@@ -495,12 +495,14 @@ def calc(
|
||||
whole: Any = None,
|
||||
read: Any = None,
|
||||
pills: list[dict] | None = None,
|
||||
logic_line: Any = None,
|
||||
) -> dict[str, Any]:
|
||||
"""`doc` = 정리한 문서 · `given` = {알약 키: 값}(없으면 지금 층 면적산출 파일에서) —
|
||||
줄마다 기준(서버 단독 · M01 엔진) → `settle`. 못 도는 줄은 까닭만(통째로 멈추지 않음).
|
||||
|
||||
프로젝트 사본 셈(142-1)도 이 한 벌 — `whole` = 사본 `단가.json`(`M02_Item_Prices.load_prices`) ·
|
||||
`read` = 참조 → 굳힌 `참조사본` · `pills` = 사본 `알약`(가져온 때 것). 없으면 지금 M01 · 층."""
|
||||
`read` = 참조 → 굳힌 `참조사본` · `pills` = 사본 `알약`(가져온 때 것) · `logic_line` = 로직 줄 셈(사본 =
|
||||
사본 `수식.json` 문서 셈 · 855-F B9-2). 없으면 지금 M01 · 층."""
|
||||
whole, have = lc.live(doc) if whole is None else whole, _area_of(doc.get("열")) if given is None else given # fmt: skip
|
||||
expand = refs.Expand(whole, read or refs.read_ref, have) # 사전조합 안 줄 수량 = 알약 값(723-1)
|
||||
if pills is None:
|
||||
@@ -525,7 +527,9 @@ def calc(
|
||||
if one.get(patch.FIELD): # 줄 덮개(715-3) = 이름 없는 단가산출 셈 · 별도계상까지
|
||||
lines.append({**line, **patch.run(whole, one, read)})
|
||||
continue
|
||||
got = lc.line(whole, doc, one) # 수식 사본 = 문서 셈(802-4a) · 별도계상까지
|
||||
got = (
|
||||
logic_line(one) if logic_line else lc.line(whole, doc, one)
|
||||
) # 수식 사본 = 문서 셈 · 별도계상까지
|
||||
lines.append({**line, **got})
|
||||
mats = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user