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.

Using the average of a trend log value in a script
#5
Trends keep 1 hour of object values sampled every minute which you can use. This won't be a true average though because any changes between sampling times are lost.

This example will fetch values from the past 30 minutes and calculate the average value.
Code:
123456789101112131415161718192021222324252627
require('trends') date = os.date('*t') time = os.time(date, true) daterange = {   ['start'] = time - 30 * 60,   ['end'] = time, } data = trends.fetch('my trend', daterange, 60) avg = 0 count = 0 for index, value in pairs(data) do   if value and value == value then     avg = avg + value     count = count + 1   end end if count > 0 then   avg = avg  / count end log(avg)
Reply


Messages In This Thread
RE: Using the average of a trend log value in a script - by admin - 16.09.2024, 10:36

Forum Jump: