19.09.2022, 08:15
Another option is to use storage.
1. Event script to accumulate the values:
2. Scheduled script to calculate the average and reset the accumulated values:
1. Event script to accumulate the values:
Code:
value = event.getvalue()
key = 'average'
storage.exec('incrbyfloat', key .. ':acc', value)
storage.exec('incr', key .. ':cnt')
2. Scheduled script to calculate the average and reset the accumulated values:
Code:
key = 'average'
acc = storage.get(key .. ':acc', 0)
cnt = storage.get(key .. ':cnt', 0)
avg = 0
if cnt > 0 then
avg = acc / cnt
end
grp.update('1/1/1', avg)
storage.delete(key .. ':acc')
storage.delete(key .. ':cnt')