# How to calculate desired value?

6 messages
Open this post in threaded view
|

## How to calculate desired value?

 Hello, I am currently working on a swimming pool control. I store values every 15 min (precise timestamp; 16:15:00; 16:30:00; etc.) and for every 15 min I store the "heat_flag", which is either "0" (heating off) or "1" (heating on). # rrdtool create temp_pool.rrd --step 900 --start "20140101 00:00" \ # DS:pump_flag:GAUGE:1200:0:1 \ # DS:heat_flag:GAUGE:1200:0:1 \ # DS:device:GAUGE:1200:0:90 \ # RRA:AVERAGE:0.5:1:103680 \ # RRA:MIN:0.5:96:3650 \ # RRA:MAX:0.5:96:3650 \ # RRA:AVERAGE:0.5:96:3650 I would like to calculate the total heating time per day. For that, I would like to find the number of "1" values per day. In the end, multiply by 15min and I know the total heating time. I tried:         CDEF:heattime2=heat_flag,900,*,60,/ \         VDEF:totalheattime=heattime2,AVERAGE'         GPRINT:totalheattime:"Total\: %2.2lf h \n"' but I get wrong results. I probably have to do the calculation completly different. Can anyone help me out here? I should get perfectly aligned values as a result: 0.25 h; 0.50h; etc. How can I achieve this? Thanks a million, spo
Open this post in threaded view
|

## Re: How to calculate desired value?

 spock <[hidden email]> wrote: > I tried: > CDEF:heattime2=heat_flag,900,*,60,/ \ > VDEF:totalheattime=heattime2,AVERAGE' > GPRINT:totalheattime:"Total\: %2.2lf h \n"' > but I get wrong results. I probably have to do the calculation completly > different. > > Can anyone help me out here? > > I should get perfectly aligned values as a result: 0.25 h; 0.50h; etc. > How can I achieve this? Give us a clue to go on, what values do you get ? Is it that you expected (say) 15 but got 14.99, or you got something completely different ? Your approach is right, I suspect rounding errors come into it. _______________________________________________ rrd-users mailing list [hidden email] https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Open this post in threaded view
|

## Re: How to calculate desired value?

 Hi Simon, thanks for helping me out. I will include a more detailed example here: 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. relevant graph parameters:         DEF:heat_flag=temp_pool.rrd:heat_flag:AVERAGE \         DEF:pump_flag=temp_pool.rrd:pump_flag:AVERAGE \         CDEF:pumptime=pump_flag,1,EQ,INF,UNKN,IF \         CDEF:heattime=heat_flag,1,EQ,INF,UNKN,IF \         CDEF:heattime2=heat_flag,900,*,60,/ \         CDEF:pumptime2=pump_flag,900,*,60,/ \         VDEF:totalpumptime=pumptime2,AVERAGE \         VDEF:totalheattime=heattime2,AVERAGE'         AREA:pumptime#10101010 \         AREA:heattime#FF000015 \         LINE2:pump_flag#000000 \         GPRINT:totalpumptime:"Filterzeit\: %2.2lf h   " \         GPRINT:totalheattime:"Heizzeit\: %2.2lf h \n"' As you can see, the calculation for totalpumptime is 6.49h, although it should be 10.25h. The LINE2: pump_flag shows clearly, that the data is there, all "1" values - rest of the day "0" values. Thanks again, spock
Open this post in threaded view
|

## Re: How to calculate desired value?

 ----- Original Message ----- From: "spock" <[hidden email]> To: <[hidden email]> 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: > > > 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 _______________________________________________ rrd-users mailing list [hidden email] https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users