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.

Get last value of trend
#7
Here you have what you looking forWink

Code:
require('trends')

-- get data for today
function returnLastTrendValue(trendName)
 dates = {}

 dates['start'] = os.date('*t')
 dates['start'].day = dates['start'].day - 1
 dates['end'] = os.date('*t')
 dates['end'].day = dates['end'].day + 1

 trends.NaN = '*'
 -- fetch previous value
 daily = trends.fetch(trendName, dates, 1)

 i = #daily
 while i > 0 do
   if daily[i] ~= '*' then return daily[i] end
   i=i-1
 end
end

lastValue = returnLastTrendValue('Your trend name')
log(lastValue)

I've tested Trends API some time ago and I've found that to have some data from today you must type not today timestamp but tomorrow and also 1 day before. The last value is the last measured value before midnight e.g. for 5minute resolution 23:55. For taking your maximum resolution you can type instead 86400 only 1. And then you should define undefined value from RRD db and ylou should look from 00:00 to first data which will appearWink
Reply


Messages In This Thread
Get last value of trend - by baggins - 06.02.2018, 12:29
RE: Get last value of trend - by Daniel - 06.02.2018, 13:37
RE: Get last value of trend - by baggins - 06.02.2018, 13:42
RE: Get last value of trend - by Daniel - 06.02.2018, 16:33
RE: Get last value of trend - by admin - 06.02.2018, 16:40
RE: Get last value of trend - by baggins - 06.02.2018, 17:12
RE: Get last value of trend - by buuuudzik - 06.02.2018, 17:57
RE: Get last value of trend - by baggins - 06.02.2018, 18:23
RE: Get last value of trend - by buuuudzik - 06.02.2018, 18:24

Forum Jump: