master
Michael Zanetti 2021-11-23 00:47:11 +01:00
parent 034f90d7a9
commit a34dd7642b
3 changed files with 6 additions and 4 deletions

View File

@ -102,7 +102,7 @@ Q_DECLARE_METATYPE(PowerBalanceLogEntries)
class ThingPowerLogEntry {
Q_GADGET
Q_PROPERTY(QDateTime timstamp READ timestamp)
Q_PROPERTY(QDateTime timestamp READ timestamp)
Q_PROPERTY(QUuid thingId READ thingId)
Q_PROPERTY(double currentPower READ currentPower)
Q_PROPERTY(double totalConsumption READ totalConsumption)

View File

@ -188,6 +188,6 @@ JsonReply *EnergyJsonHandler::GetThingPowerLogs(const QVariantMap &params)
QDateTime from = params.contains("from") ? QDateTime::fromMSecsSinceEpoch(params.value("from").toLongLong() * 1000) : QDateTime();
QDateTime to = params.contains("to") ? QDateTime::fromMSecsSinceEpoch(params.value("to").toLongLong() * 1000) : QDateTime();
QVariantMap returns;
returns.insert("thingPowerLogEntries",pack(m_energyManager->logs()->thingPowerLogs(sampleRate, thingIds, from, to)));
returns.insert("thingPowerLogEntries", pack(m_energyManager->logs()->thingPowerLogs(sampleRate, thingIds, from, to)));
return createReply(returns);
}

View File

@ -139,13 +139,15 @@ ThingPowerLogEntries EnergyLogger::thingPowerLogs(SampleRate sampleRate, const Q
QVariantList bindValues;
bindValues << sampleRate;
qCDebug(dcEnergyExperience()) << "Fetching thing power logs for" << thingIds;
QStringList thingsQuery;
foreach (const ThingId &thingId, thingIds) {
thingsQuery.append("thingId = ?");
bindValues << thingId;
}
if (!thingsQuery.isEmpty()) {
queryString += "AND (" + thingsQuery.join(" OR ") + " )";
queryString += " AND (" + thingsQuery.join(" OR ") + " )";
}
if (!from.isNull()) {
@ -598,7 +600,7 @@ bool EnergyLogger::insertPowerBalance(const QDateTime &timestamp, SampleRate sam
query.addBindValue(totalReturn);
query.exec();
if (query.lastError().isValid()) {
qCWarning(dcEnergyExperience()) << "Error logging consumption sample:" << query.lastError();
qCWarning(dcEnergyExperience()) << "Error logging consumption sample:" << query.lastError() << query.executedQuery();
return false;
}
emit powerBalanceEntryAdded(sampleRate, PowerBalanceLogEntry(timestamp, consumption, production, acquisition, storage, totalConsumption, totalProduction, totalAcquisition, totalReturn));