This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Reading trends from RRD in Lua
#4
Hi Buuudzik,

Unfortunately that option is not available, but you can easily create simulair result including timestamp by using this:

Code:
require('trends')
name = 'Słońce_Azymut'
dates = {}
dates['start'] = { year = 2017, month = 4, day = 6}
dates['end'] = { year = 2017, month = 4, day = 7}
-- default trend resolution is used when not set
resolution = 3600 -- hourly data
res, a, b = trends.fetch(name, dates, resolution)

-- Create new table with timestamp and only values between 7 and 13
newtable = {}
for i, row in ipairs(res) do
 if (i-1) >= 7 and (i-1) <= 13 then
     table.insert(newtable, {time = (i-1) .. ':00', value = row})
 end
end

log(newtable)

If you resolution is 5 minutes you can convert it to hourly data like this:

Code:
require('trends')
name = 'Słońce_Azymut'
dates = {}
dates['start'] = { year = 2017, month = 4, day = 6}
dates['end'] = { year = 2017, month = 4, day = 7}
-- default trend resolution is used when not set
resolution = 3600 -- hourly data
res, a, b = trends.fetch(name, dates, resolution)

newtable = {}
if #res == 288 then
counter = 0
total = 0
for i, row in ipairs(res) do
  total = total + row
  counter = counter + 1
  if counter == 12 then
    if ((i/12)-1) >= 7 and ((i/12)-1) <= 13 then
        table.insert(newtable, {time = ((i/12)-1) .. ':00', value = (total/12)})
    end
    counter = 0
  end
end
end

log(newtable)

If you resolution is 10 minutes change 288 to 144 and all 12 to 6 , for 15 minutes resolution change 288 to 96 and all 12 to 4, for 20 minutes resolution change 288 to 72 and all 12 to 3, for 30 minutes resolution change 288 to 48 and all 12 to 2.

BR,

Erwin
Reply


Messages In This Thread
Reading trends from RRD in Lua - by buuuudzik - 06.04.2017, 16:53
RE: Reading trends from RRD in Lua - by Erwin van der Zwart - 06.04.2017, 22:00
RE: Reading trends from RRD in Lua - by iJAF - 07.07.2022, 17:09

Forum Jump: