14.11.2022, 20:14
Event script:
Scheduled script sent every 0 minute:
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