-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_aggregator.py
60 lines (50 loc) · 1.63 KB
/
test_aggregator.py
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
import pytest
from flexmeasures.data.models.reporting.aggregator import AggregatorReporter
from datetime import datetime
from pytz import utc
@pytest.mark.parametrize(
"aggregation_method, expected_value",
[
("sum", 0),
("mean", 0),
("var", 2),
("std", 2**0.5),
("max", 1),
("min", -1),
("prod", -1),
("median", 0),
],
)
def test_aggregator(setup_dummy_data, aggregation_method, expected_value):
"""
This test computes the aggregation of two sensors containing 24 entries
with value 1 and -1, respectively, for sensors 1 and 2.
Test cases:
1) sum: 0 = 1 + (-1)
2) mean: 0 = ((1) + (-1))/2
3) var: 2 = (1)^2 + (-1)^2
4) std: sqrt(2) = sqrt((1)^2 + (-1)^2)
5) max: 1 = max(1, -1)
6) min: -1 = min(1, -1)
7) prod: -1 = (1) * (-1)
8) median: even number of elements, mean of the most central elements, 0 = ((1) + (-1))/2
"""
s1, s2, reporter_sensor = setup_dummy_data
reporter_config_raw = dict(
beliefs_search_configs=[
dict(sensor=s1.id, source=1),
dict(sensor=s2.id, source=2),
],
method=aggregation_method,
)
agg_reporter = AggregatorReporter(
reporter_sensor, reporter_config_raw=reporter_config_raw
)
result = agg_reporter.compute(
start=datetime(2023, 5, 10, tzinfo=utc),
end=datetime(2023, 5, 11, tzinfo=utc),
)
# check that we got a result for 24 hours
assert len(result) == 24
# check that the value is equal to expected_value
assert (result == expected_value).all().event_value