File size: 2,156 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from app.plant import Plant

# 海斯特站规模:单泵铭牌 Q≈850 m³/h @50Hz,5 台(三用二备)


def test_optimize_meets_target_and_saves_energy():
    plant = Plant()
    Q_target = 700.0
    res = plant.optimizer.optimize(Q_target=Q_target)
    assert res["success"]
    # 变频泵可 trim 到接近目标(软约束)
    assert abs(res["wp"]["Q_total"] - Q_target) < 150
    # 相对全泵 50Hz 基线应节能
    base = plant.baseline_all_on_50hz(Q_target)
    assert res["spec_energy"] <= base.spec_energy + 1e-6


def test_freqs_within_bounds():
    plant = Plant()
    res = plant.optimizer.optimize(Q_target=1200.0)
    for f in res["freqs"].values():
        assert 20.0 - 1e-6 <= f <= 50.0 + 1e-6


def test_start_stop_penalty_prefers_continuity():
    plant = Plant()
    # 当前 1、2 号在运,需求恰好 2 泵满足,应保持不乱切
    res = plant.optimizer.optimize(
        Q_target=1350.0, current_active=[1, 2],
        current_freqs={1: 50.0, 2: 50.0},
    )
    assert res["success"]
    # 真实厂家曲线下1号泵较小;当前1+2无法达到1350,允许切换为可行组合。
    assert abs(res["wp"]["Q_total"] - 1350.0) <= max(50.0, 1350.0 * 0.03)
    assert res["wp"]["feasible"]


def test_rotation_prefers_least_run_hours():
    plant = Plant()
    # 低需求单泵场景:变频泵(1/2/5)中累计运行 h 最少的 5# 应被优先
    res = plant.optimizer.optimize(
        Q_target=700.0,
        run_hours={1: 9000.0, 2: 9000.0, 3: 9000.0, 4: 9000.0, 5: 100.0},
    )
    assert res["success"]
    if len(res["active"]) == 1:
        assert res["active"][0] == 5


def test_higher_demand_more_pumps():
    plant = Plant()
    low = plant.optimizer.optimize(Q_target=700.0)
    high = plant.optimizer.optimize(Q_target=1700.0)
    assert high["success"]
    assert len(high["active"]) >= len(low["active"])
    assert len(high["active"]) >= 3        # 大需求需多台


def test_infeasible_target_is_not_recommended():
    plant = Plant()
    res = plant.optimizer.optimize(Q_target=10000.0, level=5.5)
    assert not res["success"]
    assert res["status"] == "infeasible_target"