How to encode expression in Cumulocity AnalyticsBuilder?

Hi,

I want to build an AnalyticsBuilder model for extracting the payload of an event.
For this I parse the string which contains a sequence of integers: “[68,70,71,49,50,0,0,0,27,91,48]”.
In pure EPL I can use sequence<integer>.parse("[80,90]")[0].
How do I have to encode this expression in the AnalyticsBuilder?

Regards Christof

Hi,
It is a little vague as to where the string is coming from like whether it is the stringified version of a json sequence or a literal string. More details on it will be helpful. We can do more with the json if we know its structure.

Thanks,
Sasmita

HI @Christof_Strack , is it resolved, did you find any solution for it or need any assistance?

Thanks,
Sasmita

Hi @anon47495121,
no, I still look for a solution.
My event looks as follows:

{
    "source": {
        "id": "4711"
    },
    "type": "c8y_EK_0_0",
    "time": "SOME_TIMESTAMP",
    "text": "EK belegt",
    "resourcePath": "/19/0/0",
    "deviceName": "1223334444",
    "objectResourcePath_/19/0/0": {},
    "resourceValue": "[180, 60, 40, 30]"
}

… and I want to parse resourceValue, i.e. get 180 as an number.

Regards Christof

Hi @Christof_Strack ,

After you extract the value of “resourceValue” (by using Extract Property block), to extract elements of sequence you need to create a custom block.

If you want to achieve it using standard blocks, you can use Expression block but it’s difficult parsing and extracting elements as there is no decent way to achieve it. Expression block does not support sequence and squqare bracket ([ ])operators. Easiest would be to write a custom block.

If you still want to extract index values using Expression block, it is complicated(and ugly). You can try this way.
Ex:

For index 0: **input1.substring(1.floor(), input1.findFrom(",", 0.floor()))**

For index 1: **input1.substring(input1.findFrom(",", 0.floor())+1.floor(), input1.findFrom(",", input1.findFrom(",", 0.floor())+1.floor()))**

For index 2: **input1.substring(input1.findFrom(",", input1.findFrom(",", 0.floor())+1.floor())+1.floor(), input1.findFrom(",", input1.findFrom(",", input1.findFrom(",",0.floor())+1.floor())+1.floor()))**

substring and findFrom takes integer parameter(see string). But in analytics builder, numeric literals are treated as float values so we need to call .floor() or other comparable methods to convert them to int before passing them to findFrom or substring action.

It becomes complicated , if the sequence length increases and if resourceValue is empty.

So, suggest to use custom block instead of expression block.

Best Regards,
Sasmita

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.