refactor(857-5): 호표 쪽 옛 가름 본체 걷음 — 시트를 직접 가르던 ReadEst.read · Stmate._blocks · Excel._columns · _summary
- 857-2 뒤 호표 계보는 둘 꼴 위에서 읽음(from_two) — 옛 본체 부르는 곳 0(저장소 전체 · 옛 조사 스크립트 docs 만) - 딸린 것: ReadEst `_columns` · `_cell_text` · `WIDE` · `_MONEY` · Stmate `_HEAD_D` · `_HEAD_B` · `_COLS` · Excel `HEADS` - B09 `Bill_Excel` 이 쓰는 `Hopyo_Excel._money` · `_HOPYO` 는 남김 - 시험 test_778_3 STmate 합성 줄 = 같은 줄을 칸줄로 싸서 from_two 로(판정 그대로) - 머리 글의 옛 이름(UnitLine · San_Book · Excel) 고침 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,7 @@ STmate 꼴(「일위대가표」 · 「단가산출근거」 시트) = `M02_Hopy
|
||||
% 줄 = floor(바탕 × 율 / 100 × 10) / 10 · 호표 비목 = floor(줄 금액 합) · 총괄표 합계 —
|
||||
어긋남은 글 목록(막지 않음).
|
||||
행(329-1) = 호표 [제N호표 줄, 마지막 구성 줄] · 구성 줄 한 줄(엑셀 1부터) ·
|
||||
근거(330-1) = 단산N참조 줄에 「단가산출」 블록 `{출처, 직종, 행}`(`M02_Hopyo_ReadEst.read`) ·
|
||||
근거(330-1) = 단산N참조 줄에 「단가산출」 블록 `{출처, 직종, 행}`(`M02_Hopyo_ReadEst.from_two`) ·
|
||||
`단산` = 블록마다 `{번, 이름, 단위, 행, 출처, 직종, 글, 금액, 항목}`(338 · 글 = 머리 뺀 몸 줄) ·
|
||||
`꼴` = 「엑셀꼴」 · 두 형식 끝에 `UnitLine.settle`(단위 줄 하위 · 재현 · 덮음 · 일위대가 줄
|
||||
투영 · 778-3).
|
||||
@@ -40,7 +40,6 @@ SHEET = "일위대가"
|
||||
SUMMARY = "일위대가총괄표"
|
||||
LISTS = ("단가산출총괄표", "일위대가목록표") # 엑셀 보기 목록 시트(779-1 격자) — 같이 읽음
|
||||
COSTS = ("노무비", "재료비", "경비")
|
||||
HEADS = ("호표", "품명", "규격", "수량", "단위", "비고")
|
||||
NO_SHEET = "일위대가 시트 없음"
|
||||
_HOPYO = re.compile(r"제\s*(\d+)\s*호표")
|
||||
_REF = re.compile(r"^(?:(단산|산근|단가산출)|(일위대가|일위|대가))(\d+)(?:참조|호표)?$")
|
||||
@@ -88,19 +87,6 @@ def _out(value: Decimal | None) -> int | float | None:
|
||||
return int(value) if value == value.to_integral_value() else float(value)
|
||||
|
||||
|
||||
def _columns(rows: list[list[Any]], money: tuple[str, ...]) -> tuple[int, dict[str, int]]:
|
||||
"""(자료 첫 줄, {머리: 열}) — 머리 글은 앞 10 줄 안 「호표」 · 「품명」 이 든 줄."""
|
||||
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 (*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 ExcelError(f"{SHEET} 시트 머리 글(호표 · 품명)을 못 찾음")
|
||||
|
||||
|
||||
def _cell(row: list[Any], col: int | None) -> Any:
|
||||
return row[col] if col is not None and col < len(row) else None
|
||||
|
||||
@@ -200,23 +186,6 @@ def _check_hopyo(hopyo: dict[str, Any], lines: list[dict[str, Any]]) -> list[str
|
||||
return bad
|
||||
|
||||
|
||||
def _summary(rows: list[list[Any]] | None) -> dict[int, Decimal]:
|
||||
"""총괄표 {호표 번: 합계} — 머리 글이 없으면 빈 것."""
|
||||
if not rows:
|
||||
return {}
|
||||
try:
|
||||
start, cols = _columns(rows, ("합계",))
|
||||
except ExcelError:
|
||||
return {}
|
||||
out = {}
|
||||
for row in rows[start:]:
|
||||
hit = _HOPYO.fullmatch(_flat(_cell(row, cols.get("호표"))))
|
||||
total = _num(_cell(row, cols.get("합계")))
|
||||
if hit and total is not None:
|
||||
out[int(hit.group(1))] = total
|
||||
return out
|
||||
|
||||
|
||||
def _by_name(raw: list[list[dict[str, Any]]], blocks: dict[int, dict[str, Any]]) -> None:
|
||||
"""비고 빈 줄(노무비 · 경비 단가 있음) → 품명 + 단위가 같은 블록이 하나뿐이면 단산 이음."""
|
||||
index: dict[tuple[str, str], list[int]] = {}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
"""M02 일위대가 실무자료 EST(엑셀꼴) 단가산출 어댑터(PLAN 776-2 · 요구 621-1 ② 정규화) —
|
||||
엑셀 「단가산출」 시트 → 블록 `{번, 이름, 단위, 행, 출처, 직종, 글, 금액, 항목}`.
|
||||
둘 꼴 EST 산근 블록(`from_two` · 857-2) → 블록 `{번, 이름, 단위, 행, 출처, 직종, 글, 금액, 항목}`.
|
||||
형식(EST 글)을 아는 곳은 여기까지.
|
||||
|
||||
블록 = B열(머리 「산출근거」) 머리 줄 「N.이름[단위]」(앞 빈칸 없음)부터 다음 머리 앞까지 ·
|
||||
블록 = 머리 「N.이름[단위]」부터 다음 머리 앞까지 ·
|
||||
출처 = 「…품셈」(오타 「품줌」) 뒤 20 글자 안 절 번호 — 책 = 앞 낱말(`book_of` · 781-1: 산림 ·
|
||||
임도(옛) · 사방(옛) · 건설 부문 · 그 밖 건설품셈(부문 모름)) ·
|
||||
부문 풀이 · 옛 번호 대응 = `M02_Hopyo_Clause.settle` ·
|
||||
직종 = 「이름 : 수」 줄의 빈칸 뺀 이름이 우리 인력(LB) 이름 · 옛이름일 때만(지금 이름으로) ·
|
||||
글 = 머리 뺀 몸 줄 `GLINES` 줄 · 줄마다 `GCHARS` 자 안 · 산출근거 열이 빈 줄은 그 오른쪽 ~ 돈 머리
|
||||
(맨 오른쪽 묶음) 앞 칸을 빈칸으로 이어 붙임(거창 꼴 · 돈 머리 없으면 `WIDE` 열) ·
|
||||
글 = 머리 뺀 몸 줄 `GLINES` 줄 · 줄마다 `GCHARS` 자 안 ·
|
||||
금액 = 머리 줄 돈 칸(1 단위).
|
||||
항목(Book 블록 항목 · 778-3) = 글 줄 → 단위 줄(꼴 = `M02_Hopyo_UnitLine`) · 줄 금액 = 「= 금액」 ·
|
||||
끝 점(「28,500. ×」) 뗌 · 율(호표 줄 이름 · 규격)에 기대지 않는 것만(섞음 율은 지문 몫):
|
||||
@@ -34,7 +33,7 @@ from M02_MasterTemplete import M02_Labor_Inputs as labor_inputs
|
||||
from M02_MasterTemplete.M02_Hopyo_Words import mtypes, parse_rhs
|
||||
|
||||
SHEET = "단가산출"
|
||||
GLINES, GCHARS, WIDE = 200, 300, 140
|
||||
GLINES, GCHARS = 200, 300
|
||||
_HEAD = re.compile(r"^(\d+)\.\s*(.*?)\s*\[([^\[\]]*)\]\s*$")
|
||||
_BOOK = re.compile(r"품[셈줌]")
|
||||
_TRADE = re.compile(r"^[\s*·\-]*([가-힣][가-힣\s]*?)\s*:\s*[\d,]")
|
||||
@@ -46,7 +45,6 @@ _BOOK_WORDS = { # 책 낱말(781-1) — 옛 책 = 「(옛)」 · 건설 부문
|
||||
}
|
||||
_BOOK_WORD = re.compile(r"(" + "|".join(_BOOK_WORDS) + r")\s*(?:부문|사업|공사)?\s*(?:표준)?\s*$")
|
||||
_TYPO_CLAUSE = re.compile(r"^(\d+)-(\d)(\d)(\d)$") # 「13-114」 = 13-11-4
|
||||
_MONEY = {"합계": "계", "노무비": "노무비", "재료비": "재료비", "경비": "경비"}
|
||||
# 항목 풀이 — 지문(`Finger`)과 같은 규칙
|
||||
COST = ("노무비", "재료비", "경비")
|
||||
SKIPW = frozenset(
|
||||
@@ -88,12 +86,6 @@ def _flat(value: Any) -> str:
|
||||
return re.sub(r"\s+", "", str(value or ""))
|
||||
|
||||
|
||||
def _cell_text(value: Any) -> str:
|
||||
if isinstance(value, float) and value == int(value):
|
||||
value = int(value)
|
||||
return str(value).strip() if value is not None else ""
|
||||
|
||||
|
||||
# ── 이름 · 출처(두 어댑터 · 뒤 단계 공용) ────────────────────────────────
|
||||
@lru_cache(maxsize=2)
|
||||
def _trade_names(whole_id: int) -> dict[str, str]:
|
||||
@@ -156,66 +148,6 @@ def rates_in(text: Any) -> set[float]:
|
||||
return out
|
||||
|
||||
|
||||
# ── 블록 읽기 ─────────────────────────────────────────────────────────
|
||||
def _columns(rows: list[list[Any]]) -> tuple[int, int, dict[str, int]]:
|
||||
"""(자료 첫 줄, 산출근거 열, {계 · 노무비 · 재료비 · 경비: 열}) — 머리 없으면 (0, 1, {}) ·
|
||||
돈 머리가 둘 묶음이면 맨 오른쪽(거창 꼴 · 값이 든 쪽)."""
|
||||
for at, row in enumerate(rows[:10]):
|
||||
flat = [_flat(v) for v in row]
|
||||
if "산출근거" in flat:
|
||||
last = len(flat) - 1
|
||||
money = {
|
||||
key: last - flat[::-1].index(head) for head, key in _MONEY.items() if head in flat
|
||||
}
|
||||
return at + 1, flat.index("산출근거"), money
|
||||
return 0, 1, {}
|
||||
|
||||
|
||||
def read(rows: list[list[Any]] | None) -> dict[int, dict[str, Any]]:
|
||||
"""단가산출 시트 줄 → `{N: {번, 이름, 단위, 행: [시작, 끝], 출처, 직종, 글, 글행, 금액, 항목,
|
||||
절}}`(행 = 엑셀 1부터 · 글행 = 글 줄마다 행 · 절 = `M02_Hopyo_Formula.tree`)."""
|
||||
if not rows:
|
||||
return {}
|
||||
start, col, money = _columns(rows)
|
||||
end = min(money.values()) if money and min(money.values()) > col + 1 else WIDE
|
||||
names = trade_names()
|
||||
blocks: dict[int, dict[str, Any]] = {}
|
||||
block: dict[str, Any] | None = None
|
||||
for at, row in enumerate(rows[start:], start + 1):
|
||||
text = row[col] if col < len(row) else None
|
||||
head = None
|
||||
if isinstance(text, str) and text.strip():
|
||||
head = None if text[:1].isspace() else _HEAD.match(text)
|
||||
else:
|
||||
text = " ".join(_cell_text(v) for v in row[col + 1 : end] if _cell_text(v))
|
||||
if not text:
|
||||
continue
|
||||
if head:
|
||||
block = blocks.setdefault(
|
||||
int(head.group(1)),
|
||||
{
|
||||
"번": int(head.group(1)),
|
||||
"이름": head.group(2),
|
||||
"단위": head.group(3).strip(),
|
||||
"행": [at, at],
|
||||
"출처": [],
|
||||
"직종": [],
|
||||
"글": [],
|
||||
"금액": {
|
||||
key: v
|
||||
for key, c in money.items()
|
||||
for v in [row[c] if c < len(row) else None]
|
||||
if isinstance(v, (int, float)) and not isinstance(v, bool)
|
||||
},
|
||||
"_글행": [],
|
||||
},
|
||||
)
|
||||
continue
|
||||
if block is not None:
|
||||
_take(block, at, text, names)
|
||||
return _finish(blocks)
|
||||
|
||||
|
||||
def _take(block: dict[str, Any], at: int, text: str, names: dict[str, str]) -> None:
|
||||
"""몸 줄 하나 → 블록 끝 행 · 글(`GLINES` 줄 · 줄마다 `GCHARS` 자) · 출처 · 직종."""
|
||||
block["행"][1] = at
|
||||
|
||||
@@ -40,13 +40,10 @@ LISTS = ("단가산출근거목록표", "노무비목록표", "중기목록표",
|
||||
SHEETS = (SHEET, CALC, *LISTS)
|
||||
_CODE = ilwi.CODE
|
||||
_META = re.compile(r"(?<![A-Z])COD\|([A-Z]{1,2}\d{5})") # 숨은 칸 「`COD|L00001」
|
||||
_HEAD_B = re.compile(r"BDCOD\|(B\d{5})")
|
||||
_HEAD_D = re.compile(r"BDCOD\|(D\d{5})")
|
||||
_RES = re.compile(r"^([LMXS])(\d{5})_\d+$")
|
||||
_RES_A = re.compile(r"^([LMXS]\d{5})[LMS]$") # A 열 「L00002L」
|
||||
_RES_G = re.compile(r"&([LMXS]\d{5})[LMS]&") # G 열 식 「&L00002L&」
|
||||
_SECTION = re.compile(r"^\s*(?:\d+\s*[.)]|[①-⑩])\s*(.*\S)")
|
||||
_COLS = {"합계": 4, "노무비": 6, "재료비": 8, "경비": 10}
|
||||
_CALC_AMOUNT = {"합계": 2, "노무비": 3, "재료비": 4, "경비": 5} # 단가산출근거 C~F 금액
|
||||
_CALC_PRICE = {"합계": 8, "노무비": 9, "재료비": 10, "경비": 11} # I~L 단가(T · L · M · S)
|
||||
NOTE, CODE_COLS, RES_COL, QTY_COL, NAME_COL = 12, range(12, 26), 12, 7, 23
|
||||
@@ -293,27 +290,9 @@ def _finish(out: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
|
||||
return out
|
||||
|
||||
|
||||
def _blocks(rows: list[list[Any]], table: dict[str, dict[str, str]]) -> dict[str, dict[str, Any]]:
|
||||
"""{D 코드: {번, 코드, 이름, 규격, 단위, 행, 출처, 직종, 글, 자원, 금액, 항목}}."""
|
||||
out: dict[str, dict[str, Any]] = {}
|
||||
block: dict[str, Any] | None = None
|
||||
state = {"절": "", "라벨": ""} # 절 제목 · 율 행 위 라벨 줄(코드 · 금액 없는 글)
|
||||
for at, row in enumerate(rows, 1):
|
||||
head = next(
|
||||
(hit for v in row[:8] if (hit := _HEAD_D.search(_s(v)))), None
|
||||
) # 머리 = G 열(판마다 B 열 글이 다름)
|
||||
if head:
|
||||
block = out.setdefault(head.group(1), _new(head.group(1), at, row, table))
|
||||
state = {"절": "", "라벨": ""}
|
||||
continue
|
||||
if block is not None and not _take(block, at, row, table, state):
|
||||
block = None
|
||||
return _finish(out)
|
||||
|
||||
|
||||
def from_two(blocks: list[dict[str, Any]], table: dict[str, dict[str, str]]) -> dict[str, Any]:
|
||||
"""둘 꼴 STmate 산근 블록 `칸줄`(머리 ~ 다음 머리 앞 칸 · `M02_San_Xlsx_Stmate.cells` · 857-2) →
|
||||
`_blocks` 와 같은 블록 — 시트를 다시 가르지 않음 · D 코드 블록만."""
|
||||
블록 — 시트를 다시 가르지 않음 · D 코드 블록만."""
|
||||
out: dict[str, dict[str, Any]] = {}
|
||||
for b in blocks:
|
||||
code = str(b.get("코드") or "")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""M02 일위대가 실무자료 단위 줄(PLAN 778-3 · D-1 · 요구 622) — 단가산출 블록 · 일위대가 줄을 같은
|
||||
「세부항목 계산 단위」 꼴로 · 자체 검산. 형식(EST · STmate)을 모름 — 읽기 어댑터
|
||||
(`M02_Hopyo_ReadEst.items` · `M02_Hopyo_Stmate._blocks`)가 블록 `항목` 을 단위 줄로 냄.
|
||||
(`M02_Hopyo_ReadEst.items` · `M02_Hopyo_Stmate.from_two`)가 블록 `항목` 을 단위 줄로 냄.
|
||||
|
||||
단위 줄 = `{묶음, 이름, 규격, 단위, 품, 밑품, 율, 인자, 계수, 단가, 금액, 밖, 기준, 기준값,
|
||||
하위, 할증, 재현, 직종, 절, 절율, 코드, 어떻게, 행}`:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
STmate(.xlsx) = 단가산출근거 시트 G 열 「BDCOD|D…」 머리 · POSS~POSE 몸(숨은 G 열 원문) ·
|
||||
꼬리(계 · 계약단가 · 총계) + 목록표 단가(노무비 · 재료비 · 경비 = E 열 · 숨은 G 열 `COD` ·
|
||||
중기 · 단가산출근거 = E~H 열 계 · 노 · 재 · 경 · 숨은 J 열 메타).
|
||||
EST(.xls · .xlsx) = 단가산출 시트 블록 글(`M02_Hopyo_ReadEst.read`) + 노임단가 ·
|
||||
EST(.xls · .xlsx) = 단가산출 시트 블록 글 + 노임단가 ·
|
||||
자재단가(적용단가) · 기계경비총괄표 · 견적단가 · 단가산출총괄표(적용 칸 · 합이 안 맞으면 당초 칸).
|
||||
"""
|
||||
|
||||
|
||||
@@ -118,7 +118,8 @@ def test_STmate_같은_코드_두_묶음_따로_계수_율_밖():
|
||||
), # fmt: skip
|
||||
_row(c0="총계"),
|
||||
]
|
||||
blocks = st._blocks(rows, {})
|
||||
lines = [{"행": at, **{chr(65 + c): v for c, v in enumerate(r) if v is not None}} for at, r in enumerate(rows, 1)] # fmt: skip
|
||||
blocks = st.from_two([{"코드": "D00001", "칸줄": lines}], {})
|
||||
units = blocks["D00001"]["항목"]
|
||||
xs = [u for u in units if u["묶음"] == "X"]
|
||||
assert [x["품"] for x in xs] == [0.1, 0.2] # 두 묶음 따로(단가 두 배 아님)
|
||||
|
||||
Reference in New Issue
Block a user