Computed Attributes - JEXL Expression

shahab2 years ago

Hello,
I am getting speed and ignition in postion attributes and through computed attributes i want to get device_status

  1. Running when speed>3 and ignition=true
  2. Idle when speed<3 and ignition = true
  3. stopped when speed<3 and ignition = false
  4. No Data when no above condition match

Now i know computed attributes expression are written in JEXL and i am no expert in the same but still i have tried and it was not working

attributes = device_status
Expression = speed > 3 && ignition==true? Running:speed<3&&ignition==true?Idle:speed<3 && ignition ==false:Stopped:NO_DATA
type= string

this is the error which is showing

org.traccar.handler.ComputedAttributesHandler.computeAttribute:119@1:94 parsing error in ':' - Parsing (ComputedAttributesHandler:119 < AttributeResource:63 < ...)

I was not able to find learning resource on JEXL so if anyone knows JEXL or know how to solve this, then please help

Anton Tananaev2 years ago

The link to JEXL format is available in our documentation:

https://commons.apache.org/proper/commons-jexl/reference/syntax.html

memesaregood2 years ago

You can try nesting the conditions:
ignition ? speed > 3 ? Running : Idle : speed < 3 ? Stopped : No Data