feat(857-2): 둘 꼴에 일위대가 불러오기 몫 칸 더함 — EST 일위대가 시트 · 블록 머리 · 칸 나눔 글 · STmate 칸줄

- EST 「일위대가」 · 「일위대가총괄표」 시트 읽기 = `M02_San_Xlsx_Ilwi.est`(칸 그대로 · 갈래 · 검산은 호표 쪽) → 둘 꼴 `일위대가`
- EST 산근 블록 `머리`(머리 글) · `머리돈`(머리 줄 수 칸) · 줄 `칸글`(글자 칸 나눔 꼴을 칸마다 빈칸 하나로) · pack 이 `엑셀행` 도 실음
- STmate 산근 블록 `칸줄`(머리 ~ 다음 머리 앞 값 든 칸 A~N · X) · `줄합` 실음 · 둘 꼴 `일위대가` = 일위대가표 공용 읽기 답 통째(숨은 칸 없어도)
- 있던 칸의 이름 · 뜻 그대로 — 실무 엑셀 11 둘 꼴 옛 칸 전부 같음 · 호표 읽기 그대로(아직 안 읽음 · 다음 커밋)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 23:32:59 +09:00
co-authored by Claude Opus 5.5
parent c0daf9663b
commit 8e21ea4037
4 changed files with 148 additions and 8 deletions
+8 -2
View File
@@ -22,7 +22,7 @@ from M02_MasterTemplete import M02_San_Emit as em
EXT = (".estx", ".stc")
RULE = {"0": "합버림_큰나머지"} # STmate SAN_TYP — 그 밖 = 비목버림
_EST_KEYS = ("행", "글", "보임", "품명", "단", "색인", "연결", "비목", "자원", "연결단가", "변수")
_EST_KEYS += ("줄참조", "결과", "합계", "저장")
_EST_KEYS += ("줄참조", "결과", "합계", "저장", "칸글")
_RES_KEYS = ("코드", "종류", "이름", "규격", "단위")
@@ -47,7 +47,8 @@ def read(name: str, data: bytes) -> dict[str, Any]:
def pack(got: dict, name: str) -> dict[str, Any]:
"""파서 답 → 둘 꼴(셈 · 변환에 쓰는 칸만 · JSON)."""
"""파서 답 → 둘 꼴(셈 · 변환에 쓰는 칸만 · JSON) · 엑셀 = 일위대가 불러오기(`M02_Hopyo_Excel.read_book`)가
읽는 칸도(857-2 — EST 줄 `칸글` · 블록 `엑셀행 머리 머리돈` / STmate 블록 `칸줄 줄합` / `일위대가`)."""
out: dict[str, Any] = {"꼴": got["꼴"], "파일": name, "표지": got.get("표지") or []}
out |= {"엑셀": True} if got.get("엑셀") else {} # 812-1 엑셀 읽기기(`M02_San_Xlsx`) — 같은 꼴
out |= (
@@ -58,7 +59,12 @@ def pack(got: dict, name: str) -> dict[str, Any]:
"엑셀"
): # 엑셀 읽기기 — 줄 행 = 시트 행(원문 카드 · 옛 엑셀 길과 같은 자리) · 블록 표지
head += ("표지", "몸", "꼬리")
head += ("엑셀행", "머리", "머리돈", "칸줄", "줄합") # 857-2 일위대가 불러오기 몫
got = {**got, "산근": [_rows(b) for b in got["산근"]]}
if (
"일위대가" in got
): # 857-2 엑셀 「일위대가」 · 「일위대가표」 시트 읽기 답(일위대가 불러오기 몫)
out["일위대가"] = got["일위대가"]
if got["꼴"] == "EST":
out["산근"] = [
{**{k: b.get(k) for k in head if k in b}, "줄": [_est_line(ln) for ln in b["줄"]]}
+20 -3
View File
@@ -55,7 +55,9 @@ def _span(text: str, name: str, start: int = 0) -> tuple[int, int] | None:
# ── 시트 → 블록 ───────────────────────────────────────────────────────
def blocks(rows: list[list[Any]]) -> list[dict[str, Any]]:
"""단가산출 시트 → [{번, 머리, 행, 저장, 줄 [{행, 엑셀행, 보임, 돈}]}](머리 = B 열 「N.이름[단위]」)."""
"""단가산출 시트 → [{번, 머리, 행, 저장, 머리돈, 줄 [{행, 엑셀행, 보임, 돈, 칸글?}]}](머리 = B 열 「N.이름[단위]」 ·
머리돈 = 머리 줄 수 칸 그대로 {계 노무비 재료비 경비} · 칸글 = 글자 칸 나눔 줄의 칸 글을 빈칸 하나로 이음
— 일위대가 불러오기 `M02_Hopyo_ReadEst.from_two` 가 읽음 · 857-2)."""
cols = sx.money_cols(rows) or [2, 3, 4, 5]
split = cols[0] > 6 # 거창 꼴 — 글자 칸 나눔(열 = 화면 자리 · B 열 = 머리만)
out: list[dict[str, Any]] = []
@@ -65,6 +67,11 @@ def blocks(rows: list[list[Any]]) -> list[dict[str, Any]]:
if m and i > 2:
out.append({"번": int(m.group(1)), "머리": head, "행": i + 1, "줄": []})
out[-1]["저장"] = sx.money_of(r, cols)
out[-1]["머리돈"] = {
k: r[j]
for k, j in zip(("계", "노무비", "재료비", "경비"), cols)
if j < len(r) and isinstance(r[j], (int, float)) and not isinstance(r[j], bool)
}
continue
if not out:
continue
@@ -74,6 +81,8 @@ def blocks(rows: list[list[Any]]) -> list[dict[str, Any]]:
else:
text = sx._cell(head)
one = {"행": len(out[-1]["줄"]) + 1, "엑셀행": i + 1, "보임": text, "칸": split}
if split:
one["칸글"] = " ".join(v.strip() for _, v in cells if v.strip())
out[-1]["줄"].append(one | {"돈": sx.money_of(r, cols)})
for b in out: # 끝 빈 줄(시트 꼬리)
while b["줄"] and not b["줄"][-1]["보임"].strip() and not b["줄"][-1]["돈"]:
@@ -147,6 +156,7 @@ class Lines:
"추정": False,
"_marks": [],
"_칸": src.get("칸"),
**({"칸글": src["칸글"]} if src.get("칸글") else {}),
}
def resource(self, kind: str, one: dict) -> dict[str, Any]:
@@ -622,7 +632,8 @@ def index(res: dict[str, list[dict]]) -> dict[str, Any]:
def read(sheets: dict[str, list]) -> dict[str, Any]:
"""EST 엑셀 시트 → {꼴, 산근, 일위, 자원, 내역, 표지}(`M02_San_Estx.read` 꼴 · 일위 = 호표 길)."""
"""EST 엑셀 시트 → {꼴, 산근, 일위, 자원, 내역, 표지, 일위대가}(`M02_San_Estx.read` 꼴 · 일위 = 호표 길 ·
일위대가 = 「일위대가」 시트 그대로 `M02_San_Xlsx_Ilwi.est` · 857-2)."""
res = sx.resources(sheets)
look = index(res)
total = {one["번"]: one for one in res.get("산근") or []}
@@ -653,13 +664,19 @@ def read(sheets: dict[str, list]) -> dict[str, Any]:
ln.pop("_칸", None)
ln["글"] = _glyph(ln["보임"], marks)
lines.append(ln)
out["산근"].append({**head, "번": b["번"], "엑셀행": b["행"], "줄": lines, "표지": tags})
more = {"머리": b["머리"], "머리돈": b["머리돈"]} # 일위대가 불러오기 몫(857-2)
out["산근"].append(
{**head, "번": b["번"], "엑셀행": b["행"], "줄": lines, "표지": tags} | more
)
out["자원"] = {
f"{kind}:{one['번']}": {k: one[k] for k in ("이름", "규격", "단위", "표")}
| {"저장": one["값"]}
for kind, rows in res.items()
for one in rows
}
from M02_MasterTemplete import M02_San_Xlsx_Ilwi as ilwi
out["일위대가"] = ilwi.est(sheets)
out["표지"] = [
f"{sx.NOTE}자원 코드 · LinkIndex · 자리(Diget) 없음 — 연결뜻 = 글 · 금액 칸 · 단가표로 정함({sx.GUESS})",
f"{sx.NOTE}자원 코드 = 단가표 이름#No(산근 = 단산 번)",
+94
View File
@@ -2,6 +2,7 @@
읽는 곳 하나 — 일위대가 불러오기(`M02_Hopyo_Stmate.read`) · 단가산출 불러오기
(`M02_San_Xlsx_Stmate.read` 「일위」) · 재료 단서(`M02_San_MatFind.from_book`).
EST 「일위대가」 · 「일위대가총괄표」 = `est`(857-2 · 칸 그대로 → 둘 꼴 `일위대가` · 갈래 · 검산 = 일위대가 불러오기).
호표 = A 「제N호표」 줄(숨은 칸 `BDCOD|B…`) → 다음 줄 이름 · 규격 · 단위 → 구성 줄 → 「합계」 · 「계」.
구성 줄 = 숨은 칸 기준(표시대로 · 글 짐작 안 함 · 원파일 구성표 BDQTY 와 같은 칸) —
N 열 메타 `COD|M00131 ␅ EXI DVD BMK IPR KWN BLA EQC PRI PRO UNI TPR` · O 열 차수 꼬리 `M00131_1`.
@@ -184,3 +185,96 @@ def blocks(sheet: dict[str, Any]) -> list[dict[str, Any]]:
| {"엑셀행": h["행"][0], "줄": h["줄"], "줄합": None, "표지": []}
for h in sheet["호표"]
]
# ── EST 「일위대가」 시트(857-2 · 일위대가 불러오기 `M02_Hopyo_Excel.read_book` 이 이 답을 받음) ──
EST_SHEET, EST_SUMMARY = "일위대가", "일위대가총괄표"
EST_HEADS = ("호표", "품명", "규격", "수량", "단위", "비고")
EST_MONEY = ("합계", "노무비", "재료비", "경비")
def _flat(v: Any) -> str:
return re.sub(r"\s+", "", str(v or ""))
def _at(row: list[Any], col: int | None) -> Any:
return row[col] if col is not None and col < len(row) else None
def _raw(v: Any) -> Any:
"""칸 값 그대로(JSON 꼴 · 날짜 등 = 글) — 수 풀이는 받는 쪽."""
return v if v is None or isinstance(v, (int, float, str, bool)) else str(v)
def columns(rows: list[list[Any]], money: tuple[str, ...]) -> tuple[int, dict[str, int]]:
"""(자료 첫 줄, {머리: 열}) — 머리 글은 앞 10 줄 안 「호표」 · 「품명」 이 든 줄 · 없음 = BookError."""
from M02_MasterTemplete.M02_San_Workbook import BookError
for at, row in enumerate(rows[:10]):
flat = [_flat(v) for v in row]
if "호표" not in flat or "품명" not in flat:
continue
cols = {head: flat.index(head) for head in (*EST_HEADS, *money) if head in flat}
below = [_flat(v) for v in rows[at + 1]] if at + 1 < len(rows) else []
start = at + 2 if "단가" in below or "금액" in below else at + 1
return start, cols
raise BookError(f"{EST_SHEET} 시트 머리 글(호표 · 품명)을 못 찾음")
def _money_raw(row: list[Any], cols: dict[str, int], offset: int) -> dict[str, Any]:
"""비목 넷(합계 = 계) 칸 그대로 — `offset` 0 = 단가 열 · 1 = 금액 열."""
return {
("계" if head == "합계" else head): _raw(_at(row, None if c is None else c + offset))
for head in EST_MONEY
for c in [cols.get(head)]
}
def _totals(rows: list[list[Any]] | None) -> list[list[Any]]:
"""총괄표 [[호표 번, 합계 칸]] — 머리 글이 없으면 빈 것."""
from M02_MasterTemplete.M02_San_Workbook import BookError
if not rows:
return []
try:
start, cols = columns(rows, ("합계",))
except BookError:
return []
out = []
for row in rows[start:]:
if hit := _HOPYO.fullmatch(_flat(_at(row, cols.get("호표")))):
out.append([int(hit.group(1)), _raw(_at(row, cols.get("합계")))])
return out
def est(sheets: dict[str, list]) -> dict[str, Any] | None:
"""EST 「일위대가」 · 「일위대가총괄표」 → {호표 [{번, 이름, 규격, 단위, 금액, 행 [처음, 끝], 줄 [{행, 이름,
규격, 수량, 단위, 단가, 금액, 비고}]}], 총괄표 [[번, 합계]]}(수 = 칸 그대로 · 갈래 · 이음 · 검산 =
`M02_Hopyo_Excel`) · 시트 없음 = None · 머리 글 없음 = {오류}.
호표 줄 = 「제N호표」 · 구성 줄 = 호표 칸 빔 · 품명 있음 · 끝 = 다음 호표."""
from M02_MasterTemplete.M02_San_Workbook import BookError
rows = sheets.get(EST_SHEET)
if rows is None:
return None
try:
start, cols = columns(rows, EST_MONEY)
except BookError as error:
return {"오류": str(error)}
text = lambda row, head: _s(_at(row, cols.get(head))) # noqa: E731
hopyos: list[dict[str, Any]] = []
for at, row in enumerate(rows[start:], start + 1):
head, name = _flat(_at(row, cols.get("호표"))), text(row, "품명")
if hit := _HOPYO.fullmatch(head):
one = {"번": int(hit.group(1)), "이름": name, "규격": text(row, "규격")}
one |= {"단위": text(row, "단위"), "금액": _money_raw(row, cols, 1), "행": [at, at]}
hopyos.append(one | {"줄": []})
continue
if head or not name or not hopyos:
continue
line = {"행": at, "이름": name, "규격": text(row, "규격")}
line |= {"수량": _raw(_at(row, cols.get("수량"))), "단위": text(row, "단위")}
line |= {"단가": _money_raw(row, cols, 0), "금액": _money_raw(row, cols, 1)}
hopyos[-1]["줄"].append(line | {"비고": text(row, "비고")})
hopyos[-1]["행"][1] = at
return {"호표": hopyos, "총괄표": _totals(sheets.get(EST_SUMMARY))}
+26 -3
View File
@@ -17,6 +17,22 @@ from M02_MasterTemplete import M02_San_Stc as stc
from M02_MasterTemplete import M02_San_Xlsx as sx
RULE = {"비목버림": "1", "합버림_큰나머지": "0"} # 끝전 갈래 → SAN_TYP
#: 일위대가 불러오기가 읽는 칸(857-2 · `M02_Hopyo_Stmate.from_two`) — A 끝 · B 글 · C~F 금액 · G 식 · H 품 ·
#: I~L 단가 · M 자원 · N 셈 밖 · X 「이름 / 규격」
CELLS = {k: ord(k) - 65 for k in "ABCDEFGHIJKLMNX"}
def cells(rows: list[list], start: int, end: int) -> list[dict[str, Any]]:
"""블록 머리 줄 ~ 다음 머리 앞 칸(값 든 칸만 · 그대로 · 빈 줄 뺌) → [{행, A.. X}]."""
from M02_MasterTemplete.M02_San_Xlsx_Ilwi import _raw
out = []
for rn in range(start, end):
r = rows[rn - 1]
one = {k: _raw(r[i]) for k, i in CELLS.items() if i < len(r) and r[i] not in (None, "")}
if one:
out.append({"행": rn, **one})
return out
def _amt(head: dict) -> dict[str, float]:
@@ -41,8 +57,9 @@ def vote(blocks: list[dict], prices: dict) -> tuple[str, dict[str, int]]:
def read(sheets: dict[str, list]) -> dict[str, Any]:
"""STmate 엑셀 시트 → {꼴, 산근, 일위, 자원, 내역, 단가, 옵션, 표지} · 일위 = 일위대가표 숨은 칸
구성 줄(828-2 `M02_San_Xlsx_Ilwi` · 숨은 칸 없으면 빈 목록 + 표지)."""
"""STmate 엑셀 시트 → {꼴, 산근, 일위, 자원, 내역, 단가, 옵션, 표지, 일위대가} · 일위 = 일위대가표 숨은 칸
구성 줄(828-2 `M02_San_Xlsx_Ilwi` · 숨은 칸 없으면 빈 목록 + 표지) · 일위대가 = 같은 시트 읽기 답 통째 ·
산근 블록 `칸줄` = 머리 ~ 다음 머리 앞 칸(일위대가 불러오기 몫 · 857-2)."""
found = book.stmate_prices(sheets)
prices = {c: {k: p.get(k) for k in ("T", "L", "M", "S", "meta")} for c, p in found.items()}
res = {
@@ -51,7 +68,9 @@ def read(sheets: dict[str, list]) -> dict[str, Any]:
for c, p in found.items()
}
out: dict[str, Any] = {"꼴": "STmate", "산근": [], "일위": [], "자원": res, "단가": prices}
for blk in book.stmate_blocks(sheets):
blocks, rows = book.stmate_blocks(sheets), sheets.get("단가산출근거") or []
ends = [b["행"] for b in blocks[1:]] + [len(rows) + 1]
for blk, end in zip(blocks, ends, strict=True):
tags: list[str] = []
lines = [stc.stc_line(i, ln["G"], res, tags) for i, ln in enumerate(blk["몸"], 1)]
for one, src in zip(lines, blk["몸"]):
@@ -66,6 +85,7 @@ def read(sheets: dict[str, list]) -> dict[str, Any]:
| {
"몸": body,
"꼬리": blk["꼬리"],
"칸줄": cells(rows, blk["행"], end), # 일위대가 불러오기 몫(857-2)
} # 엑셀 줄 금액 · 계 꼬리(검산 · `M02_San_Emit.stmate`)
)
rule, got = vote(out["산근"], prices)
@@ -76,6 +96,9 @@ def read(sheets: dict[str, list]) -> dict[str, Any]:
sheet = ilwi.read(sheets.get(ilwi.SHEET)) # 828-2 일위대가표 숨은 칸 → 구성 줄(읽는 곳 하나)
out["일위"] = ilwi.blocks(sheet)
out["일위대가"] = (
sheet # 857-2 일위대가 불러오기(`M02_Hopyo_Stmate.read`) — 숨은 칸 없어도 호표 · 줄
)
out["단서"] = mf.from_book(sheet) # 827-2 재료 단서
out["표지"] = [
f"{sx.NOTE}일위대가 구성 = 일위대가표 숨은 칸 · 내역은 안 읽음"