mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-01-09 20:26:18 +00:00
fix: load prediction adjustment with measurement in kwh (#826)
Use load energy meter reading in kWh for load prediction adjustment. Before the reading was falsely regarded to be in Wh. Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
@@ -56,9 +56,10 @@ def loadakkudoktoradjusted(config_eos):
|
||||
@pytest.fixture
|
||||
def measurement_eos():
|
||||
"""Fixture to initialise the Measurement instance."""
|
||||
# Load meter readings are in kWh
|
||||
measurement = get_measurement()
|
||||
load0_mr = 500
|
||||
load1_mr = 500
|
||||
load0_mr = 500.0
|
||||
load1_mr = 500.0
|
||||
dt = to_datetime("2024-01-01T00:00:00")
|
||||
interval = to_duration("1 hour")
|
||||
for i in range(25):
|
||||
@@ -70,8 +71,9 @@ def measurement_eos():
|
||||
)
|
||||
)
|
||||
dt += interval
|
||||
load0_mr += 50
|
||||
load1_mr += 50
|
||||
# 0.05 kWh = 50 Wh
|
||||
load0_mr += 0.05
|
||||
load1_mr += 0.05
|
||||
assert compare_datetimes(measurement.min_datetime, to_datetime("2024-01-01T00:00:00")).equal
|
||||
assert compare_datetimes(measurement.max_datetime, to_datetime("2024-01-02T00:00:00")).equal
|
||||
return measurement
|
||||
@@ -187,7 +189,7 @@ def test_calculate_adjustment(loadakkudoktoradjusted, measurement_eos):
|
||||
100.0,
|
||||
]
|
||||
)
|
||||
np.testing.assert_array_equal(weekday_adjust, expected)
|
||||
np.testing.assert_allclose(weekday_adjust, expected)
|
||||
|
||||
assert weekend_adjust.shape == (24,)
|
||||
expected = np.array(
|
||||
|
||||
@@ -217,6 +217,7 @@ class TestMeasurement:
|
||||
@pytest.fixture
|
||||
def measurement_eos(self, config_eos):
|
||||
"""Fixture to create a Measurement instance."""
|
||||
# Load meter readings are in kWh
|
||||
config_eos.measurement.load_emr_keys = ["load0_mr", "load1_mr", "load2_mr", "load3_mr"]
|
||||
measurement = get_measurement()
|
||||
record0 = MeasurementDataRecord(
|
||||
@@ -365,35 +366,35 @@ class TestMeasurement:
|
||||
with pytest.raises(ValueError, match="interval must be positive"):
|
||||
measurement_eos._energy_from_meter_readings(key, start_datetime, end_datetime, interval)
|
||||
|
||||
def test_load_total(self, measurement_eos):
|
||||
def test_load_total_kwh(self, measurement_eos):
|
||||
"""Test total load calculation."""
|
||||
start = datetime(2023, 1, 1, 0)
|
||||
end = datetime(2023, 1, 1, 2)
|
||||
interval = duration(hours=1)
|
||||
|
||||
result = measurement_eos.load_total(start_datetime=start, end_datetime=end, interval=interval)
|
||||
result = measurement_eos.load_total_kwh(start_datetime=start, end_datetime=end, interval=interval)
|
||||
|
||||
# Expected total load per interval
|
||||
expected = np.array([100, 100]) # Differences between consecutive meter readings
|
||||
np.testing.assert_array_equal(result, expected)
|
||||
|
||||
def test_load_total_no_data(self, measurement_eos):
|
||||
def test_load_total_kwh_no_data(self, measurement_eos):
|
||||
"""Test total load calculation with no data."""
|
||||
measurement_eos.records = []
|
||||
start = datetime(2023, 1, 1, 0)
|
||||
end = datetime(2023, 1, 1, 3)
|
||||
interval = duration(hours=1)
|
||||
|
||||
result = measurement_eos.load_total(start_datetime=start, end_datetime=end, interval=interval)
|
||||
result = measurement_eos.load_total_kwh(start_datetime=start, end_datetime=end, interval=interval)
|
||||
expected = np.zeros(3) # No data, so all intervals are zero
|
||||
np.testing.assert_array_equal(result, expected)
|
||||
|
||||
def test_load_total_partial_intervals(self, measurement_eos):
|
||||
def test_load_total_kwh_partial_intervals(self, measurement_eos):
|
||||
"""Test total load calculation with partial intervals."""
|
||||
start = datetime(2023, 1, 1, 0, 30) # Start in the middle of an interval
|
||||
end = datetime(2023, 1, 1, 1, 30) # End in the middle of another interval
|
||||
interval = duration(hours=1)
|
||||
|
||||
result = measurement_eos.load_total(start_datetime=start, end_datetime=end, interval=interval)
|
||||
result = measurement_eos.load_total_kwh(start_datetime=start, end_datetime=end, interval=interval)
|
||||
expected = np.array([100]) # Only one complete interval covered
|
||||
np.testing.assert_array_equal(result, expected)
|
||||
|
||||
Reference in New Issue
Block a user