Issue with computed attributes and warnings

Victor Butler5 years ago

Hi Anton,

Just discovered an issue with computed attributes, and no matter what variations of the formula I try, nothing seems to work. See below:

The problem is when we have an element that can have value of 0 and is not always reported. Let's say we have io30:

Case 1:
io30 is repored by the device as 100;
Formula: io30 ? io30 : null
Computed attribute = 100.
All ok.

Case2:
io30 is repored by the device as 0;
Formula: io30 ? io30 : null
Computed attribute is missing. That is because the formula io30 ? evaluates the 0 as null and the returned value is null.

Case3 - modifying the above formula to treat the 0 as valid value:
io30 is repored by the device as 0;
Formula: (io30 || io30 ==0) ? io30 : null
Computed attribute = 0. This formula works when the io30 is being reported.

However, if io30 is not reported with the above formula I get warning message in the traccar log:
WARN: Attribute computation error - org.traccar.handler.ComputedAttributesHandler.computeAttribute@102![0,5]:

So the problem is:
With the formula in Case2, there is no warning message but if io30 == 0, then the computed attribute is not recorded.
With the formula in Case3, if io30 == 0 the value is recorded but I get a warning message.

This is what I also tried but does not work:
io30 != "" ? io30 : null
!empty(io30) ? io30 : null
io30 ? (io30 != "" ? io30 : null) : null
if( io30 || io30 == 0 ) { io30; else null; }

It seems it's not the formula but the fact that Traccra treats the 0 when evalued as null;

Any suggestion or idea how to fix this problem?

Ananda year ago

Any solution for the above issue? I got in to the same issue.