Skip to content

Commit

Permalink
added today statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Nov 21, 2022
1 parent dfe904b commit 30d5cbf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
37 changes: 32 additions & 5 deletions grohe/99-grohe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = {
Expand All @@ -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)){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 30d5cbf

Please sign in to comment.