Skip to content

Commit

Permalink
fixed statitstics for "today"
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Sep 25, 2023
1 parent ca8a0ad commit 42e2e9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.18.0] [2023-09-25]
### fixed statistics for today - [#13](https://github.com/windkh/node-red-contrib-grohe-sense/issues/13)

## [0.17.0] [2023-09-24]
### fixed examples and added groupBy option - [#12](https://github.com/windkh/node-red-contrib-grohe-sense/issues/13)
### fixed examples and added groupBy option - [#13](https://github.com/windkh/node-red-contrib-grohe-sense/issues/13)

## [0.16.0] [2023-09-15]
### breaking change in API: data is now data/aggregated - [#12](https://github.com/windkh/node-red-contrib-grohe-sense/issues/12)
Expand Down
42 changes: 22 additions & 20 deletions grohe/99-grohe.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,28 @@ module.exports = function (RED) {
let todayMaxFlowrate = Number.NaN;

let length = withdrawals.length;
let latestDate = withdrawals[length - 1].date;
let today = new Date(new Date(latestDate).toDateString());

for (let i=0; i < length; i++) {
let item = withdrawals[i];

let date = new Date(item.date);
totalWaterConsumption += item.waterconsumption;
totalWaterCost += item.water_cost;
totalEnerygCost += item.energy_cost;
totalHotwaterShare += item.hotwater_share;
let flowrate = item.maxflowrate;
totalMaxFlowrate = getMax(flowrate, totalMaxFlowrate);

if(date > today) {
todayWaterConsumption += item.waterconsumption;
todayWaterCost += item.water_cost;
todayEnerygCost += item.energy_cost;
todayHotwaterShare += item.hotwater_share;
todayMaxFlowrate = getMax(flowrate, todayMaxFlowrate);
if(length > 0) {
let todayDate = withdrawals[0].date;
let today = new Date(new Date(todayDate).toDateString());

for (let i=0; i < length; i++) {
let item = withdrawals[i];

let date = new Date(item.date);
totalWaterConsumption += item.waterconsumption;
totalWaterCost += item.water_cost;
totalEnerygCost += item.energy_cost;
totalHotwaterShare += item.hotwater_share;
let flowrate = item.maxflowrate;
totalMaxFlowrate = getMax(flowrate, totalMaxFlowrate);

if(date >= today) {
todayWaterConsumption += item.waterconsumption;
todayWaterCost += item.water_cost;
todayEnerygCost += item.energy_cost;
todayHotwaterShare += item.hotwater_share;
todayMaxFlowrate = getMax(flowrate, todayMaxFlowrate);
}
}
}

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.17.0",
"version": "0.18.0",
"description": "Grohe sense nodes via ondus API.",
"node-red": {
"version": ">=0.1.0",
Expand Down

0 comments on commit 42e2e9e

Please sign in to comment.