- 길: sangeun from-line · formula-check · copy · equation(셋) · block · labor copy · 프로젝트 양식 reset · apply · save-as · sources · drawing-import · drawing-fields · logic-lib machine-parts · logic-lib/auto - 본체: Calc.from_line · Formula.check_doc 외 셋 · Equation 읽기 · 미리 셈 · Equation_Full 파일 · Block 끊기 · 잇기 · 수식 탭 · Labor_Copy.preview · Router_Layers 가져오기 도우미 - 화면: Api_Fetch 래퍼 여덟 · sangeunFromLine - 시험: 죽은 길만 보던 796-2c · 796-2e 파일 지움 · 함수째 지움(715-3 · 733-2 · 792-1 · 796-2b · router_drawing · template_layers · structure_panel 글자 시험) · 살아 있는 결과는 [저장] 길로 고침(795-2 · 796-2b) · 813-2 = M01 parts.of_machine 바로 - 남김: Sangeun_Copy.preview(옛 엔진 셈 거울 — 걸음 2) · B07 이 쓰는 reset_project · B09 가 쓰는 _company_projects - 검증: /openapi.json 524 → 508(뜻한 16 만) · 빌더 --check 같음 · 핵심 시험 99 통과 · 관련 시험 687 통과 · typecheck 0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
4.7 KiB
Python
95 lines
4.7 KiB
Python
"""M02 단가산출(SK) 더한 기초 블록 [연결 끊기] · [다시 잇기](PLAN 796-2e · 요구 659-3 · 656-1).
|
|
|
|
더한 기초 = 더한줄 로직(`종류: 로직`). 기본 = 연결 — 이 SK 의 로직 사본(`M02_Sangeun_Copy`)이 닿는 그 기초
|
|
(원본 바뀜은 [재생성]·[다시 잇기]에서 따라옴 · 자동 아님 · 보기만).
|
|
끊음 = 더한줄 칸 `끊음` {시점, 로직 [M01 줄]} — 끊는 때 그 기초가 닿는 닫힌 묶음(하위 로직 · 찾기 표 ·
|
|
요율 · 사본 줄 그대로 = 금액 그대로)을 이 SK 안 자기 사본으로 굳힘 → 그 줄만 고침:
|
|
칸 `수식고침`(796-2b 와 같은 꼴 · 같은 `eqm.apply`)을 그 기초 줄에 얹어 셈(`Calc.sub_run`).
|
|
[재생성] = 끊은 기초의 줄은 안 바꿈(자원 단가만 — 단가는 SK 사본 `단가` · [단가 갱신] 한 길).
|
|
다시 잇기 = `끊음` · `수식고침` 뗌 + 표지 `다시잇기`(서버만 · 셈·저장 첫머리 `Copy.settle` 이 그 기초가 닿는
|
|
닫힌 묶음을 지금 M01 줄로 갈음하고 표지 뗌 — 고친 것 버림).
|
|
화면 길(끊기 · 다시 잇기 · 끊은 기초 수식 탭)은 걷음(894) — 남은 것 = 저장 문서의 `끊음` · `수식고침` 꼴 · 셈.
|
|
저장 = SK [저장](서버가 다시 얹어 검사 · 셈 · 브라우저 값 안 받음 — 끊음 줄은 사본과 같은 `taken` 꼴 검사).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from M02_MasterTemplete import M02_Sangeun_Copy as skc
|
|
from M02_MasterTemplete import M02_Sangeun_Doc as sd
|
|
from M02_MasterTemplete import M02_Sangeun_Equation as eqm
|
|
|
|
CUT, EDIT = "끊음", eqm.KEY
|
|
MANY = 400 # 끊은 기초가 닿는 줄 상한
|
|
_OWN: dict[int, tuple[Any, Any, Any]] = {}
|
|
|
|
|
|
def is_block(one: Any) -> bool:
|
|
"""더한 기초 = 더한줄 로직(참조 · 고정 · 자원 줄 아님)."""
|
|
return isinstance(one, dict) and one.get("종류") == "로직" and bool(one.get("로직"))
|
|
|
|
|
|
def clean(raw: dict, where: str) -> dict:
|
|
"""`sd._added` 가 부름 — 끊음 · 수식고침 꼴만(뜻 검사는 셈 · 저장 `strict`)."""
|
|
cut = raw.get(CUT)
|
|
if not cut:
|
|
if raw.get(EDIT):
|
|
raise sd.DocError(f"{where} · 수식 고침은 연결을 끊은 기초만")
|
|
return {}
|
|
rows = cut.get("로직") if isinstance(cut, dict) else None
|
|
code = str(raw.get("로직"))
|
|
if any(raw.get(k) not in (None, {}, []) for k in sd.BODY):
|
|
raise sd.DocError(f"{where} · 넣은 SK 몸은 이미 이 SK 안 사본 — 연결 끊기 없음")
|
|
if (
|
|
not isinstance(rows, list)
|
|
or len(rows) > MANY
|
|
or not all(isinstance(r, dict) and r.get("키") for r in rows)
|
|
):
|
|
raise sd.DocError(f"{where} · 끊은 기초 사본 꼴이 틀림")
|
|
rows = [r for r in rows if str(r["키"])[:2] not in skc.RES] # 단가 = SK 사본 한 곳
|
|
if code not in {str(r["키"]) for r in rows}:
|
|
raise sd.DocError(f"{where} · 끊은 기초 사본에 「{code}」 줄 없음")
|
|
return {CUT: {"시점": str(cut.get("시점") or ""), "로직": rows}} | eqm.clean(raw, {})
|
|
|
|
|
|
def own(one: dict, whole: Any) -> Any:
|
|
"""끊은 기초의 셈 색인 — `whole` 위에 자기 사본 줄(끊음 아님 = `whole` 그대로)."""
|
|
cut = one.get(CUT)
|
|
if not isinstance(cut, dict):
|
|
return whole
|
|
hit = _OWN.get(id(cut))
|
|
if hit and hit[0] is cut and hit[1] is whole:
|
|
return hit[2]
|
|
if len(_OWN) > 32: # ponytail: 통째 비움 · 끊은 기초가 많아 느려지면 LRU 로
|
|
_OWN.clear()
|
|
got = skc.Copy(whole, skc._rows(cut))
|
|
_OWN[id(cut)] = (cut, whole, got)
|
|
return got
|
|
|
|
|
|
def row_of(whole: Any, one: dict, edits: list | None = None) -> tuple[dict, list[str], Any]:
|
|
"""(끊은 기초 줄 + 수식 고침, 못 얹은 까닭, 그 기초 셈 색인) — `edits` None = 그 기초 자기 고침."""
|
|
mine = own(one, whole)
|
|
row = mine.logic(str(one["로직"]))
|
|
use = one.get(EDIT) if edits is None else edits
|
|
if not use:
|
|
return row, [], mine
|
|
new, why = eqm.apply(row, use, mine)
|
|
return new, why, mine
|
|
|
|
|
|
def strict(doc: dict, whole: Any) -> None:
|
|
"""저장 — 끊은 기초 고침이 못 얹히면 400."""
|
|
for at, one in enumerate(doc.get("더한줄") or [], 1):
|
|
if is_block(one) and one.get(EDIT):
|
|
why = row_of(whole, one)[1]
|
|
if why:
|
|
raise sd.DocError(f"더한줄 {at}째 수식 고침 못 얹음 — " + " · ".join(why))
|
|
|
|
|
|
def names(doc: Any) -> list[str]:
|
|
"""끊은 기초 이름들([단가 갱신] · [재생성] 보고)."""
|
|
adds = (doc.get("더한줄") if isinstance(doc, dict) else None) or []
|
|
return [str(x.get("이름") or x.get("로직")) for x in adds if is_block(x) and x.get(CUT)]
|