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.

Counter and Trend
#1
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!
Reply
#2
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')
grp.update('1/1/1', value + 1)
Reply
#3
(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/

Code:
value = grp.getvalue('1/1/1')
grp.update('1/1/1', value + 1)

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
Reply
#4
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
  value = grp.getvalue('1/1/1') + 1
  
  -- overflow check
  if value > 0xFFFFFFFF then
    value = 0
  end

  grp.update('1/1/1', value)
end
Reply
#5
(07.06.2016, 06:17)admin Wrote: 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
 value = grp.getvalue('1/1/1') + 1
 
 -- overflow check
 if value > 0xFFFFFFFF then
   value = 0
 end

 grp.update('1/1/1', value)
end

Hi Admin,

Yes you are right, i add the +1 after validation, so it will never be that value

Sorry (;

BR,

Erwin
Reply


Forum Jump: