Logic Machine Forum
Log only objects changes / remove storage files - 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: Log only objects changes / remove storage files (/showthread.php?tid=406)



Log only objects changes / remove storage files - gtsamis - 02.10.2016

Good evening,

I need some help regarding object logging.

I have some objects that frequently sends group writes even without a value change.
Those objects are logged on the LM's Object Log and I am ending up with a bunch of records without any changes.
Is there any way that the logging will only happen if the object changes it's value?

Also can someone point the storage file location in order to remove unused ones?

Thank you in advance
George


RE: Log only objects changes / remove storage files - admin - 03.10.2016

The only solution that I see is that you create another object for each one you want to log and then filter the input value in an event script.

Add this to Common functions:
Code:
function checkupdate(sendto, mindelta)
  -- event value
  local newvalue = event.getvalue()
  -- current object value
  local curvalue = grp.getvalue(sendto)
  -- absolute delta between event and current value
  local valdelta = math.abs(curvalue - newvalue)
  -- send if delta value is large enough
  if valdelta >= mindelta then
    grp.update(sendto, newvalue)
  end
end

Create an event script for each object where you want to log only value changes. 1/1/1 is your "virtual" object which is logged, 2 is minimum delta between current "virtual" object value which causes new value to be sent. Adjust as needed.
Code:
checkupdate('1/1/1', 2)

As for storage, do you mean script storage? In newer releases it's stored in a separate database and there's no easy way to delete some of the entries unless you know all of their names. You can only do a full clear operation.


RE: Log only objects changes / remove storage files - gtsamis - 03.10.2016

(03.10.2016, 07:11)admin Wrote: The only solution that I see is that you create another object for each one you want to log and then filter the input value in an event script.

Add this to Common functions:
Code:
function checkupdate(sendto, mindelta)
 -- event value
 local newvalue = event.getvalue()
 -- current object value
 local curvalue = grp.getvalue(sendto)
 -- absolute delta between event and current value
 local valdelta = math.abs(curvalue - newvalue)
 -- send if delta value is large enough
 if valdelta >= mindelta then
   grp.update(sendto, newvalue)
 end
end

Create an event script for each object where you want to log only value changes. 1/1/1 is your "virtual" object which is logged, 2 is minimum delta between current "virtual" object value which causes new value to be sent. Adjust as needed.
Code:
checkupdate('1/1/1', 2)

As for storage, do you mean script storage? In newer releases it's stored in a separate database and there's no easy way to delete some of the entries unless you know all of their names. You can only do a full clear operation.
Thank you for the answer, unfortunately for object logging it doesn't seem optimized solution, probably i will switch to general logging where i can filter what and when to log it.
By the way, is there any way i could check objects previous state before the database update and without using storage?


For the second question I mean storage used by storage.get and storage.set
Thank you in advance
George


RE: Log only objects changes / remove storage files - admin - 03.10.2016

Well, object log main purpose is to log all telegrams. If you want to log changes you can try using trends instead. Each event script is executed only after new value has been updated in the database, so you should use storage or another object if you want to get previous value.

New firmware has storage.keys funciton which returns keys for all known storage items.


RE: Log only objects changes / remove storage files - gtsamis - 03.10.2016

(03.10.2016, 09:14)admin Wrote: Well, object log main purpose is to log all telegrams. If you want to log changes you can try using trends instead. Each event script is executed only after new value has been updated in the database, so you should use storage or another object if you want to get previous value.

New firmware has storage.keys funciton which returns keys for all known storage items.

Is there any way to completely remove a storage key that not longer used?


RE: Log only objects changes / remove storage files - admin - 03.10.2016

storage.delete(key)