Logic Machine Forum
Read from log. - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Read from log. (/showthread.php?tid=5051)



Read from log. - tomnord - 24.10.2023

I'm using the db:getall function to read historical values from a GA. The point is to read a value that is one hour old and compare it to current value. but I'm getting an offset on several minutes. Is this just because there are no new value stored exactly one hour back from when I poll?


RE: Read from log. - admin - 24.10.2023

Object log stores values only when they actually change. For your use case a scheduled script that saves current object value to storage should work better. This script can be adapted to store X latest values: https://forum.logicmachine.net/showthread.php?tid=350&pid=1726#pid1726


RE: Read from log. - tomnord - 24.10.2023

(24.10.2023, 10:52)admin Wrote: Object log stores values only when they actually change. For your use case a scheduled script that saves current object value to storage should work better. This script can be adapted to store X latest values: https://forum.logicmachine.net/showthread.php?tid=350&pid=1726#pid1726

how would you access these values for comparing?


RE: Read from log. - admin - 24.10.2023

Scheduled script that runs every minute. It will store latest 60 object values for the given address. oldvalue variable will contain the oldest entry in the list. It will be 1 hour long when the list accumulates 60 entries.
Code:
addr = '0/0/1'
key = 'values_' .. addr
max = 60

newvalue = grp.getvalue(addr)

storage.exec('lpush', key, newvalue)
storage.exec('ltrim', key, 0, max - 1)

oldvalue = storage.exec('lindex', key, -1)
oldvalue = tonumber(oldvalue)

log(newvalue, oldvalue)