- 가져온 식 만들 때 SK 가져온.근거후보 = 793-3a 블록 제안 근거후보(San_Basis_Store.block · 못 셈 = 빈 칸) - 머리 판 후보 = 원문번호 · 옵션 · 품검산 · 입력필요 n · 까닭 [표지 글] · [우리 기초로 바꾸기] 입력 필요 = 바인딩 + 후보 입력필요 + 환산 - 환산 계수 = 가져온 식에서 to-base 다시(바꿈 전 · 후 서버 정본) · 계수 없을 땐 시트 안 엶(셈 길 400 없음) - 단산 줄 고른 것 층 · 주인 뺌 — 층을 주면 옮기기가 SK 를 못 찾아 고정 줄로 옮겨짐 - 시험 test_793_3b 9(근거후보 채움 · SK 참조 옮기기) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
5.2 KiB
Python
115 lines
5.2 KiB
Python
"""M02 불러오기 단산 블록 → 가져온 식 단가산출(PLAN 793-3b · 요구 646 · 647 · 652) — 서버 단독.
|
|
|
|
올림 때 경쟁사 산근 시트(`M02_San_Book.sheets` · STmate 숨은 G 열 포함)를
|
|
`실무자료/산근/<HP>.json` 에 둠
|
|
(원본 엑셀은 안 둠 · HP 지울 때 같이 지움) → [가져온 식으로 열기] = 그 블록을 793-2a 내보내기
|
|
(`M02_San_Emit` · 이음 = 1차 줄 판정) → 793-2 만들기(`M02_Sangeun_Imported.create` · 개인 층 ·
|
|
엑셀 단가 그대로 · `가져온.근거후보` = 793-3a 근거 제안 `M02_San_Basis_Store.block` 근거후보) ·
|
|
같은 내용 SK 가 있으면 그것(다시씀 · 근거후보 그대로).
|
|
블록 번 = 판정 블록 번(STmate = 코드 「D00102」 숫자 · EST = 단가산출 블록 번).
|
|
STmate 블록 끝전(비목버림 | 합버림_큰나머지)은 파일 설정 — 참조 평가기로 둘 다 셈해
|
|
엑셀 계와 맞는 것.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from common_util.common_util_json import atomic_write_json
|
|
from M02_MasterTemplete import M02_Hopyo_Store as hopyo_store
|
|
from M02_MasterTemplete import M02_MasterTemplete_Store as store
|
|
|
|
DIRNAME = "산근"
|
|
RELOAD = "가져온 식 자료 없음 — 엑셀을 다시 올림"
|
|
RULES = ("비목버림", "합버림_큰나머지")
|
|
|
|
|
|
def _path(folder: str | Path, key: str) -> Path:
|
|
return hopyo_store._dir(folder) / DIRNAME / f"{key}.json"
|
|
|
|
|
|
def keep(folder: str | Path, key: str, name: str, data: bytes) -> None:
|
|
"""올린 엑셀 → 산근 시트 둠(STmate · EST 꼴만 · 못 읽으면 안 둠 — 올리기는 됨)."""
|
|
from M02_MasterTemplete import M02_San_Book as book
|
|
|
|
try:
|
|
sheets = book.sheets(name, data)
|
|
if not book.kind_of(sheets):
|
|
return
|
|
except Exception: # noqa: BLE001 — 산근은 덤(가져온 식 열기만 막힘)
|
|
return
|
|
path = _path(folder, key)
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
atomic_write_json(path, {"파일": name, "시트": sheets})
|
|
|
|
|
|
def has(folder: str | Path, key: str) -> bool:
|
|
return _path(folder, key).is_file()
|
|
|
|
|
|
def _rule(blk: dict, nodes: list, prices: dict) -> str:
|
|
"""STmate 블록 끝전 — 엑셀 계(꼬리 · 없으면 머리)와 맞는 쪽 · 둘 다 아니면 비목버림."""
|
|
from M02_MasterTemplete import M02_San_Eval as ev
|
|
|
|
tails = [t for t in blk["꼬리"] if t["A"].startswith("계") and not t["A"].startswith("계약")]
|
|
want = (tails or [blk["머리"]])[0].get("C")
|
|
for rule in RULES:
|
|
try:
|
|
got = ev.stmate_block(blk, nodes, prices, rule)["계"]["T"]
|
|
except Exception: # noqa: BLE001 — 못 셈 = 다음 갈래
|
|
continue
|
|
if want is not None and abs(float(got) - float(want)) < 0.5:
|
|
return rule
|
|
return RULES[0]
|
|
|
|
|
|
def emit(folder: str | Path, key: str, no: int) -> dict[str, Any]:
|
|
"""HP 단산 블록 하나 → `{로직, 원본}`(793-2a 꼴 · 이음 = M01 키)."""
|
|
from M02_MasterTemplete import M02_San_Book as book
|
|
from M02_MasterTemplete import M02_San_Emit as em
|
|
from M02_MasterTemplete import M02_San_Est as est
|
|
from M02_MasterTemplete import M02_San_Stmate as stm
|
|
|
|
hopyo_store.read(folder, key) # 없는 HP = 404
|
|
try:
|
|
saved = json.loads(_path(folder, key).read_bytes())
|
|
except (OSError, ValueError) as e:
|
|
raise store.StoreError(409, RELOAD) from e
|
|
sheets, name = saved["시트"], str(saved.get("파일") or "")
|
|
if book.kind_of(sheets) == "STmate":
|
|
blk = next((b for b in book.stmate_blocks(sheets) if int(b["코드"][1:]) == int(no)), None)
|
|
if blk is None:
|
|
raise store.StoreError(404, f"없는 단산{no}")
|
|
prices = book.stmate_prices(sheets)
|
|
nodes = stm.parse_block(blk["몸"])
|
|
return em.stmate(blk, nodes, prices, _rule(blk, nodes, prices), True, name)
|
|
prices, total = book.est_prices(sheets)
|
|
blk = next((b for b in book.est_blocks(sheets) if int(b["번"]) == int(no)), None)
|
|
if blk is None or blk["번"] not in total:
|
|
raise store.StoreError(404, f"없는 단산{no}")
|
|
return em.est(blk, est.parse_block(blk["글"], prices), total[blk["번"]], True, name)
|
|
|
|
|
|
def make(source: Path, key: str, no: int, name: str = "") -> dict[str, Any]:
|
|
"""지금 층(만들 층)에 가져온 식 SK — 같은 내용이 있으면 그 SK(`다시씀`)."""
|
|
from M02_MasterTemplete import M02_San_Basis_Store as san_basis
|
|
from M02_MasterTemplete import M02_Sangeun_Imported as imp
|
|
|
|
out = emit(source, key, no)
|
|
title = str(name or "").strip() or str(out["로직"].get("이름") or f"단산{no}")
|
|
try:
|
|
basis = san_basis.block(source, key, no).get("근거후보") or None
|
|
except Exception: # noqa: BLE001 — 근거 제안 못 셈 = 빈 칸(가져온 식은 만듦)
|
|
basis = None
|
|
try:
|
|
got = imp.create(out["로직"], out["원본"], title, basis=basis)
|
|
return {**got, "다시씀": False}
|
|
except store.StoreError as e:
|
|
same = (e.detail or {}).get("같은것") if isinstance(e.detail, dict) else None
|
|
if e.status != 409 or not same:
|
|
raise
|
|
got = imp.create(out["로직"], out["원본"], title, use=same[0]["키"])
|
|
return {**got, "다시씀": True}
|