File size: 1,024 Bytes
aec7019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from app.models.forecaster import FlowForecaster


def test_material_balance_inflow():
    fc = FlowForecaster(wet_well_area=20.0)
    # 液位不变 → 入流≈出流
    fc.update(0.0, 3.0, 300.0)
    q_in = fc.update(1.0, 3.0, 300.0)
    assert abs(q_in - 300.0) < 1.0
    # 液位上升 → 入流 > 出流
    q_in2 = fc.update(2.0, 3.01, 300.0)
    assert q_in2 > 300.0


def test_linear_trend_prediction():
    fc = FlowForecaster(wet_well_area=20.0, window=100)
    # 构造液位平稳、出流线性上升的场景
    level = 3.0
    for t in range(60):
        fc.update(float(t), level, 200.0 + t * 2.0)
    pred = fc.predict(horizon_s=10.0)
    assert pred is not None
    # 上升趋势应外推出高于当前均值的值
    assert pred > fc.current_avg()


def test_falls_back_to_mean_when_insufficient():
    fc = FlowForecaster()
    assert fc.predict() is None or fc.predict() == 0.0
    fc.update(0.0, 3.0, 250.0)
    fc.update(1.0, 3.0, 250.0)
    assert abs(fc.predict() - fc.current_avg()) < 1e-6