refactor(776-3): 지문 형식 모름 — 단위 줄 투영 한 벌 · 몫 한 벌 · 블록 단가 = 항목 · clause 대체 몸 · 오타 정규식 걷음 · 맞춤 캐시 = HP 지문 칸
- Finger — 풀이 두 벌(_text · _stmate) 걷고 블록 단위 줄 투영 하나(_units) · 글은 조건 · 옛 판 · 계수 · 「…의 N %」 만 · 셈 밖 줄 안 씀 - Shares — 몫 = 단위 줄을 절(제목 · 윗절)로 묶음 한 벌 · 식 다시 풀기(qty_of · sections_stm) 걷음 · trade = ReadEst.trade - Elem.prices = 단위 줄 단가(글 다시 안 풂 · machines 갈래 안 건드림) - Match.clause = Basis.clause 만 · 대체 몸 · _TYPO_CLAUSE 걷음(오타는 읽기 ReadEst.sources) · fix_typo = 사본(Line 이 부름) - Fit.cache_path — HP 지문 칸(올린 엑셀 sha256 + 판) · 파일 그대로면 다시 안 읽음(lru) · 붙여넣기 HP 만 파일 해시 - 지문 전후 = 셈 단위 275 중 150 같음 · 다름 = 장비 절 · 글(쓰는 곳 없음) 100 · 고침(STmate 기계 두 묶음 · 거창 자재 · 끝 점 직종 · 옛 몫 금액 ÷ 단가 엉터리 · 제외금액 줄) — 골든 1위 줄마다 · 불리는 블록 206 갈래 · 1위 · 상태 전후 같음(162/177 · 기초 80 · SK 37 · 대기 89) - S1 다시 굳힘 = 봉화 · 울진대흥 · 울진소광 자원(같은 코드 두 묶음 따로) · S2 다시 굳힘 125/275(위 까닭) - 시험 고침 — finger(블록 = ReadEst.items · STmate 단위 줄 · 셈 밖) · fit 옛 HP(항목 · 글 없음) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
노임 = LB 이름 글자 묶음 닮음 · 단가 = LB 값
|
||||
기계 = EQ 갈래 겹침 · 규격 수(같음 1 · 겹침 0.5) · 이름 낱말 덤 · 괄호 낱말 어긋남 깎음 ·
|
||||
단가 없음(기계경비는 로직 셈) · `machine` = 하나로 가름(778-1)
|
||||
차례 = 점수(0.1 단위로 접음) › 엑셀 단가에 가까운 것(엑셀 단가 = 블록 글 「이름 단가 × 식 = 금액」 · 모르면 점수만).
|
||||
차례 = 점수(0.1 단위로 접음) › 엑셀 단가에 가까운 것(엑셀 단가 = 블록 단위 줄 단가 · 모르면 점수만).
|
||||
서버 단독 · 읽기만.
|
||||
"""
|
||||
|
||||
@@ -17,10 +17,10 @@ import re
|
||||
from typing import Any
|
||||
|
||||
from M01_MasterData import M01_MasterData_Store as m01
|
||||
from M02_MasterTemplete import M02_Hopyo_Finger as finger
|
||||
from M02_MasterTemplete import M02_Hopyo_Match as hm
|
||||
from M02_MasterTemplete import M02_Hopyo_Material as hmat
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import mtypes, nfkc, parse_rhs, specnums
|
||||
from M02_MasterTemplete import M02_Hopyo_UnitLine as unit_line
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import mtypes, nfkc, specnums
|
||||
|
||||
TOP = 3
|
||||
POOL = 5
|
||||
@@ -35,16 +35,12 @@ PARTS = ("자동덮개", "부착용", "콤팩터", "습지")
|
||||
|
||||
|
||||
def prices(block: dict[str, Any] | None) -> dict[str, float]:
|
||||
"""블록 글 → `{이름: 엑셀 단가}`(직종 줄 「직종 : 단가 × 식」 · 자재 줄 「이름 단가 × 식 = 금액」)."""
|
||||
"""블록 단위 줄(노무 · 자재 · 값) → `{이름: 엑셀 단가}`(첫 것 · 776-3 — 글 다시 안 풂)."""
|
||||
out: dict[str, float] = {}
|
||||
for raw in (block or {}).get("글") or []:
|
||||
row = str(raw).rstrip()
|
||||
cm = finger._COLON.match(row)
|
||||
mm = None if cm else finger._MAT.match(row)
|
||||
name = (cm or mm).group("name").strip() if (cm or mm) else ""
|
||||
got = parse_rhs((cm or mm).group("rhs")) if name else None
|
||||
if got and got.get("단가"):
|
||||
out.setdefault(re.sub(r"^[0-9가-힣]\.", "", name).strip(), float(got["단가"]))
|
||||
for one in (block or {}).get("항목") or []:
|
||||
price = unit_line.money(one.get("단가")) if one.get("묶음") in ("L", "M", "E") else None
|
||||
if price:
|
||||
out.setdefault(re.sub(r"^[0-9가-힣]\.", "", str(one.get("이름") or "")).strip(), price)
|
||||
return out
|
||||
|
||||
|
||||
|
||||
@@ -1,102 +1,45 @@
|
||||
"""M02 일위대가 실무자료 엑셀 지문(PLAN 338-1 · 설계 2-2) — 호표 줄 + 이어진 단가산출 블록 →
|
||||
직종 품 · 장비 시간 · 자재 수량 · 율 · 계수 · 조건 · 조항 · 몫. 금액 안 씀(식 맨 앞 단가는 뗌).
|
||||
"""M02 일위대가 실무자료 엑셀 지문(PLAN 338-1 · 설계 2-2 · 776-3) — 호표 줄 + 이어진 단가산출 블록 →
|
||||
직종 품 · 장비 시간 · 자재 수량 · 율 · 계수 · 조건 · 조항 · 몫. 금액 안 씀.
|
||||
|
||||
엑셀꼴 = 블록 `글`(머리 뺀 몸 줄)을 줄마다 풂 — 절 `^\\d+\\.` · 작은 절 `^[가-하]\\.` ·
|
||||
직종 줄 「직종 : 단가 × 식 = 금액」(우리 인력 이름 · 옛이름) · 장비 = 「노무비 · 경비 · 재료비 :
|
||||
단가 ÷ Q」
|
||||
+ 지금 장비(노무비 > 경비 > 재료비) · 자재 = 「이름 단가 × 수량 = 금액」 · 「: 별도계상」 ·
|
||||
못 풀면 금액 ÷ 단가(「역산」 · 품 되찾기만).
|
||||
STmate = 블록 `자원`(L · X · M · S) 품이 곧 품(노무비 · 재료비 · 경비 세 줄 같은 품은 한 번) ·
|
||||
섞음 = 이름 · 규격 몫 둘(작은 쪽 인력 · 큰 쪽 장비).
|
||||
몫(조합용 · 설계 2-7) = 맨 윗 절마다 노임 · 장비 벡터(`M02_Hopyo_Shares`).
|
||||
형식 모름 — 블록 단위 줄(`항목` · `M02_Hopyo_UnitLine`)의 투영:
|
||||
L 노무 = 직종 품 · 식이 있으면 맨 인자가 섞음 비율 후보(호표 이름 · 규격 · 절 제목의 (N%) ·
|
||||
8:2)와 같을 때 율로 가름 · 식 없는 줄(QTY)은 호표 이름 비율 둘 이상이면 작은 쪽(인력)
|
||||
X 기계 = 장비 {갈래, 규격, 시간, 밑시간, 율, 절, 글} · 식 없는 줄은 큰 비율(장비)로 가름
|
||||
M 자재 = 식(수량) · 별도계상(품 없음) · E 값 줄에 수량이 있으면 장비 글이면 장비 · 아니면 자재
|
||||
셈 밖 · 율 · 하위 줄 = 안 씀(율 % 는 글에서).
|
||||
글(블록 머리 「N.이름 [단위]」 + 몸 글) = 조건 · 옛 판 · 계수(q · K · f …) · 글 속 「…의 N %」.
|
||||
몫(조합용 · 설계 2-7) = 절마다 노임 · 장비 벡터(`M02_Hopyo_Shares.sections`).
|
||||
블록 없는 기계(hr) 줄 = `machine` · 노임 · 장비를 바로 적은 호표 = `direct`.
|
||||
값 · 규칙은 336 실험(C4 `s1_excel_fp` · K5 `stmate`) 그대로.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections import Counter
|
||||
from typing import Any
|
||||
|
||||
from M02_MasterTemplete import M02_Hopyo_Basis as hopyo_basis
|
||||
from M02_MasterTemplete import M02_Hopyo_ReadEst as hopyo_est
|
||||
from M02_MasterTemplete import M02_Hopyo_Shares as shares
|
||||
from M02_MasterTemplete.M02_Hopyo_Shares import trade
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import conds, mtypes, parse_rhs, specnums
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import conds, mtypes, specnums
|
||||
|
||||
COST = {"노무비", "재료비", "경비"}
|
||||
SKIPW = {
|
||||
"소계",
|
||||
"계",
|
||||
"합계",
|
||||
"인부소계",
|
||||
"자재소계",
|
||||
"주자재소계",
|
||||
"운반",
|
||||
"상차",
|
||||
"기계",
|
||||
"다짐",
|
||||
"적사",
|
||||
"살수",
|
||||
"집토",
|
||||
"암절취",
|
||||
"채집",
|
||||
"인력",
|
||||
"장비",
|
||||
"작업조건",
|
||||
"1일시공량",
|
||||
"작업면적",
|
||||
"1시간작업량",
|
||||
"기계채집",
|
||||
"구조물터파기",
|
||||
}
|
||||
_COLON = re.compile(
|
||||
r"^\s*(?:\d+\)|[0-9가-힣]\.)?\s*(?P<name>[^::=]{1,40}?)\s*[::]\s*(?P<rhs>.*)$"
|
||||
)
|
||||
_MAT = re.compile(
|
||||
r"^\s*(?P<name>[^\d\s::=][^::=]*?[A-Za-z가-힣)\]])\s+(?P<rhs>[\d,]+(?:\.\d+)?\s*[×xX*÷/].*=.*)$"
|
||||
)
|
||||
_PCT = re.compile(r"([가-힣]+)의\s*([\d.]+)\s*%")
|
||||
_COEF = re.compile(
|
||||
r"(?<![A-Za-z가-힣])(q|qs|q1|K|k|f|f1|f2|E|Es|Cm|L|V1|V2|T|rt|n|t1|t2|t3|t4)\s*=\s*"
|
||||
r"(\d+(?:\.\d+)?)(?![\d.]*\s*[×x*÷/])"
|
||||
)
|
||||
_HEAD = re.compile(r"^\s*(\d+)\.\s*(.*)$")
|
||||
_SUB = re.compile(r"^\s*([가-하])\.\s*(.*)$")
|
||||
_SECTION = re.compile(r"^\s*(\d+\.|[가-하]\.)")
|
||||
OLD = re.compile(
|
||||
r"((?<![\d,.])20(0\d|1\d|20)(?![\d,.])|(?<!\d)(1\d|20)년|임도품셈|임도표준품셈|사방품셈|사방사업표준품셈)"
|
||||
)
|
||||
_LASTNUM = re.compile(r"=\s*([\d,]+(?:\.\d+)?)\s*$")
|
||||
_HOURS = re.compile(r"(hr|시간)", re.I)
|
||||
TRADE_UNITS = ("인",)
|
||||
rates_in = hopyo_est.rates_in
|
||||
|
||||
|
||||
def _flat(s: Any) -> str:
|
||||
return re.sub(r"\s+", "", str(s or ""))
|
||||
|
||||
|
||||
def _ratio(rhs: str) -> float | None:
|
||||
"""식을 못 풀 때만 — 금액 ÷ 단가(품 되찾기용)."""
|
||||
m = re.match(r"^\s*([\d,]+(?:\.\d+)?)", rhs)
|
||||
n = _LASTNUM.search(rhs)
|
||||
if not m or not n:
|
||||
return None
|
||||
p, a = float(m.group(1).replace(",", "")), float(n.group(1).replace(",", ""))
|
||||
return a / p if p else None
|
||||
|
||||
|
||||
def rates_in(text: Any) -> set[float]:
|
||||
"""글 속 섞음 비율 후보 — (N%) · 8:2 · 9:1."""
|
||||
t = str(text or "")
|
||||
out = {round(float(n) / 100, 4) for n in re.findall(r"(\d+(?:\.\d+)?)\s*%", t)}
|
||||
out = {v for v in out if 0 < v < 1}
|
||||
for a, b in re.findall(r"(\d+)\s*:\s*(\d+)", t):
|
||||
a, b = float(a), float(b)
|
||||
if a and b and a + b <= 20:
|
||||
out |= {round(a / (a + b), 4), round(b / (a + b), 4)}
|
||||
return out
|
||||
|
||||
|
||||
def empty(line: dict[str, Any], block: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
block = block or {}
|
||||
basis = line.get("근거") or {}
|
||||
@@ -133,12 +76,10 @@ def _round(fp: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def excel(block: dict[str, Any] | None, line: dict[str, Any]) -> dict[str, Any]:
|
||||
"""HP 블록(설계 3-1) + 그 줄(이름 · 규격 · 단위) → 지문 · 블록이 없거나 글 · 자원이 없으면
|
||||
"""HP 블록(설계 3-1) + 그 줄(이름 · 규격 · 단위) → 지문 · 블록이 없거나 단위 줄 · 글이 없으면
|
||||
기계(hr) 줄 지문(장비 1 시간) 또는 빈 지문."""
|
||||
if block and block.get("자원"):
|
||||
return _round(_stmate(block, line))
|
||||
if block and block.get("글"):
|
||||
return _round(_text(block, line))
|
||||
if block and (block.get("항목") or block.get("글")):
|
||||
return _round(_units(block, line))
|
||||
return machine(line)
|
||||
|
||||
|
||||
@@ -155,124 +96,59 @@ def machine(line: dict[str, Any]) -> dict[str, Any]:
|
||||
return fp
|
||||
|
||||
|
||||
def _text(block: dict[str, Any], line: dict[str, Any]) -> dict[str, Any]:
|
||||
"""엑셀꼴 — 블록 글 줄마다 풂(C4 `north`)."""
|
||||
fp = empty(line, block)
|
||||
def _text(fp: dict[str, Any], block: dict[str, Any]) -> None:
|
||||
"""블록 글 → 조건(머리 + 앞 넉 줄 + ※ · 작업조건 줄) · 옛 판 · 계수 · 「…의 N %」."""
|
||||
head = f"{block.get('번', '')}.{block.get('이름', '')} [{block.get('단위', '')}]"
|
||||
text = [head, *[str(t) for t in block.get("글") or []]]
|
||||
front = [t for t in text[:5]] + [t for t in text if "※" in t or "작업조건" in t]
|
||||
head_text = " ".join([fp["이름"], fp["규격"], *front])
|
||||
fp["조건"] = {k: sorted(v) for k, v in conds(head_text).items()}
|
||||
front = text[:5] + [t for t in text if "※" in t or "작업조건" in t]
|
||||
got = conds(" ".join([fp["이름"], fp["규격"], *front]))
|
||||
fp["조건"] = {k: sorted(v) for k, v in got.items()}
|
||||
fp["옛판"] = bool(OLD.search(" ".join(text[:6])))
|
||||
sec, sub, mach, label = 0, "", None, ""
|
||||
got_cost: dict[tuple, tuple] = {}
|
||||
item_rates = rates_in(f"{fp['이름']} {fp['규격']}")
|
||||
sec_rates: set[float] = set()
|
||||
|
||||
def unmix(got: dict | None) -> dict | None:
|
||||
"""율 메모가 없는데 맨 인자가 섞음 비율 후보와 같으면 율로 가름."""
|
||||
if got and not got["율"]:
|
||||
for v in got.get("인자") or []:
|
||||
if round(v, 4) in item_rates | sec_rates and 0 < v < 1:
|
||||
return {**got, "밑품": got["밑품"] / v, "율": [[round(v, 4), "섞음"]]}
|
||||
return got
|
||||
|
||||
for raw in text[1:]:
|
||||
row = raw.rstrip()
|
||||
h, s = _HEAD.match(row), _SUB.match(row)
|
||||
if h or s:
|
||||
if h:
|
||||
sec, sub = int(h.group(1)), ""
|
||||
sec_rates = rates_in(h.group(2))
|
||||
else:
|
||||
sub = s.group(1)
|
||||
sec_rates = sec_rates | rates_in(s.group(2))
|
||||
title = (h or s).group(2)
|
||||
ts = mtypes(title)
|
||||
mach = (ts, specnums(title)) if ts else None
|
||||
label = title.strip() if ts else ""
|
||||
for k, v in _PCT.findall(row):
|
||||
fp["율"].append([k, float(v)])
|
||||
cm = _COLON.match(row)
|
||||
name = re.sub(r"^[0-9가-힣]\.", "", _flat(cm.group("name"))) if cm else ""
|
||||
who = hopyo_basis.trade_names().get(name) if cm else None
|
||||
if who:
|
||||
rhs = cm.group("rhs")
|
||||
got = unmix(parse_rhs(rhs))
|
||||
if got:
|
||||
_labor(fp, who, got["품"], got["밑품"], got["율"], "식")
|
||||
elif r := _ratio(rhs):
|
||||
_labor(fp, who, r, r, [], "역산")
|
||||
continue
|
||||
if cm and name in COST:
|
||||
got = unmix(parse_rhs(cm.group("rhs")))
|
||||
if got and mach:
|
||||
key = (sec, sub, label)
|
||||
prio = 0 if (name == "노무비" and got["단가"] > 0) else 1 if name == "경비" else 2
|
||||
if key not in got_cost or prio < got_cost[key][0]:
|
||||
got_cost[key] = (prio, mach, got)
|
||||
continue
|
||||
if cm and name not in SKIPW and re.search(r"(별도|별산)", cm.group("rhs")):
|
||||
fp["자재"].append({"이름": cm.group("name").strip(), "품": None, "밑품": None})
|
||||
continue
|
||||
mm = _MAT.match(row)
|
||||
if mm and not cm and (got := parse_rhs(mm.group("rhs"))):
|
||||
fp["자재"].append(
|
||||
{"이름": mm.group("name").strip(), "품": got["품"], "밑품": got["밑품"]}
|
||||
)
|
||||
continue
|
||||
if not (h or s):
|
||||
ts = mtypes(row)
|
||||
if ts and "%" not in row and not cm:
|
||||
mach, label = (ts, specnums(row)), row.strip()
|
||||
for row in text[1:]:
|
||||
fp["율"] += [[k, float(v)] for k, v in _PCT.findall(row)]
|
||||
if not _SECTION.match(row):
|
||||
for k, v in _COEF.findall(row):
|
||||
fp["계수"].setdefault(k, float(v))
|
||||
for (sec_, sub_, lab), (_, (ts, sp), got) in got_cost.items():
|
||||
where = f"{sec_}.{sub_}" if sub_ else str(sec_)
|
||||
one = {"갈래": sorted(ts), "규격": sorted(sp), "시간": got["품"], "밑시간": got["밑품"]}
|
||||
fp["장비"].append({**one, "율": got["율"], "절": where, "글": lab})
|
||||
fp["몫"] = shares.sections(text[1:])
|
||||
return fp
|
||||
|
||||
|
||||
def _stmate(block: dict[str, Any], line: dict[str, Any]) -> dict[str, Any]:
|
||||
"""STmate — 자원 품이 곧 품(K5 `stmate`)."""
|
||||
def _unmix(one: dict[str, Any], rates: set[float]) -> tuple[float, list]:
|
||||
"""(밑품, 율) — 율 메모가 없는데 맨 인자가 섞음 비율 후보와 같으면 율로 가름."""
|
||||
if not one.get("율"):
|
||||
for v in one.get("인자") or []:
|
||||
if round(v, 4) in rates and 0 < v < 1:
|
||||
return one["밑품"] / v, [[round(v, 4), "섞음"]]
|
||||
return one["밑품"], one.get("율") or []
|
||||
|
||||
|
||||
def _units(block: dict[str, Any], line: dict[str, Any]) -> dict[str, Any]:
|
||||
fp = empty(line, block)
|
||||
text = [str(t) for t in block.get("글") or []][:60]
|
||||
fp["조건"] = {
|
||||
k: sorted(v) for k, v in conds(" ".join([fp["이름"], fp["규격"], *text[:4]])).items()
|
||||
}
|
||||
fp["옛판"] = bool(OLD.search(" ".join(text[:4])))
|
||||
for t in text:
|
||||
for k, v in _COEF.findall(t):
|
||||
fp["계수"].setdefault(k, float(v))
|
||||
for k, v in _PCT.findall(t):
|
||||
fp["율"].append([k, float(v)])
|
||||
rates = rates_in(f"{fp['이름']} {fp['규격']}")
|
||||
lab_rate = min(rates) if len(rates) >= 2 else None
|
||||
mach_rate = max(rates) if len(rates) >= 2 else None
|
||||
seen: Counter = Counter()
|
||||
for x in block.get("자원") or []:
|
||||
kind, q = x.get("갈래"), x.get("품")
|
||||
nm, sp = str(x.get("이름") or ""), str(x.get("규격") or "")
|
||||
if not q:
|
||||
_text(fp, block)
|
||||
item_rates = rates_in(f"{fp['이름']} {fp['규격']}")
|
||||
pair = sorted(item_rates) if len(item_rates) >= 2 else []
|
||||
lab_rate, mach_rate = (pair[0], pair[-1]) if pair else (None, None)
|
||||
for one in block.get("항목") or []:
|
||||
kind, q, how = one.get("묶음"), one.get("품"), one.get("어떻게")
|
||||
if one.get("밖") or (q is None and how != "별도"):
|
||||
continue
|
||||
seen[(x.get("코드"), round(float(q), 9))] += 1
|
||||
if seen[(x.get("코드"), round(float(q), 9))] > 1: # 노무비 · 재료비 · 경비 세 줄 같은 품
|
||||
continue
|
||||
q = float(q)
|
||||
ts = mtypes(f"{nm} {sp}")
|
||||
if kind == "L":
|
||||
if who := trade(nm):
|
||||
base = q / lab_rate if lab_rate else q
|
||||
_labor(fp, who, q, base, [[lab_rate, "섞음"]] if lab_rate else [], "QTY")
|
||||
elif kind == "X" or (kind == "S" and ts):
|
||||
one = {"갈래": sorted(ts), "규격": sorted(specnums(sp) | specnums(nm)), "시간": q}
|
||||
base = q / mach_rate if mach_rate else q
|
||||
fp["장비"].append({**one, "밑시간": base, "율": [], "절": "0", "글": f"{nm} {sp}"})
|
||||
elif kind in ("M", "S"):
|
||||
fp["자재"].append({"이름": f"{nm} {sp}".strip(), "품": q, "밑품": q})
|
||||
fp["몫"] = shares.sections_stm(block.get("자원") or [], text)
|
||||
text = f"{one.get('이름') or ''} {one.get('규격') or ''}".strip()
|
||||
rates = item_rates | set(one.get("절율") or [])
|
||||
if kind == "L" and (who := one.get("직종") or trade(one.get("이름"))):
|
||||
if how == "QTY":
|
||||
base, r = (q / lab_rate, [[lab_rate, "섞음"]]) if lab_rate else (q, [])
|
||||
else:
|
||||
base, r = _unmix(one, rates) if how == "식" else (one["밑품"], one["율"])
|
||||
_labor(fp, who, q, base, r, how)
|
||||
elif kind == "X" or (kind == "E" and mtypes(text)):
|
||||
if how == "QTY":
|
||||
base, r = (q / mach_rate if mach_rate else q), []
|
||||
else:
|
||||
base, r = _unmix(one, rates)
|
||||
sizes = specnums(one.get("규격") or "") | specnums(one.get("이름") or "")
|
||||
got = {"갈래": sorted(mtypes(text)), "규격": sorted(sizes), "시간": q}
|
||||
fp["장비"].append({**got, "밑시간": base, "율": r, "절": one.get("절"), "글": text})
|
||||
elif kind in ("M", "E") and (how in ("식", "별도", "QTY")):
|
||||
fp["자재"].append({"이름": text, "품": q, "밑품": one.get("밑품", q)})
|
||||
fp["몫"] = shares.sections(block.get("항목") or [])
|
||||
return fp
|
||||
|
||||
|
||||
@@ -282,7 +158,7 @@ def direct(hopyo: dict[str, Any]) -> dict[str, Any] | None:
|
||||
fp = empty({k: hopyo.get(k) for k in ("이름", "규격", "단위")})
|
||||
texts = [str(t) for t in hopyo.get("근거글") or []]
|
||||
texts += [f"{x.get('이름')} {x.get('규격')}" for x in lines if x.get("갈래") == "근거글"]
|
||||
fp["출처"] = hopyo_basis.sources(" ".join(texts))
|
||||
fp["출처"] = hopyo_est.sources(" ".join(texts))
|
||||
hit = False
|
||||
for x in lines:
|
||||
q = x.get("수량")
|
||||
|
||||
@@ -20,6 +20,7 @@ import hashlib
|
||||
import json
|
||||
import queue
|
||||
import threading
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -295,9 +296,21 @@ def _hp_path(folder: Path, key: str) -> Path:
|
||||
return hopyo_store._path(folder, key)
|
||||
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
def _hp_mark(path: str, stamp: tuple[int, int]) -> str:
|
||||
"""HP 지문 칸(올린 엑셀 sha256 + 읽기 판 · 776-3) — 없으면(붙여넣기) 파일 해시 · 파일이 그대로면
|
||||
(`stamp` = 바뀐 때 · 크기) 다시 안 읽음."""
|
||||
raw = Path(path).read_bytes()
|
||||
doc = json.loads(raw)
|
||||
mark = doc.get("지문") if isinstance(doc, dict) else None
|
||||
return f"{mark[:16]}{doc.get('판')}" if mark else hashlib.sha256(raw).hexdigest()[:16]
|
||||
|
||||
|
||||
def cache_path(folder: Path, key: str) -> Path:
|
||||
hp = hashlib.sha256(_hp_path(folder, key).read_bytes()).hexdigest()[:16]
|
||||
return ours.folder() / f"맞춤_{hp}_{ours.version()}_{CALC_VERSION}.json"
|
||||
hp = _hp_path(folder, key)
|
||||
got = hp.stat()
|
||||
mark = _hp_mark(str(hp), (got.st_mtime_ns, got.st_size))
|
||||
return ours.folder() / f"맞춤_{mark}_{ours.version()}_{CALC_VERSION}.json"
|
||||
|
||||
|
||||
def units(doc: dict[str, Any]) -> list[tuple[str, dict | None, dict]]:
|
||||
|
||||
@@ -343,7 +343,6 @@ def name_cands(line: dict[str, Any], got: dict[str, Any] | None = None) -> list[
|
||||
|
||||
# ── 인용 조항 · 이름 · 근거 차례(338 · 설계 2-4 B 차례) ─────────────────────
|
||||
_OLD_TEXT = re.compile(r"(20(1\d|2[0-4])|1\d년|2[0-4]년|임도품셈|임도표준품셈|사방품셈)")
|
||||
_TYPO_CLAUSE = re.compile(r"^(\d+)-(\d)(\d)(\d)$") # 13-114 → 13-11-4
|
||||
_GENERIC = frozenset(
|
||||
"인력 기계 장비 소계 합계 노무비 재료비 경비 적용 기준 별도계상 별도 인부 보통인부 특별인부 "
|
||||
"설치 해체 운반 작업 시공 사용 포함 공구손료 경장비 손료 기계경비 재료 인건비 품셈 표준품셈 "
|
||||
@@ -352,32 +351,14 @@ _GENERIC = frozenset(
|
||||
|
||||
|
||||
def fix_typo(theirs: list) -> list[list[str]]:
|
||||
"""엑셀 인용 조항 오타 — 「13-114」 → 「13-11-4」."""
|
||||
out = []
|
||||
for book, n in theirs or []:
|
||||
m = _TYPO_CLAUSE.match(str(n))
|
||||
out.append([book, f"{m.group(1)}-{m.group(2)}{m.group(3)}-{m.group(4)}" if m else n])
|
||||
return out
|
||||
"""엑셀 인용 조항 사본 — 오타(「13-114」 → 13-11-4)는 읽기(`ReadEst.sources`)가 이미 고침."""
|
||||
return [list(x) for x in theirs or []]
|
||||
|
||||
|
||||
def clause(theirs: list, our: dict[str, Any]) -> tuple[float, list[str], str]:
|
||||
"""(점수, 맞은 우리 조항 글, 꼬리표) — 같음 1 · 윗마디 0.9(엑셀 6-2 ↔ 우리 6-2-2) · 앞 마디 0.5
|
||||
·
|
||||
나 창 `Basis.clause` 가 있으면 그것."""
|
||||
if hasattr(hopyo_basis, "clause"):
|
||||
return hopyo_basis.clause(theirs, our)
|
||||
nums = [n for book, n in theirs if book == our["책"]]
|
||||
same = sorted(n for n in nums if n in our["조항"])
|
||||
if same:
|
||||
return 1.0, [f"{our['구분']} {n}" for n in same], "조항 같음"
|
||||
kids = sorted(c for c in our["조항"] for n in nums if c.startswith(n + "-"))
|
||||
if kids:
|
||||
return 0.9, [f"{our['구분']} {n}" for n in kids], "조항 같음"
|
||||
heads = {n.rsplit("-", 1)[0] for n in nums}
|
||||
near_ = sorted(n for n in our["조항"] if n.rsplit("-", 1)[0] in heads)
|
||||
if near_:
|
||||
return 0.5, [f"{our['구분']} {n}" for n in near_], "앞 마디 같음"
|
||||
return 0.0, [], ""
|
||||
"""(점수, 맞은 우리 조항 글, 꼬리표) — `M02_Hopyo_Basis.clause`(같음 1 · 윗마디 0.9 ·
|
||||
앞 마디 0.5)."""
|
||||
return hopyo_basis.clause(theirs, our)
|
||||
|
||||
|
||||
def _strong_basis(line: dict[str, Any], cand: dict[str, Any]) -> bool:
|
||||
@@ -393,9 +374,6 @@ def b_order(line: dict[str, Any], got: dict[str, Any] | None = None, text: Any =
|
||||
근거: {로직: 근거}}` — 이름 후보 + 근거 후보 합침(접힘 없음) · 「같음」도 근거 검사(인용 조항이
|
||||
다른 로직을 가리키면 후보) · 옛 판 글이면 같음 그대로 · 씨앗은 이름 같음 자리."""
|
||||
got = got or targets()
|
||||
basis_ = dict(line.get("근거") or {})
|
||||
if basis_.get("출처"):
|
||||
line = {**line, "근거": {**basis_, "출처": fix_typo(basis_["출처"])}}
|
||||
basis = hopyo_basis.candidates(line, got)
|
||||
named = candidates(line, "로직", got, None)
|
||||
merged_c = [c for c in hopyo_basis.merge(basis, named) if c.get("로직")]
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
"""M02 일위대가 맞춤 몫(PLAN 338-1 · 설계 2-2 · 2-7) — 단가산출 블록을 맨 윗 절(1. 2. 3.)
|
||||
· 작은 절(가. 나.)로 갈라 몫마다 노임(직종 → 인) · 장비(「굴착기|0.6」 → 시간) 벡터.
|
||||
|
||||
엑셀꼴 = 「직종 : 노임 × 식 = 금액」(식을 못 풀면 금액 ÷ 노임) · 장비 이름 줄 뒤 「노무비 : 단가 ÷ Q
|
||||
× 몫」 ·
|
||||
소계 · 합계 절 뺌. STmate = 자원 L · X(절 = 자원 `절` · 없으면 한 몫). 금액 안 씀.
|
||||
규칙은 336 실험(C5 `c01_trees.sections` · `sections_stm`) 그대로 · 장비 갈래는
|
||||
`M02_Hopyo_Words.mtypes`.
|
||||
"""M02 일위대가 맞춤 몫(PLAN 338-1 · 설계 2-2 · 2-7 · 776-3) — 단가산출 블록 단위 줄을 절(맨 윗 절 ·
|
||||
작은 절)마다 묶어 노임(직종 → 인) · 장비(「굴착기|0.6」 → 시간) 벡터. 형식 모름(단위 줄만 ·
|
||||
`M02_Hopyo_UnitLine`) · 셈 밖 줄 뺌 · 금액 안 씀 · 장비 갈래 = `M02_Hopyo_Words.mtypes`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import operator
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from M02_MasterTemplete import M02_Hopyo_Basis as hopyo_basis
|
||||
from M02_MasterTemplete.M02_Hopyo_ReadEst import trade # 노임 이름 → 우리 인력(B09 도 씀)
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import mtypes, nfkc
|
||||
|
||||
__all__ = ["eq_key", "sections", "trade"]
|
||||
_SIZE = re.compile(r"(\d+(?:\.\d+)?)\s*(㎥|m3|톤|ton|t\b|kw|hp)", re.I)
|
||||
_OPS = {
|
||||
ast.Mult: operator.mul,
|
||||
ast.Div: operator.truediv,
|
||||
ast.Add: operator.add,
|
||||
ast.Sub: operator.sub,
|
||||
}
|
||||
_TRADE = re.compile(
|
||||
r"^[\s*·\-○◇]*([가-힣][가-힣\s]*?)\s*:\s*([\d,]+(?:\.\d+)?)\s*(.*?)(?:=\s*([\d,]+(?:\.\d+)?))?\s*$"
|
||||
)
|
||||
_SECTION = re.compile(r"^\s*(\d+)\s*\.\s*(.*)$")
|
||||
_EQ_COST = re.compile(r"^\s*노\s*무\s*비\s*:\s*([\d,]+(?:\.\d+)?)\s*(.*?)(?:=\s*[\d,.]+)?\s*$")
|
||||
_SKIP_SEC = re.compile(r"^(합\s*계|소\s*계|계)")
|
||||
_SUBLABEL = re.compile(r"^\s*[가-하]\s*\.\s*(.*)$")
|
||||
_COSTLINE = re.compile(r"^\s*(노\s*무\s*비|재\s*료\s*비|경\s*비)\s*:")
|
||||
|
||||
|
||||
def trade(name: Any) -> str | None:
|
||||
"""노임 이름 → 우리 인력 이름(빈칸 · 옛이름 · 괄호 글 풀이) · 아니면 None."""
|
||||
names = hopyo_basis.trade_names()
|
||||
flat = re.sub(r"\s+", "", str(name or ""))
|
||||
return names.get(flat) or names.get(re.sub(r"\(.*?\)", "", flat))
|
||||
|
||||
|
||||
def eq_key(text: Any) -> str | None:
|
||||
@@ -54,124 +27,23 @@ def eq_key(text: Any) -> str | None:
|
||||
return f"{'+'.join(sorted(kinds))}|{size}"
|
||||
|
||||
|
||||
def _eval(node: ast.AST) -> float:
|
||||
if isinstance(node, ast.Expression):
|
||||
return _eval(node.body)
|
||||
if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)):
|
||||
return float(node.value)
|
||||
if isinstance(node, ast.BinOp) and type(node.op) in _OPS:
|
||||
return _OPS[type(node.op)](_eval(node.left), _eval(node.right))
|
||||
if isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.USub):
|
||||
return -_eval(node.operand)
|
||||
raise ValueError("식 아님")
|
||||
|
||||
|
||||
def qty_of(expr: str) -> float | None:
|
||||
"""「273,540 × 3인 ÷ 55㎥ × 2」 → 3/55×2 · 「59,020 ÷ 23.1 × 90%」 → 1/23.1×0.9."""
|
||||
s = re.sub(r"\([^()0-9]*\)", "", str(expr)).replace(",", "")
|
||||
s = re.sub(r"(\d+(?:\.\d+)?)\s*%", r"(\1/100)", s)
|
||||
s = s.replace("×", "*").replace("÷", "/").replace("X", "*").replace("x", "*")
|
||||
s = re.sub(r"/\s*(?=[^\d(\s.])", " ", s) # 「인/㎥」 의 / 는 단위
|
||||
s = re.sub(r"[^\d.+\-*/() ]", " ", s)
|
||||
s = re.sub(r"(?<=\d)\.(?!\d)", "", s) # 「4.」 → 4
|
||||
s = re.sub(r"\(\s*\)", " ", s).strip()
|
||||
m = re.match(r"\s*\d+(?:\.\d+)?", s)
|
||||
if not m:
|
||||
return None
|
||||
s = "1" + s[m.end() :]
|
||||
s = re.sub(r"(?<=[\d)])\s+(?=[\d(])", "*", s) # 빈칸으로 붙은 수는 곱
|
||||
try:
|
||||
v = _eval(ast.parse(s, mode="eval"))
|
||||
except (SyntaxError, ValueError, ZeroDivisionError):
|
||||
return None
|
||||
return v if 0 < v < 1e4 else None
|
||||
|
||||
|
||||
def _part(title: str, parent: str) -> dict[str, Any]:
|
||||
return {"제목": title, "절": parent, "노임": {}, "장비": {}}
|
||||
|
||||
|
||||
def sections(texts: list[str]) -> list[dict[str, Any]]:
|
||||
"""블록 몸 글 → 몫마다 {제목, 절, 노임, 장비} — 노임 · 장비가 하나도 없는 몫은 뺌."""
|
||||
out: list[dict[str, Any]] = []
|
||||
cur: dict[str, Any] | None = None
|
||||
eq, parent = None, ""
|
||||
for raw in texts:
|
||||
line = str(raw).rstrip()
|
||||
sec = _SECTION.match(line)
|
||||
if sec and not re.match(r"^\s*\d+\.\d", line):
|
||||
title = sec.group(2).strip()
|
||||
if _SKIP_SEC.match(title.replace(" ", "")):
|
||||
cur = None
|
||||
continue
|
||||
parent = title
|
||||
cur = _part(title, title)
|
||||
out.append(cur)
|
||||
eq = eq_key(title)
|
||||
def sections(units: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""블록 단위 줄(`M02_Hopyo_UnitLine`) → 몫마다 {제목 = 줄 절, 절 = 윗절, 노임, 장비} — 셈 밖 ·
|
||||
매개값 없는 줄 뺌 · 장비 = 시간 50 아래 · 노임 · 장비가 하나도 없는 몫은 뺌."""
|
||||
out: dict[str, dict[str, Any]] = {}
|
||||
for one in units:
|
||||
q, kind = one.get("품"), one.get("묶음")
|
||||
if one.get("밖") or not q or kind not in ("L", "X"):
|
||||
continue
|
||||
sub = _SUBLABEL.match(line) if cur is not None else None
|
||||
if sub and not _SKIP_SEC.match(sub.group(1).replace(" ", "")):
|
||||
cur = _part(f"{parent} · {sub.group(1).strip()}", parent)
|
||||
out.append(cur)
|
||||
if cur is None:
|
||||
if out or not line.strip():
|
||||
continue
|
||||
cur = _part("", "")
|
||||
out.append(cur)
|
||||
if re.search(r"(소계|합계|인부소계)", line.replace(" ", "")):
|
||||
eq = None
|
||||
continue
|
||||
sub = _SUBLABEL.match(line)
|
||||
if sub:
|
||||
eq = eq_key(sub.group(1))
|
||||
elif not _COSTLINE.match(line) and (k := eq_key(line)):
|
||||
eq = k
|
||||
m = _EQ_COST.match(line)
|
||||
if m and eq:
|
||||
q = qty_of(f"{m.group(1)} {m.group(2)}")
|
||||
if q and q < 50:
|
||||
cur["장비"][eq] = cur["장비"].get(eq, 0) + q
|
||||
continue
|
||||
t = _TRADE.match(line)
|
||||
if t and (who := trade(t.group(1))):
|
||||
q = qty_of(f"{t.group(2)} {t.group(3)}")
|
||||
if q is None and t.group(4): # 식을 못 풀면 금액 ÷ 노임(품 되찾기만)
|
||||
q = float(t.group(4).replace(",", "")) / float(t.group(2).replace(",", ""))
|
||||
if q:
|
||||
cur["노임"][who] = cur["노임"].get(who, 0) + q
|
||||
return [s for s in out if s["노임"] or s["장비"]]
|
||||
|
||||
|
||||
def sections_stm(res: list[dict[str, Any]], texts: list[str]) -> list[dict[str, Any]]:
|
||||
"""STmate 자원(L · X) → 몫(자원 `절` = 글 줄 차례면 그 앞 맨 윗 절 · 글이면 그 제목 · 없으면 한
|
||||
몫)."""
|
||||
marks = []
|
||||
for at, t in enumerate(texts):
|
||||
sec = _SECTION.match(t)
|
||||
if sec and not re.match(r"^\s*\d+\.\d", t):
|
||||
if not _SKIP_SEC.match(sec.group(2).replace(" ", "")):
|
||||
marks.append((at, sec.group(2).strip()))
|
||||
|
||||
def which(where: Any) -> str:
|
||||
if isinstance(where, str):
|
||||
return where
|
||||
if isinstance(where, int) and not isinstance(where, bool):
|
||||
got = [m for m in marks if m[0] <= where]
|
||||
return got[-1][1] if got else ""
|
||||
return ""
|
||||
|
||||
secs: dict[str, dict[str, Any]] = {}
|
||||
seen = set()
|
||||
for x in res:
|
||||
q, kind = x.get("품"), x.get("갈래")
|
||||
if not q or kind not in ("L", "X") or (x.get("코드"), q, x.get("절")) in seen:
|
||||
continue
|
||||
seen.add((x.get("코드"), q, x.get("절")))
|
||||
title = which(x.get("절"))
|
||||
s = secs.setdefault(title, _part(title, title))
|
||||
if kind == "L" and (who := trade(x.get("이름"))):
|
||||
s["노임"][who] = s["노임"].get(who, 0) + float(q)
|
||||
elif kind == "X":
|
||||
k = eq_key(f"{x.get('이름') or ''} {x.get('규격') or ''}") or f"?{x.get('코드')}"
|
||||
s["장비"][k] = s["장비"].get(k, 0) + float(q)
|
||||
return [s for s in secs.values() if s["노임"] or s["장비"]]
|
||||
title = str(one.get("절") or "")
|
||||
part = out.setdefault(title, _part(title, str(one.get("윗절") or title)))
|
||||
if kind == "L" and (who := one.get("직종") or trade(one.get("이름"))):
|
||||
part["노임"][who] = part["노임"].get(who, 0) + float(q)
|
||||
elif kind == "X" and q < 50:
|
||||
k = eq_key(f"{one.get('이름') or ''} {one.get('규격') or ''}") or f"?{one.get('코드')}"
|
||||
part["장비"][k] = part["장비"].get(k, 0) + float(q)
|
||||
return [p for p in out.values() if p["노임"] or p["장비"]]
|
||||
|
||||
Reference in New Issue
Block a user