From 2da2d9458b5b834eb0f7f7060977d85749e12d86 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 7 Dec 2021 23:48:23 +0100 Subject: [PATCH] Cleanups --- libnymea-energy/energylogs.h | 2 +- plugin/energylogger.cpp | 4 +--- plugin/energymanagerimpl.cpp | 11 ++++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libnymea-energy/energylogs.h b/libnymea-energy/energylogs.h index 79c89a2..301b6e2 100644 --- a/libnymea-energy/energylogs.h +++ b/libnymea-energy/energylogs.h @@ -38,7 +38,7 @@ public: virtual PowerBalanceLogEntries powerBalanceLogs(SampleRate sampleRate, const QDateTime &from = QDateTime(), const QDateTime &to = QDateTime()) const = 0; /*! Returns logs for the given sample rate for currentPower, totalEnergyConsumed and totalEnergyProduced for the given things. - * From and to may be given to limie results to a time span. + * From and to may be given to limit results to a time span. * If thingIds is empty, all things will be returned. */ virtual ThingPowerLogEntries thingPowerLogs(SampleRate sampleRate, const QList &thingIds, const QDateTime &from = QDateTime(), const QDateTime &to = QDateTime()) const = 0; diff --git a/plugin/energylogger.cpp b/plugin/energylogger.cpp index 9f1193c..9119a6d 100644 --- a/plugin/energylogger.cpp +++ b/plugin/energylogger.cpp @@ -488,7 +488,7 @@ void EnergyLogger::rectifySamples(SampleRate sampleRate, SampleRate baseSampleRa // Normally we'd need to find the newest available sample of a series and catch up from there. // However, it could happen a series does not have any samples at all yet. For example if we're logging since january, // and at new years the system was off, we missed the new years yearly sample and don't have any earlier. For those cases - // we need to start resampling from the oldest timestamp we find in the DB at all (regardless of the sampleRate) + // we need to start resampling from the oldest timestamp we find in the DB for the base sampleRate. QDateTime oldestBaseSample = getOldestPowerBalanceSampleTimestamp(baseSampleRate); QDateTime newestSample = getNewestPowerBalanceSampleTimestamp(sampleRate); @@ -577,8 +577,6 @@ bool EnergyLogger::samplePowerBalance(SampleRate sampleRate, SampleRate baseSamp { QDateTime sampleStart = sampleEnd.addMSecs(-sampleRate * 60 * 1000); - // FIXME: If base samplerate does not contain a single entry in the given timeframe (e.g. system has been off for more than 15 mins) we seem to mess up totalConsumption - // Needs verifying that lower sample rates are always rectified first! qCDebug(dcEnergyExperience()) << "Sampling power balance" << sampleRate << "from" << sampleStart << "to" << sampleEnd; double medianConsumption = 0; diff --git a/plugin/energymanagerimpl.cpp b/plugin/energymanagerimpl.cpp index dc9b849..ea664f3 100644 --- a/plugin/energymanagerimpl.cpp +++ b/plugin/energymanagerimpl.cpp @@ -12,10 +12,11 @@ EnergyManagerImpl::EnergyManagerImpl(ThingManager *thingManager, QObject *parent m_thingManager(thingManager), m_logger(new EnergyLogger(this)) { - // Most of the time we get a bunch of signals at the same time (root meter, producers, consumers etc) - // In order to decrease some load on the system, we'll wait for wee bit until we actually update to - // accumulate those changes and calculate the change in one go. - m_balanceUpdateTimer.setInterval(50); + // Most of the time we get a bunch of state changes (currentPower, totals, for inverter, battery, rootmeter) + // at the same time if they're implemented by the same plugin. + // In order to decrease some load on the system, we'll wait for the event loop pass to finish until we actually + // update to accumulate those changes and calculate the change in one go. + m_balanceUpdateTimer.setInterval(0); m_balanceUpdateTimer.setSingleShot(true); connect(&m_balanceUpdateTimer, &QTimer::timeout, this, &EnergyManagerImpl::updatePowerBalance); @@ -125,7 +126,7 @@ void EnergyManagerImpl::watchThing(Thing *thing) qCDebug(dcEnergyExperience()) << "Wathing thing:" << thing->name(); - // React on things that requie us updating the power balance + // React on things that require us updating the power balance if (thing->thingClass().interfaces().contains("energymeter") || thing->thingClass().interfaces().contains("smartmeterproducer") || thing->thingClass().interfaces().contains("energystorage")) {