EPA CEP PROTON中的数组条件

时间:2016-09-29 15:50:06

标签: fiware complex-event-processing fiware-cep

使用CEP Proton我想检查对于在时间间隔内收到的事件,第二个事件和后续事件的id是否包含在第一个事件中的类型数组的属性中。假设第一个事件带有名为group的属性,它是一个整数数组(10,20,30)。以下事件将带有id,ex 20,25等。我想检查这些事件的id是否包含在第一个事件中包含的属性组中。 为此,我在EPA中创建了一个条件

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

但是当我点击验证时出现错误

Error   Error in  EPA: expression error of undefined    myepa

我做错了吗? 我无法使用ArrayGet访问属性数组?或者ArrayContains可能无法使用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"}}

2 个答案:

答案 0 :(得分:1)

请分享您的应用程序的整个JSON定义。

根据您提供的信息,不清楚它是哪种类型的EPA(要访问一系列事件,您需要有状态的EPA,并且您需要确保以这样的方式编写应用程序以便能够区分第一次和后续事件。)

此外,您还不清楚为什么要尝试在表达式的两个部分中访问相同的事件实例 - myevent。

ArrayContains接收(数组,值)作为操作数。 你传递它(值,值),并假设“myevent.id”也是一个数组,从你的描述中我理解它不是?

无论如何,我看到你的表达有很多潜在的问题,因此我希望看到整个JSON,或者至少与“myepa”EPA相关的部分。

答案 1 :(得分:0)

我已经查看了JSON应用程序,存在多个问题: 1)您正在使用聚合类型的EPA来计算COUNT。计数用于计算事件。它是一个整数变量。不能为其分配布尔值。 因此比较表达式如" count == true" 或者分配布尔值,例如:" count:ArrayContains(ArrayGet(gupsyupdate.neighbours,0),ArrayGet(gupsyupdate.id,ArraySize(gupsyupdate.id)-1))" 无效。

2)另外,假设您在某处使用此表达式,而不是在count变量中: -gupsyupdate事件没有属性" id",所以你不能在表达式中使用它。 -ArrayGet(gupsyupdate.neighbours,0) - 将返回一个数组中的单个对象...所以你不能在ArrayContains表达式中使用它,它应该接收一个数组

3)EPA的政策没有意义......它是一个聚合EPA,但你将它与评价策略一起使用"立即"和基数政策"单身"。这意味着这个EPA只会在收到第一个gupsyupdate事件时立即评估一次。所以它不会真正充当聚合器......

请根据此输入修改您的申请。