fix: test forecast uses UTC hour for solar/price lookup

buildWinterForecast was indexing solarW[] and winterPrices[] by slot
position h instead of actual UTC hour. When a forecast starts at 18:00,
h=8 (02:00 AM) was getting solarW[8]=1200W, giving midnight slots a
false solar bonus in RuleBasedStrategy::slotScore(). The strategy
correctly chose those slots, but countSlotsInCheapestN (price-only)
reported them as outside the 6 cheapest hours → test 1 failed.

Fix: index both arrays by slot.start.toUTC().time().hour() so solar
peaks at noon and prices reflect the real time-of-day. All 11 tests pass.

Also includes the INCLUDEPATH += \$\$PWD fix in energyplugin.pri that
makes relative includes work for test builds consuming the .pri.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
feature/shedule-manager
Patrick Schurig 2026-02-24 06:53:20 +01:00
parent 0797f37c78
commit 69246618ee
2 changed files with 8 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# All files in energyplugin use relative includes (e.g. "types/foo.h").
# Consumers of this .pri must have the energyplugin root on their include path.
INCLUDEPATH += $$PWD
greaterThan(QT_MAJOR_VERSION, 5) {
message("Building using Qt6 support")
CONFIG *= c++17

View File

@ -59,9 +59,11 @@ QList<EnergyTimeSlot> TestScheduler::buildWinterForecast(const QDateTime &start)
EnergyTimeSlot slot;
slot.start = start.addSecs(h * 3600);
slot.end = start.addSecs((h + 1) * 3600);
slot.solarForecastW = solarW[h];
// Index by actual UTC hour so solar peaks at noon and prices reflect time-of-day
int utcHour = slot.start.toUTC().time().hour();
slot.solarForecastW = solarW[utcHour];
slot.baseConsumptionW = baseW;
slot.electricityPrice = winterPrices[h];
slot.electricityPrice = winterPrices[utcHour];
slot.electricitySellPrice = 0.04;
forecast.append(slot);
}