26 lines
788 B
Python
26 lines
788 B
Python
"""Линейная интерполяция (аналог FRAC в методичке)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def frac(numerator: float, denominator: float) -> float:
|
|
if denominator == 0:
|
|
return 0.0
|
|
return numerator / denominator
|
|
|
|
|
|
def lerp(x: float, x1: float, n1: float, x2: float, n2: float) -> float:
|
|
"""Norma = n1 + frac(n2 - n1, x2 - x1) * (x - x1)."""
|
|
if x2 == x1:
|
|
return n1
|
|
return n1 + frac(n2 - n1, x2 - x1) * (x - x1)
|
|
|
|
|
|
def popr_index(udoy: float, boundaries: list[float]) -> int:
|
|
"""1-based индекс столбца POPR_K по суточному удою."""
|
|
idx = 1
|
|
for i, bound in enumerate(boundaries, start=1):
|
|
if udoy >= bound:
|
|
idx = i + 1
|
|
return min(idx, len(boundaries) + 1)
|