feat(срез 4.1): strict-режим движка (fail-loud вместо тихих нулей)

EstimateCalculator(strict=False): нет ресурса/цены материала/машины/труда/перевозки/КП →
result.missing + result.ok=False + position.unresolved, а не молчаливый 0. Fable-чек закрыл
дыры: труд 545.28 (проверка кода разряда в labor_price_map), транспорт/КП→0. strict=False —
прежнее поведение (29 railway-тестов зелёные, числа не изменились). Остаточные дыры (балласт-
хардкод, cost_base-как-текущая, ozp=None) — известные ограничения, следующий срез.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-17 21:20:24 +10:00
co-authored by Claude Opus 4.8
parent f72378351c
commit 01b8cf760b
2 changed files with 31 additions and 1 deletions
+27 -1
View File
@@ -44,16 +44,22 @@ class EstimateCalculator:
coeff_config: CoefficientConfig | None = None,
overhead_config: OverheadConfig | None = None,
limited_costs_config: LimitedCostsConfig | None = None,
strict: bool = False,
):
self.fgis = fgis
self.resources = resources
self.coeff_config = coeff_config
self.overhead_config = overhead_config
self.limited_costs_config = limited_costs_config or LimitedCostsConfig()
# strict (срез 4.1): нет ресурса/цены → в result.missing + result.ok=False,
# а не тихий ноль (иначе смета «посчитается» с дырами и занизит итог).
self.strict = strict
self._missing: list = []
def calculate(self, sections: list[Section]) -> EstimateResult:
"""Calculate entire estimate from sections list."""
result = EstimateResult()
self._missing = []
for section in sections:
for subsection in section.subsections:
@@ -104,6 +110,8 @@ class EstimateCalculator:
smr + result.temp_buildings + result.winter_cost + result.contingency, 2
)
result.missing = self._missing
result.ok = not self._missing
return result
def _calc_position(self, item: WorkItem) -> PositionResult | None:
@@ -133,6 +141,8 @@ class EstimateCalculator:
"""Calculate transport position."""
price_key = item.code.replace("ФССЦпг ", "ФССЦпг-").strip()
price_data = TRANSPORT_PRICES.get(price_key)
if price_data is None and self.strict:
self._missing.append({"code": item.code, "reason": "цена перевозки (ФССЦпг) не найдена"})
current_price = price_data[2] if price_data else 0.0
total_cost = round(item.qty * current_price, 2)
@@ -140,18 +150,22 @@ class EstimateCalculator:
gesn_code=item.code, name=item.name, unit=item.unit,
qty=item.qty, pz=total_cost, total=total_cost,
transport_cost=total_cost, is_transport=True,
unresolved=(price_data is None),
)
def _calc_kp(self, item: WorkItem) -> PositionResult:
"""Calculate commercial proposal position."""
price_key = item.code.replace("КП ", "КП-").strip()
price_data = KP_PRICES.get(price_key)
if price_data is None and self.strict:
self._missing.append({"code": item.code, "reason": "цена по КП не найдена"})
current_price = price_data[2] if price_data else 0.0
total_cost = round(item.qty * current_price, 2)
return PositionResult(
gesn_code=item.code, name=item.name, unit=item.unit,
qty=item.qty, pz=total_cost, total=total_cost, is_kp=True,
unresolved=(price_data is None),
)
def _calc_gesn(self, item: WorkItem) -> PositionResult:
@@ -161,9 +175,11 @@ class EstimateCalculator:
res = self.resources.get(code_key)
if not res:
if self.strict:
self._missing.append({"code": item.code, "reason": "нет ресурсного состава в resources.json"})
return PositionResult(
gesn_code=item.code, name=item.name,
unit=item.unit, qty=qty,
unit=item.unit, qty=qty, unresolved=True,
)
coeffs = get_coefficients(item.code, self.coeff_config)
@@ -178,6 +194,9 @@ class EstimateCalculator:
razryad = res.ozp.razryad
chel_hours = res.ozp.chel_hours
labor_price = get_labor_current_price(self.fgis, razryad)
if self.strict and get_labor_code(razryad, "1-100-") not in self.fgis.labor_price_map:
self._missing.append({"code": f"труд р.{razryad}",
"reason": f"цена труда рабочих не найдена (позиция {item.code})"})
total_zt_hours = round(chel_hours * qty * k_zt, 7)
ot_cost = round(total_zt_hours * labor_price, 2)
@@ -199,6 +218,8 @@ class EstimateCalculator:
m_current = m.cost_base
else:
m_current = 0
if self.strict:
self._missing.append({"code": m.code, "reason": f"цена машины не найдена (в позиции {item.code})"})
total_m_qty = round(m.qty * qty * k_em, 7)
m_cost = round(total_m_qty * m_current, 2)
@@ -209,6 +230,9 @@ class EstimateCalculator:
mach_price = get_labor_current_price(
self.fgis, m.razryad_mash, is_machinist=True
)
if self.strict and get_labor_code(m.razryad_mash, "4-100-") not in self.fgis.labor_price_map:
self._missing.append({"code": f"труд маш.р.{m.razryad_mash}",
"reason": f"цена труда машинистов не найдена (позиция {item.code})"})
mach_cost = round(mach_hours * mach_price, 2)
otm_total_hours += mach_hours
otm_total_cost += mach_cost
@@ -232,6 +256,8 @@ class EstimateCalculator:
mat_current = mat.cost_base
else:
mat_current = 0
if self.strict:
self._missing.append({"code": mat.code, "reason": f"цена материала не найдена (в позиции {item.code})"})
total_mat_qty = round(mat.qty * qty, 7)
mat_cost = round(total_mat_qty * mat_current, 2)
+4
View File
@@ -71,6 +71,7 @@ class PositionResult:
is_transport: bool = False
is_kp: bool = False
is_material: bool = False
unresolved: bool = False # strict: позиция не рассчитана (нет ресурса/цены) — не выдавать как готовую
@dataclass
@@ -97,3 +98,6 @@ class EstimateResult:
contingency: float = 0.0 # Резерв на непредвиденные
contingency_pct: float = 0.0
grand_total_with_limits: float = 0.0 # Итого с лимитированными
# strict-режим (срез 4.1): fail-loud вместо тихих нулей.
missing: list = field(default_factory=list) # [{code, reason}] — что не рассчиталось
ok: bool = True # False → в смете есть нерассчитанные позиции