hexalog / libklio normalize readings to minute-resolution
Created by: gonium
NOTE: This was originally submitted here: https://github.com/mysmartgrid/hexabus/issues/107
Hi,
I would like to record multiple devices in the house with HexaBus plugs+ and plot a sum graph with a minute resolution. The fact that each plug submits its readings at different seconds is not quite good for this use case. My quick and dirty workaround was:
- just cut off split seconds of timestamp
- look at the 5 values before and after the current value to see if there's another reading for the same minute
- average over values of the same minute
Of course, it would be even better to calculate a more accurate minute value by taking the last value before and the first after the minute in question. E.g., if you had readings (UNIX timestamp here converted to human-readable datetime)
datetime value 2012-10-01 19:59:40 50 2012-10-01 20:00:30 100 2012-10-01 20:01:10 200
- imagine a line through the points (2012-10-01 19:59:40;50) and (2012-10-01 20:00:30;100) which could also be referred to by (-20;50) and (30;100) when counting the seconds to the next full minute (full minute = 0)
- the linear equation has the form y = ax + b
- the gradient of the line through the two points is a = (100-50)/((30-(-20)) = 50/50 = 1
- with the point (-20;50) you get b=70
do the same with the next two timestamps (-30;100) and (10;200), you get a = 2,5 and b = 175
That way, the normalized readings would read:
datetime value 2012-10-01 20:00:00 70 2012-10-01 20:01:00 175
Could we have this calculation in libklio?
Cheers,
Monika