![]() |
Counter and Trend - 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: Counter and Trend (/showthread.php?tid=317) |
Counter and Trend - managementboy - 06.06.2016 Hi, I am unsure how to realize this: I have a reed contact attached to the re:actor. I want to count the times it gets opened and log this, but I also would like to use it in a trend to see how often the reed gets opened in a day,week,month. Cheers! RE: Counter and Trend - admin - 06.06.2016 You can create an event script which increases object value on each run. Trend will automatically show how many events happened during selected period. You can also get trend data from Lua to display certain stats: http://openrb.com/docs/ Code: value = grp.getvalue('1/1/1') RE: Counter and Trend - Erwin van der Zwart - 06.06.2016 (06.06.2016, 13:19)admin Wrote: You can create an event script which increases object value on each run. Trend will automatically show how many events happened during selected period. You can also get trend data from Lua to display certain stats: http://openrb.com/docs/ Tip: Use a 12. 4 byte unsigned integer object to have maximum size to count without exponent and also use: value_reed = event.getvalue() if value_reed == true then value = grp.getvalue('1/1/1') if value >= (256*256*256*256) then -- max of 12. 4 byte unsigned integer object grp.update('1/1/1', 0) -- reset object value to zero to start counting from start again else grp.update('1/1/1', value + 1) end end This makes the counting only happening on opening of the reed otherwise the count will happen on opening and closing, and will make the object value jump to 0 when max of object is reached. BR, Erwin RE: Counter and Trend - admin - 07.06.2016 Erwin, that check is incorrect 256 * 256 * 256 * 256 = 0x100000000 (4294967296) Maximum value for unsigned 32-bit integer is 0xFFFFFFFF (4294967295) Code: if event.getvalue() then RE: Counter and Trend - Erwin van der Zwart - 07.06.2016 (07.06.2016, 06:17)admin Wrote: Erwin, that check is incorrect Hi Admin, Yes you are right, i add the +1 after validation, so it will never be that value Sorry (; BR, Erwin |