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.

Average power for the last clock hour
#12
Event script:

Code:
local st_name = 'average' -- Local table name
local value_in = '4/6/1' -- GA data input



local st_table = storage.get(st_name)
if not st_table then
  log('Table Created')
  local st_values = {}
  storage.set(st_name, st_values)
end



table.insert(st_table, grp.getvalue(value_in))



storage.set(st_name, st_table)

Scheduled script sent every 0 minute:
Code:
local st_name = 'average' -- Name on local table
local result_avg = '4/3/34' -- GA for result output



local st_table = storage.get(st_name)
if st_table then
  local size = 0
  local sum_val = 0
  for i, v in pairs(st_table) do
    sum_val = v + sum_val
    size = size + 1
  end
 
  local avg_val = sum_val / size
  grp.write(result_avg, avg_val)
  local reset_table = {}
  log(avg_val)
  log(size)
  storage.set(st_name, reset_table)
  log(storage.get(st_name))
end
Reply


Messages In This Thread
RE: Average power for the last clock hour - by Rune - 14.11.2022, 20:14

Forum Jump: