diff --git a/B09_Estimation/B09_Estimation_ResourceAxis_Transposed.py b/B09_Estimation/B09_Estimation_ResourceAxis_Transposed.py index 79b87bf4..d8595726 100644 --- a/B09_Estimation/B09_Estimation_ResourceAxis_Transposed.py +++ b/B09_Estimation/B09_Estimation_ResourceAxis_Transposed.py @@ -46,6 +46,8 @@ def _normalize_label(text: str) -> str: #: 「계」 열 — **가공 + 조립을 이미 더한 값**이다. 같이 읽으면 두 번 센다(㉤ 열 방향). _SUM_GROUP_LABELS = ("계", "합계", "소계", "총계") +#: 갈래 이름에 적힌 제 밑수 — 「대형헬기 (400ha당)」. +_RE_VARIANT_BASIS = re.compile(r"\(\s*(\d[\d,]*(?:\.\d+)?)\s*(?:ha|㏊|㎡|㎥|m|본|개소)\s*당\s*\)") def _sum_group_positions(headers: list, resource_count: int) -> set: @@ -143,6 +145,7 @@ def _match_two_row_table( unit: str, ordinal: list, skip_rows: int, + basis_quantity: Decimal | None = None, ) -> bool: """2단 표 — **숫자 칸을 순서대로** 자원에 맞춘다. @@ -180,9 +183,15 @@ def _match_two_row_table( ) ) continue + # ⚠ 밑수로 나눔 — 갈래 이름이 「(400ha당)」 처럼 제 밑수를 적으면 그것으로(8-6-1 유인헬기가 + # 160배·400배 부풀어 있던 자리 · 2026-09-15). 표 밑수가 한 벌뿐이라 갈래 밑수를 못 가르던 병. + found = _RE_VARIANT_BASIS.search(variant) + divisor = Decimal(found.group(1).replace(",", "")) if found else basis_quantity for (order, entry, blocked), amount in zip(ordinal, numbers): if blocked: continue # 「계」 묶음 — 이미 더한 값이다 + if divisor not in (None, 0, Decimal(1)): + amount = amount / divisor result.rows.append( ResourceRow( work_item_code=work_item_code, @@ -497,7 +506,9 @@ def match_transposed_table( # 자원 이름이 **둘째 줄**에 오는 2단 표일 수 있다. ordinal, skip_rows = second_row_columns(table, catalog) if ordinal: - return _match_two_row_table(node, table, catalog, result, unit, ordinal, skip_rows) + return _match_two_row_table( + node, table, catalog, result, unit, ordinal, skip_rows, basis_quantity + ) if not columns: return False diff --git a/resources/tester/test_b09_variant_basis.py b/resources/tester/test_b09_variant_basis.py new file mode 100644 index 00000000..836db1b4 --- /dev/null +++ b/resources/tester/test_b09_variant_basis.py @@ -0,0 +1,40 @@ +"""갈래마다 밑수가 다른 표 — 2026-09-15 브레인(헬기 착수 전 바로잡기). + +8-6-1 유인헬기방제 표(F0225)는 「소형헬기 (160ha당)」·「대형헬기 (400ha당)」 갈래마다 밑수가 다른데, +2단 머리 표 읽기(`_match_two_row_table`)가 **밑수로 아예 안 나눠** 제목 단위 「ha」 에 160ha·400ha 몫이 +그대로 앉아 있었음(160배·400배 부풂). 표 밑수가 한 벌(160ha)로만 잡혀 대형 400ha 도 못 가름. +⇒ 갈래 이름의 「(N단위당)」 이 있으면 그 밑수로, 없으면 표 밑수로 나눔. +그 길을 지나는 표 다섯 중 밑수가 1 이 아닌 표는 8-6-1 하나 · 갈래마다 밑수가 다른 표도 전체에서 8-6-1 하나. +""" + +from __future__ import annotations + +from decimal import Decimal + +from B09_Estimation.B09_Estimation_UnitPrice import cached_build + + +def _labor(book, title: str) -> dict[str, Decimal]: + return { + book.titles[r.ref_code].name: r.quantity + for r in book.details[title] + if r.ref_code in ("1002", "1003") + } + + +def test_유인헬기_인력은_갈래_밑수로_나눈_ha당() -> None: + book = cached_build().book + small = _labor(book, "B-FP-08-06-01#소형헬기(160ha당)") + assert ( + small["특별인부"] == Decimal("0.8") / 160 and small["보통인부"] == Decimal("8.2") / 160 + ), small + large = _labor(book, "B-FP-08-06-01#대형헬기(400ha당)") + assert ( + large["특별인부"] == Decimal("2.1") / 400 and large["보통인부"] == Decimal("13.4") / 400 + ), large + + +def test_밑수_1_인_2단_표는_그대로() -> None: + book = cached_build().book + rows = [r for t in book.titles if t.startswith("B-FP-12-03#") for r in book.details[t]] + assert rows and all(r.quantity < 20 for r in rows) # 철근 가공·조립 ton당 — 나누기 전과 같음