Logging on value change
-
If a meta point update is triggered and the new value in context is the same as the value last logged for this point, does the logger consider this value changed and to be logged as well?
-
As reading through the help :
When point value changes is the default logging setting. The point value and its time of occurrence is written to the database only if the value of the point actually changes. This setting provides the best compromise of quality of historical information vs storage space efficiency. For Numeric points, a Tolerance, or "deadband", can also be provided; the value will be logged if the absolute value of the difference between the present value and the previous value equals or exceeds the given tolerance.
I would suggest to use The When point timestamp changes setting which is similar in behaviour to the on value change setting, but the timestamp of the sample is compared instead of the value to save all triggers to Mango database.
Thomas
-
That wholly depends on your preferred context setting. If you want updates with the timestamp, use update for the context, otherwise set to change instead.
change the dropdown under the meta point script for context to only work on changes as opposed to value updates.
To
However to make things easier for yourself and ensure your values are the same and prevent running code as well, you could run a series of if statements to check if
point.value!==point.lastValue
and simply return the metapoint's current value if the statement is false.
That's my ten cents worth.
Fox
-
Thanks guys!
If the documentation Thomas provided still leaves questions, one can see exactly how the ON_CHANGE logging type will behave in the DataPointRT class for the different data types: https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/serotonin/m2m2/rt/dataImage/DataPointRT.java#L283
However to make things easier for yourself and ensure your values are the same and prevent running code as well, you could run a series of if statements to check if
point.value!==point.lastValue
and simply return the metapoint's current value if the statement is false.I would add that
point.value!==point.lastValue
is pseudocode, and while it will run in a Mango JavaScript environment I would expect it always to be false (lastValue is a function)consider,
print(p.value); //let's say 1 print(p.lastValue().doubleValue); //also 1 print(typeof p.lastValue(1).doubleValue); //'number' print(typeof p.lastValue(1)); //'object' print(typeof p.value); //'number' print(typeof p.lastValue); //'function' print(p.value === p.lastValue) //false print(p.value === p.lastValue(1, true).doubleValue) //true this time, not-pseudocode (for numeric points)
Also note that lastValue(0) would be the last, logged value. So +1 is the value before that.
-
@phildunlap cheers phil!
-
Are these statements equivalent?
Counter Context update
var values= Counter.last(2);
var INCREMENT = Counter.value - values[0].value;
var INCREMENT = Counter.value - Counter.pointValueBefore(values[0].time).value; -
In your first,
var INCREMENT = Counter.value - values[0].value;
Did you mean
var INCREMENT = Counter.value - values[1].value;
?Again you probably want to use .doubleValue since I would guess
typeof values[0].value === 'object'
As of Mango 3.5 the JavaScript context point functions are not using the cache (unless told to, like
var values = p.last(2, true);
), so yes I would expect those to be equivalent. Getting deeply into this might involve understanding the last comment in this git issue: https://github.com/infiniteautomation/ma-core-public/issues/1305 -
AHHH I upgraded to 3.5 and saw the meta data go wild. So I rolled it back to 3.4 and restored a backup. Hence the Excel Schema warning.
We have not use the logged event to trigger any meta point updates.
So changing the meta points to use p.last(2, true) enables cache and script will work after we update to 3.5?
I assume last(2,true) only works in mango 3.5 correct? -
I would think so. Cache control on the functions was added in 3.5. Prior to that they were always using the cache.