feat(ТСН): НР/СП из сборника .8 — разбор, хранение и начисление от ФОТ

План T8 требовал НР/СП по видам работ; до сих пор их не было вовсе.
- tsn_parse: разбор таблицы .8 (номер, название с переносами и подпунктами,
  два процента справа); на настоящем сборнике 58 видов работ.
- build_tsn_ref: таблица nr_sp, схема 3; отчёт считает nr_sp.
- ext_pull: разбор .8 идёт через parse_nr_sp.
- tsn_ref.find_nr_sp: поиск нормы по виду работ с провенансом.
- tsn_calc.calc_position(work_type=…): НР и СП от текущей заработной платы (ОТ),
  итог = ПЗ + НР + СП; без вида работ или без ставки — nr_sp_incomplete, итог без
  НР/СП (прямые затраты), не «0» и не выдуманное число.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
anor
2026-11-18 04:39:56 +10:00
co-authored by Claude Code
parent 6381e2625f
commit 3764b67064
8 changed files with 232 additions and 6 deletions
+55
View File
@@ -378,6 +378,61 @@ def _unit_of_tokens(tokens: list[str]) -> str:
return unit[:-1] + "." if unit.endswith(",") else unit
NR_NUM_X = 400 # в таблице .8 проценты стоят справа от x=400
def _nr_sp_items(lines: list, page: int = 0) -> list[dict]:
"""Строки таблицы НР/СП: номер позиции, название (может переноситься), два процента.
Заголовки групп без процентов позиции не дают, но их текст прилипает к следующей
названной строке — так «Комплекс работ по монтажу конструкций крупнопанельных /
жилых домов» не теряется.
"""
items: list[dict] = []
pending, group, group_no = "", "", ""
for line in lines:
words = sorted(line)
if not words:
continue
num = words[0][2] if words[0][0] < 90 else ""
is_number = bool(re.match(r"^\d+(?:\.\d+)*\.$", num))
text = " ".join(w for x, _, w in words if 90 <= x < NR_NUM_X)
nums = [w for x, _, w in words if x >= NR_NUM_X]
if is_number and not nums:
group, group_no, pending = text, num.rstrip("."), text
continue
if is_number:
# подпункт «1.01.» наследует название группы «1. Земляные работы, выполняемые:»
prefix = group if group_no and num.startswith(group_no + ".") else ""
pending = f"{prefix} {text}".strip() if prefix else text
elif text and not nums:
pending = (pending + " " + text).strip()
if group_no:
group = (group + " " + text).strip()
if len(nums) >= 2 and pending:
over = _num(nums[0])
prof = _num(nums[1])
if over is not None and prof is not None:
items.append({"work_type": pending, "overhead": over, "profit": prof,
"page": page})
pending = ""
return items
def parse_nr_sp(path: str, meta: dict | None = None) -> dict:
"""Сборник ТСН-2001.8: нормы накладных расходов и сметной прибыли по видам работ."""
meta = meta or {}
items: list[dict] = []
pages_total = 0
with fitz.open(path) as doc:
pages_total = doc.page_count
for pno in range(pages_total):
items.extend(_nr_sp_items(_lines(doc[pno].get_text("words")), page=pno + 1))
return {"items": items, "book": meta.get("book") or "ТСН-2001.8",
"stats": {"pages_total": pages_total, "items_parsed": len(items)},
"file": meta.get("file")}
def parse_price_book(path: str, meta: dict | None = None) -> dict:
"""Сметные цены ресурсов из справочника .1 (материалы) или .2 (машины).