# [rrd-users] How to calculate desired value?

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Sun Aug 24 03:17:04 CEST 2014

```----- Original Message -----
From: "spock" <collector at sappers.de>
To: <rrd-users at lists.oetiker.ch>
Sent: Saturday, August 23, 2014 9:57 PM
Subject: Re: [rrd-users] How to calculate desired value?

> Hi Simon, thanks for helping me out.
> I will include a more detailed example here:
> <http://rrd-mailinglists.937164.n2.nabble.com/file/n7582382/tempday1.png>
>
> The graph shows 24h; database has step 900
> Lets take the grey area:
> we have "1" values from 09:30 to 19:45 = 10.25h.

I think it is 09:15, and 10.5 hours.

Relevant parameters include start and end time, number of pixels.
You should have "--end {some timestamp equal to midnight} --start
end-24h --width {any number being a whole multiple of 96}"
If not, something has to give and question #1 (see below) is answered.

You have a rate of 1 from 09:15 to 19:45. 10.5 hours
You have a rate of 0 from 00:00 to 09:15 and from 19:45 to 24:00.  9.25
hours and 4.25 hours, total 13.5 hours.
You compute the average rate, which is 10.5/24=0.4375.
You multiply that by 900, divide by 60, and the answer should be 6.5625 so
the two questions are:
1: why do you get a different outcome
2: why do you think you should multiply by 15 ( *900/60 is the same as *15)
to get hours?

The answer to question #1 could be as Simon suggested: rounding errors. I
expect the amount of time could be not exactly 24 hours.
The solution to question #2 is to think it over again.  Assuming your start
and end times are exactly midnight, you are averaging over a 24 hour period,
you have an average "pump on" ratio which you should multiply by 24 to get
the amount of hours.  The answer you should get would be 10.5 (or 10.25 if I
see things wrong) except for that (relatively small) error from question #1.

Further testing:

Fake some data, have the (fake) pump on during exactly 1 hour 23:00 the day
before until midnight, and no other times. Then print the average pump time.
It should be zero.  In a different testing round, do the same from midnight
at the end of that day until 01:00. Again the average pump time should be
zero.  If it is not in either test, then you know there is a problem with
the start time or the end time.
In a third test, have the pump on from 12:00 to 15:00. The average rate
should be exactly 0.125

Just print the average of pump_flag to debug, no CDEFs involved.
Look at the output of rrdtool dump and verify that it matches what you
expect.

Oh and by the way: i got confused because you started talking about
heat_flag and then switched to pump_flag. I know how it is when debugging,
it is easy to confuse yourself in similar ways. Whenever a value is not what
you expect, take a step back and look at the problem again.

HTH
Alex

```

More information about the rrd-users mailing list