简体   繁体   中英

Array Condition within EPA CEP PROTON

Using CEP Proton I want to check if, for the events received in a time interval, the id of the second and following events is contained in an attribute of type array coming in the first event. Let's say the first event is coming with the attribute called group that is an array of integers (10, 20, 30). The following events will come with an id, ex 20, 25 and so on. I want to check if the id of those events is included in the attribute group included in the first event. For that I have created a condition in EPA

ArrayContains(ArrayGet(myevent.group,0),ArrayGet(myevent.id,ArraySize(myevent.id)-1))

However I'm getting an error when I click on verify

Error   Error in  EPA: expression error of undefined    myepa

Am I doing anything wrong? Cannot I access to the attribute array using ArrayGet ? Or maybe ArrayContains cannot work with the result of ArrayGet ?

JSON

{"epn":{"events":[{"name":"GupsyContextUpdate","createdDate":"Thu Sep 29 2016","attributes":[{"name":"entityId","type":"String","dimension":0},{"name":"entityType","type":"String","dimension":0,"description":"The cost of this event occurrence. Negative if this is an opportunity"},{"name":"SF","type":"Integer","dimension":0,"description":"Used in case the this event occur within an interval"},{"name":"occupied","type":"Integer","dimension":"0"},{"name":"framecounter","type":"Integer","dimension":"0"},{"name":"RSSI","type":"String","dimension":"0"},{"name":"hwversion","type":"String","dimension":"0"},{"name":"swversion","type":"String","dimension":"0"},{"name":"compassz","type":"String","dimension":"0"},{"name":"MACBS","type":"String","dimension":"0"},{"name":"SNR","type":"String","dimension":"0"},{"name":"devEUI","type":"String","dimension":"0"},{"name":"battery","type":"String","dimension":"0"},{"name":"devicetype","type":"String","dimension":"0"},{"name":"compassx","type":"String","dimension":"0"},{"name":"compassy","type":"String","dimension":"0"},{"name":"compasst","type":"String","dimension":"0"},{"name":"neighbours","type":"String","dimension":"1"},{"name":"timestamp","type":"String","dimension":"0"}]},{"name":"gupsyoutput","createdDate":"Thu Sep 29 2016","attributes":[{"name":"Certainty","type":"Double","defaultValue":"1","dimension":0,"description":"The certainty that this event happen (value between 0 to 1)"},{"name":"OccurrenceTime","type":"Date","dimension":0,"description":"No value means it equals the event detection time, other option is to use one of the defined distribution functions with parameters"},{"name":"ExpirationTime","type":"Date","dimension":0},{"name":"Cost","type":"Double","dimension":0,"description":"The cost of this event occurrence. Negative if this is an opportunity"},{"name":"Duration","type":"Double","defaultValue":"0","dimension":0,"description":"Used in case the this event occur within an interval"},{"name":"test","type":"String","dimension":"1"}]}],"epas":[{"name":"gupsyepa","createdDate":"Thu Sep 29 2016","epaType":"Aggregate","context":"gupsyct","inputEvents":[{"name":"GupsyContextUpdate","alias":"gupsyupdate","consumptionPolicy":"Consume","instanceSelectionPolicy":"First"}],"computedVariables":[{"name":"count","aggregationType":"Count","gupsyupdate":"ArrayContains(ArrayGet(gupsyupdate.neighbours,0),ArrayGet(gupsyupdate.id,ArraySize(gupsyupdate.id)-1))"}],"assertion":"count == true","evaluationPolicy":"Immediate","cardinalityPolicy":"Single","internalSegmentation":[],"derivedEvents":[{"name":"gupsyoutput","reportParticipants":false,"expressions":{"Duration":"0","test":"ArrayContains(ArrayGet(gupsyupdate.neighbours,0),ArrayGet(gupsyupdate.devEUI,ArraySize(gupsyupdate.devEUI)-1))"}}]}],"contexts":{"temporal":[{"name":"gupsyct","createdDate":"Thu Sep 29 2016","type":"TemporalInterval","atStartup":false,"neverEnding":false,"initiators":[{"initiatorType":"Event","initiatorPolicy":"Ignore","name":"GupsyContextUpdate"}],"terminators":[{"terminatorType":"RelativeTime","terminationType":"Terminate","relativeTime":"15000"}]}],"segmentation":[],"composite":[]},"consumers":[{"name":"gupsyconsumer","createdDate":"Thu Sep 29 2016","type":"Rest","properties":[{"name":"URL","value":"http://127.0.0.1/ProtonParser/TestEvent2Log.php"},{"name":"contentType","value":"application/xml"},{"name":"formatter","value":"xml"},{"name":"delimiter","value":";"},{"name":"tagDataSeparator","value":"="},{"name":"dateFormat","value":"dd/MM/yyyy-HH:mm:ss"}],"events":[{"name":"gupsyoutput"}]}],"producers":[],"name":"gupsy"}}

Please share the whole JSON definition of your application.

From the information you have provided it is not clear which type of EPA it is (to access a series of events you need a statefull EPA and you need to make sure you write the application in such a way as to be able to distinguish between the first and subsequent events).

Additionally it is not clear why you try to access the same event instance- myevent in both parts of the expression.

ArrayContains recieves (array, value) as operands. You pass it (value, value), and thats assuming that "myevent.id" is also an array, which from your description I understood it is not?

Anyway, I see lots of potential problems with your expression, therefore I would like to see the whole JSON, or at least the part relevant to the "myepa" EPA.

I have reviewed the JSON application, there are multiple problems: 1)You are using an EPA of type aggregate, to calculate a COUNT. Count is for counting events. It is an integer variable. No boolean values can be assigned to it. Therefore comparison expressions like "count == true" Or assigment of boolean values like : "count : ArrayContains(ArrayGet(gupsyupdate.neighbours,0),ArrayGet(gupsyupdate.id,ArraySize(gupsyupdate.id)-1))" Are not valid.

2)Additionally, assuming you use this expression somewhere, and not in count variable: -the gupsyupdate event has no attribute "id", so you cannot use this in an expression. -ArrayGet(gupsyupdate.neighbours,0) - will return a single object within an array... So you cannot use it in ArrayContains expression which is supposed to receive an array

3)The policies of the EPA doesn't make sense... It is an aggregation EPA, but you use it with evaluationPolicy of "Immediate" and cardinality policy "Single". That means this EPA will be evaluated only once, immediately as it receives the first gupsyupdate event. So it will not really act as aggregator....

Please revise your application according to this input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM