35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
from app.ml.explanation import explain_feature
|
|
from app.ml.training import FeatureModel
|
|
|
|
|
|
def _model(slope: float) -> FeatureModel:
|
|
return FeatureModel(
|
|
sample_count=4,
|
|
mean=20.0,
|
|
standard_deviation=1.0,
|
|
minimum=18.0,
|
|
maximum=22.0,
|
|
slope=slope,
|
|
intercept=18.5,
|
|
)
|
|
|
|
|
|
def test_explain_feature_describes_rising_forecast() -> None:
|
|
explanation = explain_feature("temperature", 21.0, 21.5, _model(0.5))
|
|
|
|
assert explanation.direction == "steigend"
|
|
assert explanation.change == 0.5
|
|
assert explanation.historical_range == (18.0, 22.0)
|
|
assert "4 Messwerte" in explanation.summary
|
|
assert "Trend +0.500" in explanation.summary
|
|
|
|
|
|
def test_explain_feature_describes_stable_and_falling_forecasts() -> None:
|
|
stable = explain_feature("humidity", 50.0, 50.0, _model(0.0))
|
|
falling = explain_feature("temperature", 21.0, 20.5, _model(-0.5))
|
|
|
|
assert stable.direction == "stabil"
|
|
assert falling.direction == "fallend"
|