- Пакетная структура src/smeta_railway/ с модулями calc/, data/, output/ - Pydantic-конфиг: всё через YAML, сметчик не трогает Python - EstimateCalculator: ядро расчёта, параметризованные коэффициенты - FGISLookup: pickle cache (4.7с → ~50мс при повторном запуске) - CLI: smeta generate/fetch-resources/validate (typer) - 28 тестов (coefficients, overhead, fgis, estimate) - Исправлен баг: НР/СП для земляных работ (92%/46% вместо 109%/65%) - ПЗ совпадают бит-в-бит со старым генератором Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
196 lines
5.8 KiB
Python
196 lines
5.8 KiB
Python
"""Tests for EstimateCalculator."""
|
|
|
|
import pytest
|
|
|
|
from smeta_railway.calc.estimate import EstimateCalculator
|
|
from smeta_railway.config import Section, Subsection, WorkItem
|
|
from smeta_railway.data.fgis import FGISLookup
|
|
from smeta_railway.models import (
|
|
LaborResource,
|
|
MachineResource,
|
|
MaterialResource,
|
|
NormResources,
|
|
)
|
|
|
|
|
|
def _make_fgis() -> FGISLookup:
|
|
"""Create a minimal FGIS lookup for testing."""
|
|
return FGISLookup(
|
|
index_map={
|
|
"91.09.03-031": 1.64,
|
|
"91.09.05-023": 1.64,
|
|
},
|
|
base_price_map={
|
|
"91.09.03-031": 3771.54,
|
|
"91.09.05-023": 2200.0,
|
|
},
|
|
current_price_map={},
|
|
labor_price_map={
|
|
"1-100-31": 550.0,
|
|
"4-100-060": 700.0,
|
|
},
|
|
)
|
|
|
|
|
|
def _make_resources() -> dict[str, NormResources]:
|
|
"""Create minimal resources for testing."""
|
|
return {
|
|
"28-01-031-01": NormResources(
|
|
norm_code="28-01-031-01",
|
|
norm_name="Выправка пути ВПО",
|
|
unit="км",
|
|
ozp=LaborResource(razryad=3.1, chel_hours=20.0),
|
|
machines=[
|
|
MachineResource(
|
|
code="91.09.03-031",
|
|
name="Платформы моторные",
|
|
unit="маш.-ч",
|
|
qty=5.0,
|
|
cost_base=3771.54,
|
|
razryad_mash=6.0,
|
|
),
|
|
],
|
|
materials=[],
|
|
),
|
|
}
|
|
|
|
|
|
class TestEstimateCalculator:
|
|
def test_single_gesn_position(self):
|
|
"""Test calculation of a single GESN position."""
|
|
fgis = _make_fgis()
|
|
resources = _make_resources()
|
|
calc = EstimateCalculator(fgis, resources)
|
|
|
|
sections = [
|
|
Section(
|
|
name="Test",
|
|
subsections=[
|
|
Subsection(items=[
|
|
WorkItem(
|
|
code="ГЭСН 28-01-031-01",
|
|
name="Выправка пути",
|
|
unit="км",
|
|
qty=2.0,
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
]
|
|
|
|
result = calc.calculate(sections)
|
|
assert len(result.positions) == 1
|
|
|
|
pos = result.positions[0]
|
|
assert pos.gesn_code == "ГЭСН 28-01-031-01"
|
|
assert pos.qty == 2.0
|
|
assert pos.ot_cost > 0
|
|
assert pos.em_cost > 0
|
|
assert pos.pz > 0
|
|
assert pos.nr > 0
|
|
assert pos.sp > 0
|
|
assert pos.total > pos.pz
|
|
|
|
def test_transport_position(self):
|
|
"""Test transport position calculation."""
|
|
fgis = FGISLookup()
|
|
calc = EstimateCalculator(fgis, {})
|
|
|
|
sections = [
|
|
Section(
|
|
name="Transport",
|
|
subsections=[
|
|
Subsection(items=[
|
|
WorkItem(
|
|
code="ФССЦпг 236019-00-0071-0080",
|
|
name="Перевозка щебня",
|
|
unit="1 т груза",
|
|
qty=100,
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
]
|
|
|
|
result = calc.calculate(sections)
|
|
assert len(result.positions) == 1
|
|
pos = result.positions[0]
|
|
assert pos.is_transport
|
|
assert pos.transport_cost == pytest.approx(100 * 815.96, rel=1e-3)
|
|
|
|
def test_kp_position(self):
|
|
"""Test commercial proposal position."""
|
|
fgis = FGISLookup()
|
|
calc = EstimateCalculator(fgis, {})
|
|
|
|
sections = [
|
|
Section(
|
|
name="KP",
|
|
subsections=[
|
|
Subsection(items=[
|
|
WorkItem(
|
|
code="КП РСП-19",
|
|
name="Сварка на РСП",
|
|
unit="стык",
|
|
qty=10,
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
]
|
|
|
|
result = calc.calculate(sections)
|
|
pos = result.positions[0]
|
|
assert pos.is_kp
|
|
assert pos.pz == pytest.approx(10 * 8129.21, rel=1e-3)
|
|
|
|
def test_material_position_skipped(self):
|
|
"""Material positions have zero costs."""
|
|
fgis = FGISLookup()
|
|
calc = EstimateCalculator(fgis, {})
|
|
|
|
sections = [
|
|
Section(
|
|
name="Mat",
|
|
subsections=[
|
|
Subsection(items=[
|
|
WorkItem(
|
|
code="Материал",
|
|
name="Шпала Ш1",
|
|
unit="шт.",
|
|
qty=44,
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
]
|
|
|
|
result = calc.calculate(sections)
|
|
pos = result.positions[0]
|
|
assert pos.is_material
|
|
assert pos.pz == 0
|
|
|
|
def test_grand_totals_accumulate(self):
|
|
"""Grand totals should accumulate across positions."""
|
|
fgis = FGISLookup()
|
|
calc = EstimateCalculator(fgis, {})
|
|
|
|
sections = [
|
|
Section(
|
|
name="Transport",
|
|
subsections=[
|
|
Subsection(items=[
|
|
WorkItem(code="ФССЦпг 236019-00-0071-0080",
|
|
name="A", unit="т", qty=100),
|
|
WorkItem(code="ФССЦпг 236019-00-0001-0005",
|
|
name="B", unit="т", qty=200),
|
|
]),
|
|
],
|
|
),
|
|
]
|
|
|
|
result = calc.calculate(sections)
|
|
expected = 100 * 815.96 + 200 * 731.17
|
|
assert result.grand_transport == pytest.approx(expected, rel=1e-3)
|
|
assert result.grand_pz == pytest.approx(expected, rel=1e-3)
|