You can't have ifs, but you can have ternary expressions.
Thank you Anton. I tried to play with ternary expressions but it throws the error message below.
org.traccar.processing.ComputedAttributesHandler.computeAttribute@6:1 parsing error near '... io1==260&&i ...' - Parsing (... < ComputedAttributesHandler:86 < AttributeResource:51 < ...)
I use the following expression in expression field. Attribute is set to "Operator" and type to "Text".
io1==260&&io2==01?"Plus":
io1==260&&(io2==02||io2==34)?"T-Mobile":
io1==260&&(io2==03||io2==05)?"Orange":
io1==260&&(io2==04||io2==15)?"Tele2":
io1==260&&(io2==06||io2==07||io2==98)?"Play":
:false
First of all, I would recommend adding spaces between everywhere. Secondly, I would recommend removing new lines. If it still doesn't work you should try to start with smaller expression and add on top of that.
OK, looks like the spaces did the trick... don't even know why... Anyway, the following code works.
io1==260 && io2==01 ? "Plus" :
io1==260 && ( io2==02 || io2==34 ) ? "T-Mobile" :
io1==260 && ( io2==03 || io2==05 ) ? "Orange" :
io1==260 && ( io2==04 || io2==15 ) ? "Tele2" :
io1==260 && ( io2==06 || io2==07 || io2==98 ) ? "Play" :
false
Now, how can I make it visible on my Status and Location tab? I would like to hide the io1 and io2 and instead display the newly created attribute called "GSM network".
You can hide attributes. Check user attributes.
Thanks. Yes that did the trick with hiding the io1 and io2 attributes. I did that on the Server configuration - not user.
However, I still can't get the new "GSM network" (operator) attribute to be visible in "status and location" tab for a certain device.
It probably means your device doesn't report those io values.
That was not the case. I just realized that computed attributes only works on new data. So, it doesn't compute the attributes on the fly whenever I'm showing the location in UI.
That's not what I expected but it's acceptable.
Thank you once again. We can close the topic for now.
Dear all,
I'm using H02 protocol. My tracker return the following additional data:
io1 - MCC
io2 - MNC
io3 - LAC
io4 - CID
Instead of presenting RAW values in the localisation I want to implement some logic and processing to those values.
i.e.
when seeing below values:
Io1 - 260
Io2 - 06
Io3 - 01211
Io4 - 19573
I want to replace the io1 and io2 in the screen and display only a "GSM Network Name". In above case 260 06 translated to Play GSM network.
Also translating LAC and CID to coordination would be usefull.
I tried to play with computed attributes without success. Looks like the expression doesn't accept multiple "if's" or case statement.
Can you please help me?
Thanks