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.

Trends_Log
#1
Wink 
Hello, I would like to know how I can put a trend to a function, to see the data of this in a graph.
I was watching this document:
Http://openrb.com/docs/trends.htm
But I do not understand if this code should be added to the function or created separately. Also I get error with the library: genohm-scada.trends
Thanks...
Reply
#2
For 99% you are using Logic Machine with firmware after april 2016 so you should use this API:

http://openrb.com/docs/trends-new.htm
Reply
#3
Hi,
Sorry, that code I should add to the function that I set the trend?
Reply
#4
What do you want to do? Add new trend(1) or download the data(2) from existing trend and operation on this data?

If you want 1) add new trend you should use menu, this has nothing with scripting.

If you want 2) download data then you should do exactly what is in API. For example when you want download last year daily data of trend "Gas" you should paste in a script:
Code:
require('trends')

trend_name = "Gas"

-- get data for the past year
dates = {}
dates['start'] = os.date('*t')
dates['start'].year = dates['start'].year - 1
dates['end'] = os.date('*t')

-- fetch previous value
yearly = trends.fetch(trend_name, dates, 86400)

Then you can operate freely on such data(normal table). You can use it also in function. All is in the manual of Logic Machine and on:
http://openrb.com/docs/
Reply
#5
Hi,
Could you average the data obtained between certain dates? 

Thanks for your help. Big Grin
Reply
#6
For calculating average value for some period you should use trends.fetchone() function instead trends.fetch().

You can also look here:
http://forum.logicmachine.net/showthread...=trend+api
Reply
#7
Should I work in a resident function?

Another question is, in the graphic part, the data that is shown is the average of all the data that was handled in that time interval?
For example, I put a resolution trend of 5 minutes.
Reply
#8
It depends what you want do. What is your task?
Reply
#9
In the first instance I want to make a test of logic, so I generated a basic function that generates random numbers and that creates a trend. But I do not know if the data that shows me in the graph is an average of the interval, I also want to know the average between certain dates of these data.
Reply
#10
Following the API it is the average from selected period. You should only know that the minimum resolution is 1 day(from 00:00 to 23:59). If you want check what is the average from e.g. 8:00-16:00 you should use fetch function and calculate this.
Reply
#11
OK, what kind of function should I handle the average?
To be able to download this data should I add some library?
Thank you. Big Grin
Reply
#12
This is little example for calculating average value:
Code:
require('trends')

-- get data for the last day from 00:00 to 23:59
dates = {}
dates['start'] = os.date('*t')
dates['start'].day = dates['start'].day - 1
dates['end'] = os.date('*t')

-- fetch previous value
daily = trends.fetch('Wind', dates)

sum = 0
for k,v in ipairs(daily) do
 sum = sum + v
end

average = sum/(#daily)
log(average)
Reply


Forum Jump: