0
Answered

D105, how to calculate the daily average gas consumtion by month

Sasa 3 days ago in Dashboard and Widgets updated 3 days ago 8
GOOD, I'M SATISFIED
Satisfaction mark by Sasa 3 days ago
Answered

Just divide the monthly gas consumption by the number of days in the month. :)

For example, if gas (water/electricity) consumption is stored in the Ch1 data.

In the widget settings, in the Arithmetic operation section, select f(x) and write the following code in JavaScript syntax

var yy = new Date(d.TIME).getFullYear();
var mm = new Date(d.TIME).getMonth();
var dd = new Date(yy, mm + 1, 0).getDate();
d.Ch1 / dd;

Image 2608

Thanks for the formula you sent, that's something, but not what I wanted.

Let's say, if we take the current data for this month:

- Total monthly consumption in March so far is 115.7 m3

- 27 days have passed

- So, if we divide 115.7 by 27, we get the average daily consumption in March so far 4, 285 m3

And that's what I want to have, but your formula is a little bit different!

Can I get a formula that will show as stated above!

Best regards

Sasa

Here are the actual pictures, where it is clear that according to the entered formula, the average consumption in the ''month'' tab shows 37.3 m3!

But I want it to show:

- in the ''month'' tab the daily monthly average which should be 4,285

Image 2614

This is because the Ch1 data is pulses, not cubic meters.

Add to the formula the conversion from pulses to meters, for example, 

if you have 1 imp = 0.01 m3


. . .

d.Ch1 * 0.01 / dd;

Yes, you are right, the given formula does not know about the current month.

This can be corrected.

var dd;
var now = new Date();
var cm = +new Date(now.getFullYear(), now.getMonth(), 1);
if (d.TIME == cm) {
dd = now.getDate();
} else {
var yy = new Date(d.TIME).getFullYear();
var mm = new Date(d.TIME).getMonth();
dd = new Date(yy, mm + 1, 0).getDate();
} d.Ch1 * 0.01 / dd;

Image 2617

Image 2616

Now I've managed to get the correct average and create a similar table, but I don't know how to fill in the ''days'' tab on table, to show me the number of days in the month, like in your table?

"dd"  - is days. It's simple:

var dd;
var now = new Date();
var cm = +new Date(now.getFullYear(), now.getMonth(), 1);
if (d.TIME == cm) {
dd = now.getDate();
} else {
var yy = new Date(d.TIME).getFullYear();
var mm = new Date(d.TIME).getMonth();
dd = new Date(yy, mm + 1, 0).getDate();
}
dd;

Now is everything as it should be!

Thanks for your help!