refactor(855-E 2-E4 ㉯-3 ⑤): 옛 수식 탭 무리 지움 — M01 Equation · Sangeun_Formula · master_equation 다섯
- git rm: M01_MasterData_Equation(서버 길 없음 · 제품 부름 0 · 시험만) · M02_Sangeun_Formula(_catch · _eng 파서 · 식 글 번역 — 부르는 곳 = M01 Equation 뿐) · scripts master_equation · _edit · _group · _view · _sign(서로 · 위 둘 · 시험만 부름) - master_symbol: M02_San_ToDoc 이 쓰는 SUBMAX · lookup(+ rule · short) 만 남김 — 옛 수식 내보내기 기호 씌우기(apply · _walk · family_name · is_symbol · SYMBOL · FAMILY) 지움 - 남김: master_equation_link(M01 Doc 새 기호 연결 후보) · ui_template_equation*(새 줄 쌓기 eqText) · M02_Sangeun_Equation(옛 칸 수식고침 받으면 400 지킴 — 엔진 몸 아님 · 동작) - 시험: test_796_1 · 799_1 · 800_5 · 801_3 git rm(옛 수식 나무 · 묶음 · 기호 모델만 봄) · 792_1 식 글 번역 · 상한 둘 지움(옛 SK 식 칸 막음 · 초기화 · 지문 그대로) · 800_2 = 새 기호 연결 후보만(로직 갈래 → 단가산출 갈래 · 옛 수식 탭 · 화면 소스 글자 시험 지움) - 죽은 주석: Sangeun_Copy · Sangeun_Equation · master_doc_trace · master_equation_link - 서버 길 469 → 469(길 없던 모듈) · typecheck 0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,7 +132,7 @@ class Copy:
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
return getattr(self._whole, name)
|
||||
|
||||
def __copy__(self) -> Copy: # 수식 고침(796-2b · `master_equation_edit.swap`) — 얕은 사본
|
||||
def __copy__(self) -> Copy: # 얕은 사본(옛 수식 고침 796-2b 몫)
|
||||
out = object.__new__(Copy)
|
||||
out.__dict__.update(self.__dict__)
|
||||
return out
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""M02 단가산출(SK) 옛 칸 `수식고침`(PLAN 796-2b) — 받지 않음(855-E 2-E4).
|
||||
|
||||
옛 수식 탭 고침 = 바탕 로직 줄에 엔진 수식 고침(`master_equation_edit`)을 얹던 칸 · 화면 길은 894 에서 걷음 ·
|
||||
옛 수식 탭 고침 = 바탕 로직 줄에 엔진 수식 고침(옛 `master_equation_edit` · 855-E 2-E4 지움)을 얹던 칸 · 화면 길은 894 에서 걷음 ·
|
||||
저장본 0 · 고침은 단가산출 수식 문서(줄 쌓기 · 수식 길 저장)로 — 받으면 400.
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
"""M02 단가산출 식 글 번역(PLAN 792-1 · 855 2-E2) — 이름 꼴 ↔ 엔진 식 · 식 글 상한.
|
||||
|
||||
M01 수식 탭(`M01_MasterData_Equation`) · 가져온 식(`M02_Sangeun_Imported`)이 부름.
|
||||
이름 꼴 — `×` `÷`(= `*` `/`) · `[노임 형틀목공]`(요소 · 겹치면 키 덧붙임) · `[별칭]`(바탕 줄
|
||||
`찾기` · `로직` 부르기 = `master_copy.aliases` · 별칭표는 바탕 줄에서만 지음 = 사용자 고침에
|
||||
안 흔들림) · 맨 이름 = 입력 · 중간 · 변수 · 덧줄 · 비목 · 엔진 날식도 그대로 받음.
|
||||
옛 SK 식 칸(변수줄 · 식덮개 · 더한줄 수량식)은 셈 은퇴(855 2-C1) 뒤 받지 않음(`M02_Sangeun_Const.clean_more` · 855 2-E2).
|
||||
보안 — eval 없음(엔진 파서만) · 식 길이 `LONG` · 괄호 깊이 `DEEP`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
LONG = 300 # 식 글 길이
|
||||
DEEP = 12 # 괄호 깊이
|
||||
WORD = {
|
||||
"LB": "노임",
|
||||
"EQ": "기계",
|
||||
"MT": "자재",
|
||||
"MP": "자재",
|
||||
"MO": "유가",
|
||||
"FX": "환율",
|
||||
"RT": "요율",
|
||||
}
|
||||
|
||||
|
||||
def _eng() -> Any:
|
||||
from M02_MasterTemplete import M02_Labor_Doc as labor
|
||||
|
||||
return labor.m01.cm.mf
|
||||
|
||||
|
||||
def _whole() -> Any:
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
|
||||
return m01.loaded()[1]
|
||||
|
||||
|
||||
# ── 식 글 상한 ────────────────────────────────────────────────────────
|
||||
def limits(text: str) -> list[str]:
|
||||
"""식 글 상한 — 길이 · 괄호 깊이(파서 앞 · 깊은 괄호 = 서버 500 막음)."""
|
||||
out, depth, top, quoted = [], 0, 0, False
|
||||
if len(text) > LONG:
|
||||
out.append(f"식이 {LONG} 자를 넘음")
|
||||
for ch in text:
|
||||
if ch == "'":
|
||||
quoted = not quoted
|
||||
elif not quoted and ch in "([":
|
||||
depth += 1
|
||||
top = max(top, depth)
|
||||
elif not quoted and ch in ")]":
|
||||
depth -= 1
|
||||
if top > DEEP:
|
||||
out.append(f"괄호가 {DEEP} 겹을 넘음")
|
||||
return out
|
||||
|
||||
|
||||
# ── 이름 꼴 ↔ 엔진 식 ────────────────────────────────────────────────
|
||||
@functools.lru_cache(maxsize=2)
|
||||
def _labels(whole: Any) -> tuple[dict, dict]:
|
||||
"""(키 → 이름 꼴 글, 글 → 키) — 같은 글이 여럿이면 글에 키를 덧붙임."""
|
||||
base: dict[str, str] = {}
|
||||
for tid, word in WORD.items():
|
||||
for key, row in (whole.index.get(tid) or {}).items():
|
||||
words = (word, str(row.get("이름") or ""), str(row.get("규격") or ""))
|
||||
base[key] = re.sub(r"\s+", " ", re.sub(r"[\[\]]", "", " ".join(words))).strip()
|
||||
count: dict[str, int] = {}
|
||||
for label in base.values():
|
||||
count[label] = count.get(label, 0) + 1
|
||||
label_of = {k: v if count[v] == 1 else f"{v} {k}" for k, v in base.items()}
|
||||
return label_of, {v: k for k, v in label_of.items()}
|
||||
|
||||
|
||||
def _mc() -> Any:
|
||||
_eng() # 엔진 길(scripts)이 sys.path 에 깔림
|
||||
import master_copy
|
||||
|
||||
return master_copy
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=512)
|
||||
def _alias_of(raw: str) -> tuple[tuple[str, str], ...]:
|
||||
"""바탕 줄 별칭표 ((이름, 원문)) — 줄 글마다 한 번."""
|
||||
return tuple((a["이름"], a["원문"]) for a in _mc().aliases(json.loads(raw), _whole()))
|
||||
|
||||
|
||||
def aliases(row: dict) -> dict[str, str]:
|
||||
"""{별칭: 원문 부르기}(바탕 줄 · `master_copy.aliases`)."""
|
||||
return dict(_alias_of(json.dumps(row, ensure_ascii=False, sort_keys=True, default=str)))
|
||||
|
||||
|
||||
@functools.cache
|
||||
def _catch() -> type:
|
||||
"""엔진 파서 + 요소 키 · 부르기 글자 자리 기록."""
|
||||
mf = _eng()
|
||||
|
||||
class Catch(mf._Parser):
|
||||
def __init__(self, text: str) -> None:
|
||||
super().__init__(text)
|
||||
self.refs: list = []
|
||||
self.calls: list = []
|
||||
|
||||
def primary(self): # noqa: ANN202
|
||||
self.ws()
|
||||
at = self.i
|
||||
node = super().primary()
|
||||
if node[0] == "ref" and mf.mk.KEY.fullmatch(node[1]):
|
||||
self.refs.append((at, self.i, node[1]))
|
||||
elif node[0] in ("find", "logic"):
|
||||
self.calls.append((at, self.i))
|
||||
return node
|
||||
|
||||
return Catch
|
||||
|
||||
|
||||
def _spots(text: str) -> tuple[list, list] | None:
|
||||
"""(요소 키 자리, 바깥 부르기 자리) · 못 읽음 = None."""
|
||||
mf, p = _eng(), _catch()(text)
|
||||
try:
|
||||
p.parse()
|
||||
except (mf.FormulaError, RecursionError):
|
||||
return None
|
||||
calls = [
|
||||
c for c in p.calls if not any(o[0] <= c[0] and c[1] <= o[1] and o != c for o in p.calls)
|
||||
]
|
||||
return p.refs, calls
|
||||
|
||||
|
||||
def to_name(text: str, row: dict) -> str:
|
||||
"""엔진 식 → 이름 꼴(`*` → `×` · 요소 = `[노임 …]` · 바탕 별칭 부르기 = `[별칭]`)."""
|
||||
got = _spots(text)
|
||||
if got is None:
|
||||
return text
|
||||
refs, calls = got
|
||||
label_of = _labels(_whole())[0]
|
||||
raw_to = {re.sub(r"\s+", " ", v): k for k, v in aliases(row).items()}
|
||||
cuts = []
|
||||
for a, b in calls:
|
||||
name = raw_to.get(re.sub(r"\s+", " ", text[a:b]))
|
||||
if name:
|
||||
cuts.append((a, b, f"[{name}]"))
|
||||
for a, b, key in refs:
|
||||
if key in label_of and not any(x <= a and b <= y for x, y in calls):
|
||||
cuts.append((a, b, f"[{label_of[key]}]"))
|
||||
out, at = [], 0
|
||||
for a, b, word in sorted(cuts):
|
||||
out += [_times(text[at:a]), word]
|
||||
at = b
|
||||
return "".join(out) + _times(text[at:])
|
||||
|
||||
|
||||
def _times(part: str) -> str:
|
||||
"""따옴표 밖 `*` → `×`."""
|
||||
bits = part.split("'")
|
||||
return "'".join(b.replace("*", "×") if i % 2 == 0 else b for i, b in enumerate(bits))
|
||||
|
||||
|
||||
def to_engine(text: str, row: dict) -> tuple[str, list[str]]:
|
||||
"""이름 꼴 → (엔진 식, 까닭) — `×` `÷` · `[…]` = 키 · 바탕 별칭 · 요소 글 · 맨 별칭 이름."""
|
||||
names = aliases(row)
|
||||
find = _labels(_whole())[1]
|
||||
mk = _eng().mk
|
||||
out, why, at, quoted = [], [], 0, False
|
||||
while at < len(text):
|
||||
ch = text[at]
|
||||
if ch == "'":
|
||||
quoted = not quoted
|
||||
if quoted or ch not in "×÷[]":
|
||||
out.append(ch)
|
||||
at += 1
|
||||
continue
|
||||
if ch in "×÷":
|
||||
out.append("*" if ch == "×" else "/")
|
||||
at += 1
|
||||
continue
|
||||
end = text.find("]", at)
|
||||
if ch == "]" or end < 0:
|
||||
return text, ["대괄호 짝 안 맞음"]
|
||||
word = re.sub(r"\s+", " ", text[at + 1 : end]).strip()
|
||||
keys = mk.KEY.findall(word)
|
||||
if word in names:
|
||||
out.append(names[word])
|
||||
elif word in find:
|
||||
out.append(find[word])
|
||||
elif keys and len(keys) == 1:
|
||||
out.append(keys[0])
|
||||
else:
|
||||
why.append(f"없는 이름 「[{word}]」")
|
||||
at = end + 1
|
||||
got = "".join(out)
|
||||
taken = _names(row)
|
||||
bare = {k: v for k, v in names.items() if k not in taken}
|
||||
return (_unmask(got, bare) if bare else got), why
|
||||
|
||||
|
||||
def _unmask(text: str, raw_of: dict) -> str:
|
||||
return _mc()._unmask(text, raw_of)
|
||||
|
||||
|
||||
def _names(row: dict) -> set[str]:
|
||||
return {str(x.get("이름")) for k in ("입력", "중간", "덧줄") for x in row.get(k) or []}
|
||||
Reference in New Issue
Block a user