Files
smeta-railway/src/smeta_railway/calc/coefficients.py
T
anorandClaude Opus 4.6 897d2d1b76 refactor: декомпозиция монолита в пакет smeta-railway
- Пакетная структура 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>
2026-03-20 18:42:19 +10:00

147 lines
4.4 KiB
Python

"""
Complication coefficients for railway capital repair.
Technical part GESN-2022, Collection 28 "Zheleznye dorogi".
Parameterized via ProjectConfig — coefficient values and exclusion rules
come from YAML, not hardcoded.
"""
from smeta_railway.config import CoefficientConfig, CoefficientDef
from smeta_railway.models import Coefficients
# Default coefficient definitions (can be overridden via YAML)
DEFAULT_COEFFICIENTS: list[dict] = [
{
"key": "dvizhenie",
"code": "2022-13-ГЭСН-ПР-28-01-1.1.8-000",
"name": ("Выполнение работ в условиях движения поездов "
"для участков с размерами движения 91-108 поездов/сут"),
"value": 1.60,
"apply_zt": True,
"apply_em": True,
"apply_ztm": True,
},
{
"key": "vl",
"code": "2022-13-ГЭСН-ПР-28-01-1.2-000",
"name": ("Производство работ вблизи объектов, "
"находящихся под высоким напряжением"),
"value": 1.20,
"apply_zt": False,
"apply_em": True,
"apply_ztm": True,
},
{
"key": "okno",
"code": "2022-13-ГЭСН-ПР-28-01-1.3.1-000",
"name": ("Производство работ с прекращением движения "
'поездов по перегону (в «окно»)'),
"value": 1.81,
"apply_zt": False,
"apply_em": True,
"apply_ztm": True,
},
]
DEFAULT_EXCLUDE_NORMS: dict[str, list[str]] = {
"okno": [
"28-01-155-", # replacement of fastenings (manual work)
"28-01-043-", # rail cutting (manual machine)
"28-01-044-", # insulating joints (manual)
],
}
def get_default_config() -> CoefficientConfig:
"""Build default CoefficientConfig."""
defs = [CoefficientDef(**d) for d in DEFAULT_COEFFICIENTS]
return CoefficientConfig(
definitions=defs,
exclude_norms=DEFAULT_EXCLUDE_NORMS,
)
def get_coefficients(
gesn_code: str,
config: CoefficientConfig | None = None,
) -> Coefficients:
"""
Compute resulting coefficients for a GESN norm.
Args:
gesn_code: full code like "ГЭСН 28-01-037-02"
config: coefficient config from YAML (uses defaults if None)
Returns:
Coefficients dataclass with zt, em, ztm, applied list, formulas
"""
if config is None:
config = get_default_config()
code = gesn_code.replace("ГЭСН ", "").strip()
# Only apply coefficients to collection 28 norms
if not code.startswith("28-01-"):
return Coefficients(
formulas={"zt": "", "em": "", "ztm": ""},
)
zt = 1.0
em = 1.0
ztm = 1.0
applied: list[str] = []
parts_zt: list[str] = []
parts_em: list[str] = []
parts_ztm: list[str] = []
for cdef in config.definitions:
# Check exclusion rules for this coefficient
excluded_prefixes = config.exclude_norms.get(cdef.key, [])
if any(code.startswith(p) for p in excluded_prefixes):
continue
# Apply coefficient
if cdef.apply_zt:
zt *= cdef.value
parts_zt.append(f"{cdef.value:.2f}")
if cdef.apply_em:
em *= cdef.value
parts_em.append(f"{cdef.value:.2f}")
if cdef.apply_ztm:
ztm *= cdef.value
parts_ztm.append(f"{cdef.value:.2f}")
applied.append(cdef.key)
def formula(parts: list[str], result: float) -> str:
if len(parts) == 0:
return ""
if len(parts) == 1:
return parts[0]
return "*".join(parts) + f"={result:.4f}"
return Coefficients(
zt=round(zt, 4),
em=round(em, 4),
ztm=round(ztm, 4),
applied=applied,
formulas={
"zt": formula(parts_zt, zt),
"em": formula(parts_em, em),
"ztm": formula(parts_ztm, ztm),
},
)
# Backward-compatible accessors for coefficient codes/names
def get_coeff_codes(config: CoefficientConfig | None = None) -> dict[str, str]:
if config is None:
config = get_default_config()
return {d.key: d.code for d in config.definitions}
def get_coeff_names(config: CoefficientConfig | None = None) -> dict[str, str]:
if config is None:
config = get_default_config()
return {d.key: d.name for d in config.definitions}