# [rrd-users] Question about averaging daily ; but with 5 min. steps

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Tue Dec 15 13:25:25 CET 2009

```----- Original Message -----
From: "Jean-Yves Avenard" <jyavenard at gmail.com>
To: <rrd-users at lists.oetiker.ch>
Sent: Monday, December 14, 2009 11:28 PM
Subject: Re: [rrd-users] Question about averaging daily ;but with 5 min.
steps

> 2009/12/15 Alex van den Bogaerdt <alex at vandenbogaerdt.nl>:
>> It still does. Else you would understand that this 'problem' is no
>> different
>> from having bits (or megabytes) in your database and using CDEF and
>> GPRINT
>> to display the average, after being multiplied by 86400, to get the
>> amount
>> of bits (or megabytes) in a day.
>
> You still obviously haven't read my original post in what I'm trying
> to achieve :(
>
>
>> If the average is 1J/s (== 1W), and if you multiply by 86400s, you can
>> cross
>> out the 's' units and end up with 86400J. And if you input kWh instead of
>> J,
>> you end up with kWh instead of J. Which is what you ask for.
>
> No, this is not what I'm asking for at all... Why are you so convinced
> I'm having an issue converting Watts over time in Wh ?

Because you wrote Wh = watt/hour. It is W times 1 hour, one Wh is just 3600
Joules.  And because I get lost in all the calculations you perform in the
rrdtool script you show. Calculations which may not even be necessary.

In the database you have (or: should have) Joules. Or kWh, that doesn't
really matter. I would prefer Joules, but it's up to you. I think we agree
that this does not matter, and I will write Joules from now on. You can map
that to Wh if you like.

You feed Watts to RRDtool, then because of how RRDtool works it stores the
amount of Joules (per second, which is Watts). So, you work with Joules and
should think in Joules.

Then, when you subtract your usage from your generated power, with a minimum
of zero, you end up with the amount of Joules you did generate but not use
yourself.  The remainder is fed to the net. You want to know how much that
amount is. Correct?

> The basic calculation is pretty much:
> CDEF:cexport=ctotal,csolar,-,0,MAX

Assuming that "ctotal" is the amount of power used, and "csolar" is the
amount of power generated:
I think you wrote this summary backwards, or else this is where your problem
is. It should be
CDEF:cexport=csolar,ctotal,-,0,MAX

The average of that amount of Joules during a certain time frame (such as
86400 seconds), multiplied by the number of seconds, is the amount of
Joules.  And converting that to Wh or kWh is just a matter of multiplying
(using CDEF) before letting RRDtool compute its average.

You could, for instance, let RRDtool generate a report without graphing. Use
PRINT (not: GPRINT) to write the average.

rrdtool graph nothing --start \$midnight1 --end start+24h DEF:ctotal=....
DEF:csolar=... CDEF:cexport=csolar,ctotal,-,0,MAX,86400,*,3600,/
PRINT:cexport:AVERAGE:%6.2lf

(you need to add several lines, for instance make sure there are no
unknowns)

For every 5-minute slot: if you produced more than you used, it turns up as
a positive number. If you produced less than you used, it turns up as zero.
A smaller example (one day would be too much): 0, 0, 10, 20, 50, 40, 0, 0,
0, 0
During 6 intervals you used less than you produced. 10+20+50+40=120. When
RRDtool is averaging this, it would compute 120/12=10. When multiplied with
the amount of time, 12 in my example, you end up with 120 which is, not
surprisingly, the same as 10+20+50+40.
In this example I used unnamed units. The result is the same if I work in
kWh, Wh, time slots of 300 seconds, etc.

```