feat(859-4): 같은 이름 · 규격 품목 여러 줄 = 엑셀 단가와 값이 가장 가까운 줄(단가산출 · 일위대가 불러오기 공통)

- San_MatFind.closest — 이은 키의 쌍둥이(지역 꼬리 뗀 이름 · 규격 같은 줄 + 표기만 다른 같은 품목 줄 Hopyo_MatSame.peers) 가운데 같은 단위 · 값이 엑셀 단가에 가장 가까운 줄 · 줄 글이 밝힌 지역 · 상하차 · 관급/사급 안에서만 · 값 같음 · 엑셀 값 없음 = 지금 차례
- San_Link.m01 재료 = 자원 엑셀 단가(단가[비목])를 넘김 · 코드 길(done)도 같은 규칙
- 북부청임도 원형돌망태 12 줄 = 엑셀과 같은 품목(MT006349 · MT006350 · 관급 값 없는 줄 아님) · 일위대가 재료 이음 다른 품목 0
- 뜻한 바뀜 = 불러오기 지문 블록 40(3,241 중 · 엑셀 판 금액 · 검산 같음 · 우리 판만 다름 · 바뀐 줄 55 번 13 종) · 올림 「고정 · 재료」 7 파일
- 시험 test_859_4 넷 더함(값 가까운 줄 · 밝힌 지역 · 불러오기 길 값 관문 없음 · 판정 말)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 22:24:16 +09:00
co-authored by Claude Opus 5.5
parent be7c1ead3a
commit 4575becf8a
5 changed files with 194 additions and 65 deletions
+19 -5
View File
@@ -217,6 +217,16 @@ def same(line: dict[str, Any]) -> dict[str, Any] | None:
hits = [book()["줄"][i] for i in book()["찾기"]["spec"].get(me["whole"], [])]
hits = [x for x in hits if not x["bag"] and not me["bag"]]
return _pick(hits, line) if hits and len({_fold(x) for x in hits}) == 1 else None
ok = _ok(me, scored)
if not ok:
return None
best = max(k for k, _ in ok)
group = [x for k, x in ok if k == best]
return _pick(group, line) if len({_fold(x) for x in group}) == 1 else None
def _ok(me: dict[str, Any], scored: list) -> list[tuple[tuple, dict[str, Any]]]:
"""㉮ 표기만 다른 같은 품목으로 볼 줄 — 굳센 이름 같음 · 규격 수 맞음 · 수 없는 규격은 낱말 겹침."""
ok = []
for (strong, share, tier, common, words, same_core), x in scored:
if not tier or (tier == 1 and not strong):
@@ -224,11 +234,15 @@ def same(line: dict[str, Any]) -> dict[str, Any] | None:
if not me["bag"] and not x["bag"] and not share and words:
continue # 수 없는 규격 = 규격 낱말이 겹쳐야
ok.append(((tier, common, share, strong, same_core), x))
if not ok:
return None
best = max(k for k, _ in ok)
group = [x for k, x in ok if k == best]
return _pick(group, line) if len({_fold(x) for x in group}) == 1 else None
return ok
def peers(line: dict[str, Any]) -> list[str]:
"""줄과 표기만 다른 같은 품목 자재 키들(859-4 값 가까운 줄 고름 · 규격 빈 줄 = 없음)."""
me, scored = _scored(line)
if not me["spec"]:
return []
return [k for _, x in _ok(me, scored) if (k := x["row"]["one"].get("자재"))]
def _stems(me: dict[str, Any]) -> set[str]:
+13 -2
View File
@@ -29,6 +29,7 @@ def m01(kind: str, src: dict, label: str = "") -> tuple[str | None, str | None]:
from M02_MasterTemplete import M02_San_MatFind as mf
line = {k: src.get(k) or "" for k in ("이름", "규격", "단위")}
price = excel_price(src) # 859-4 같은 품목 여러 줄 = 엑셀 값 가까운 줄
if kind == "재료" and apart(line): # 817-1 원가 합 밖(원본 금액 그대로) · 827-2 품목은 판정에
clean = hmat_clean(line)
got = mf.find(clean, src, _keys(clean, hrow.m01_picks("재료", clean)), label, apart=True)
@@ -44,7 +45,7 @@ def m01(kind: str, src: dict, label: str = "") -> tuple[str | None, str | None]:
return got["키"], mfind.mark(got, line["이름"], line["규격"])
if kind == "재료" and src.get("종류") == "자재" and (hit := ea.est_code(src.get("코드"))):
key = ea.one(line, hit) or hit[0] # 815-1 K1 — EST 원파일 자재 = 우리 자재 출처 코드
return mf.done(key, "코드", src, line["단위"])["키"], None # 840-3 단위 맞춤
return mf.done(key, "코드", src, line["단위"], price)["키"], None # 840-3 단위 맞춤
oil = ea.keys("MO", line["이름"], line["규격"]) if kind == "재료" else []
if kind == "재료":
if oil or elem.oil_rows(line["이름"]):
@@ -63,7 +64,7 @@ def m01(kind: str, src: dict, label: str = "") -> tuple[str | None, str | None]:
else:
got = hrow.m01_picks(kind, line)
if kind == "재료": # 827-2 — 지금 찾기 키 → 판정(규칙 · 단서 · 네 갈래)
return mf.find(line, src, _keys(line, got), label)["키"], None
return mf.find({**line, "단가": price}, src, _keys(line, got), label)["키"], None
keys = {x.get("키") for x in got if x.get("키")}
if (
len(keys) > 1 and kind == "유가"
@@ -76,6 +77,16 @@ def m01(kind: str, src: dict, label: str = "") -> tuple[str | None, str | None]:
return None, None
def excel_price(src: dict) -> float | None:
"""자원 엑셀 단가(`단가` {L · M · S}[비목] · 비목 없음 = 재료비 M) — 없음 · 0 = None."""
price = src.get("단가") if isinstance(src.get("단가"), dict) else {}
try:
got = float(str(price.get(src.get("비목") or "M")).replace(",", ""))
except (TypeError, ValueError):
return None
return got if got > 0 else None
def _keys(line: dict, got: list[dict]) -> set[str]:
"""재료 1차 찾기 키 — 여럿이면 지역 꼬리 뗀 정확 일치(814-1) · 없으면 자재표 전체 정확 일치(815-1 K3)."""
from M02_MasterTemplete import M02_Elem_Alias as ea
+64 -4
View File
@@ -1,6 +1,7 @@
"""불러오기 재료 찾기 판정 · 단서 · 자동 규칙(PLAN 827-2 · 요구 810 ~ 812 · 조사 810-2 · 811-2).
`M02_San_Link.m01` 재료 줄이 부름 · 서버 단독 · 읽기만 · 판정은 이름 · 규격 · 단위 · 단서 글만(단가 값 안 봄) ·
`M02_San_Link.m01` 재료 줄이 부름(단가산출 · 일위대가 불러오기 한 벌 · 859-4) · 서버 단독 · 읽기만 ·
판정은 이름 · 규격 · 단위 · 단서 글만 · 이은 뒤 같은 품목 여러 줄 = 엑셀 단가와 값이 가장 가까운 줄(`closest`) ·
별칭을 만들거나 제안하지 않음(별칭 = 사람이 표기 변형을 잇는 칸 · 요구 812-1).
줄 판정 `자원["재료찾기"]` = {판정, 방법, 키, 후보, 단서}:
@@ -36,6 +37,7 @@ from typing import Any
from M02_MasterTemplete import M02_Hopyo_Match as hm
from M02_MasterTemplete import M02_Hopyo_Material as hmat
from M02_MasterTemplete import M02_Hopyo_MatSame as ms
from M02_MasterTemplete import M02_Mat_Place as place
LINKED, NO_SPEC, MANY, NONE = "이어짐", "규격 없음 — 고르기", "후보 여럿", "우리 표에 없음"
UNIT = "단위 다름 — 고르기"
@@ -125,21 +127,25 @@ def _texts(me: dict, code: str, label: str) -> tuple[tuple[str, str], ...]:
def find(
line: dict, src: dict | None = None, keys: Any = (), label: str = "", apart: bool = False
) -> dict:
"""재료 줄(별도계상 글 뗀) → 판정(`src` 있으면 `자원["재료찾기"]` 에 둠) · keys = 지금 엔진 찾기 키들."""
"""재료 줄(별도계상 글 뗀 · `단가` = 엑셀 단가) → 판정(`src` 있으면 `자원["재료찾기"]` 에 둠) ·
keys = 지금 엔진 찾기 키들."""
text = tuple(str(line.get(k) or "") for k in ("이름", "규격", "단위"))
code = str((src or {}).get("코드") or "")
me = ms._item(text[0], text[1])
keys = tuple(sorted(k for k in keys if k))
got = _by_unit(line, dict(_find(*text, keys, _texts(me, code, label), apart, id(hm.targets()))))
got = closest(line, got)
got |= {"후보": [dict(x) for x in got["후보"]], "단서": list(got["단서"])}
if src is not None:
src["재료찾기"] = got
return got
def done(key: str, how: str, src: dict | None = None, unit: str = "") -> dict:
"""이미 정한 이음(코드 길) 판정."""
def done(key: str, how: str, src: dict | None = None, unit: str = "", price: Any = None) -> dict:
"""이미 정한 이음(코드 길) 판정 · `price` = 엑셀 단가(같은 품목 지역 줄 고름)."""
got = _by_unit({"단위": unit}, {"판정": LINKED, "방법": how, "키": key, "후보": [], "단서": []})
head = {k: (src or {}).get(k) or "" for k in ("이름", "규격")}
got = closest({**head, "단위": unit, "단가": price}, got)
if src is not None:
src["재료찾기"] = got
return got
@@ -200,6 +206,60 @@ def _by_unit(line: dict, got: dict) -> dict:
}
def closest(line: dict, got: dict) -> dict:
"""같은 품목 여러 줄 → 엑셀 단가(`line["단가"]`)와 값이 가장 가까운 줄(859-4 · 요구 903) — 이은 판정만 ·
쌍둥이 = 지역 꼬리 뗀 이름 · 규격 같은 줄(`ea.exact` · 지역 · 상하차) + 표기만 다른 같은 품목 줄
(`ms.peers` · 관급/사급 · 덧말) · 이은 줄과 같은 단위 · 줄 글이 밝힌 지역 · 상하차 · 관급/사급이 맞는 줄 먼저
(「외송각재, 대전」 = 대전 줄들 안에서) · 값 같음 · 엑셀 값 없음 = 지금 차례 그대로."""
from M02_MasterTemplete import M02_Elem_Alias as ea
want, key = _money(line.get("단가")), got.get("키")
if want is None or got["판정"] != LINKED or not key:
return got
row = ea.row(ea.MARKET, key)
if not row:
return got
unit, plain = row.get("단위"), hm.mm.plain_unit
pool = [key, *ea.exact(row.get("이름"), row.get("규격"))]
pool += (
ms.peers({k: line.get(k) or "" for k in ("이름", "규격", "단위")})
if line.get("이름")
else []
)
pool = [k for k in pool if _told(line, ea.row(ea.MARKET, k))] or pool
def gap(k: str) -> float | None:
r = ea.row(ea.MARKET, k)
v = _money(place.value(r)) if r else None
return None if v is None or plain(r.get("단위")) != plain(unit) else abs(v - want)
scored = [(g, i, k) for i, k in enumerate(dict.fromkeys(pool)) if (g := gap(k)) is not None]
best = min(scored)[2] if scored else key
return got if best == key else {**got, "키": best, "방법": f"{got['방법']} · 값 가까운 줄"}
def _told(line: dict, row: dict) -> bool:
"""우리 줄이 가져온 줄 글이 밝힌 지역 · 상하차 · 관급/사급과 맞음(밝힘 없음 = 맞음)."""
spot = place.line(line.get("이름"), line.get("규격"))
where = str(row.get("지역") or place.mmerge.where(row))
if spot["지역"] not in ("", place.NONE) and not place.hit(where, spot["지역"]):
return False
if spot["상하차"] not in ("", place.NONE) and row.get("상하차") != spot["상하차"]:
return False
text = f"{line.get('이름') or ''} {line.get('규격') or ''}"
want = next((w for w in hmat.SUPPLY if w in text), None)
have = next((w for w in hmat.SUPPLY if w in str(row.get("이름") or "")), None)
return want is None or have in (None, want)
def _money(raw: Any) -> float | None:
try:
got = float(str(raw).replace(",", ""))
except (TypeError, ValueError):
return None
return got if got > 0 else None
def _alike(me: dict, x: dict) -> bool:
"""이름 같은 우리 줄이 이 물건일 수 있음 — 우리 규격 빔 · 가져온 수 없음 · 수 하나라도 같음(BUTTON BIT Ø38 ↔ 105mm = 아님)."""
return (