diff --git a/CHANGELOG.md b/CHANGELOG.md index f623009..ff2c1c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.15.0] [2022-11-21] +### added more statistics to history data + ## [0.14.0] [2022-11-20] ### added statistics for measurements and withdrawals - [#3](https://github.com/windkh/node-red-contrib-grohe-sense/issues/3) ### improved readability of notifications - [#4](https://github.com/windkh/node-red-contrib-grohe-sense/issues/4) diff --git a/grohe/99-grohe.js b/grohe/99-grohe.js index ffdb191..dbceac7 100644 --- a/grohe/99-grohe.js +++ b/grohe/99-grohe.js @@ -139,16 +139,27 @@ module.exports = function (RED) { let totalWaterConsumption = 0; let totalWaterCost = 0; let totalEnerygCost = 0; - let maxFlowrate = Number.NaN; + let totalMaxFlowrate = Number.NaN; let totalDuration = 0; let minDuration = Number.NaN; let maxDuration = Number.NaN; + let todayWaterConsumption = 0; + let todayWaterCost = 0; + let todayEnerygCost = 0; + let todayMaxFlowrate = Number.NaN; + let todayDuration = 0; + let length = withdrawals.length; + let latestStopTime = withdrawals[length - 1].stoptime; + let today = new Date(new Date(latestStopTime).toDateString()); + for (let i=0; i < length; i++) { let item = withdrawals[i]; - let duration = (new Date(item.stoptime) - new Date(item.starttime)) / 1000; + let stopDate = new Date(item.stoptime); + let startDate = new Date(item.starttime); + let duration = (stopDate- startDate) / 1000; totalDuration += duration; minDuration = getMin(duration, minDuration); maxDuration = getMax(duration, maxDuration); @@ -157,7 +168,15 @@ module.exports = function (RED) { totalWaterCost += item.water_cost; totalEnerygCost += item.energy_cost; let flowrate = item.maxflowrate; - maxFlowrate = getMax(flowrate, maxFlowrate); + totalMaxFlowrate = getMax(flowrate, totalMaxFlowrate); + + if(stopDate > today) { + todayWaterConsumption += item.waterconsumption; + todayWaterCost += item.water_cost; + todayEnerygCost += item.energy_cost; + todayMaxFlowrate = getMax(flowrate, todayMaxFlowrate); + todayDuration += duration; + } } let convertWithdrawals = { @@ -168,10 +187,18 @@ module.exports = function (RED) { totalWaterCost : totalWaterCost, totalEnerygCost : totalEnerygCost, totalDuration : totalDuration, + todayWaterConsumption : todayWaterConsumption, + todayWaterCost : todayWaterCost, + todayEnerygCost : todayEnerygCost, + todayDuration : todayDuration, + } + + if (!isNaN(totalMaxFlowrate)){ + convertWithdrawals.totalMaxFlowrate = totalMaxFlowrate; } - if (!isNaN(maxFlowrate)){ - convertWithdrawals.maxFlowrate = maxFlowrate; + if (!isNaN(todayMaxFlowrate)){ + convertWithdrawals.todayMaxFlowrate = todayMaxFlowrate; } if (!isNaN(minDuration)){ diff --git a/package.json b/package.json index 1fca154..d1379cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-grohe-sense", - "version": "0.14.0", + "version": "0.15.0", "description": "Grohe sense nodes via ondus API.", "node-red": { "version": ">=0.1.0",