我正在尝试执行以下示例:
我在orionCB中创建了两个实体。
subservice = / subtest
{
"id":"sensor1",
"type":"sensor",
"id_accumulator":"accumulator1",
"typeEvent": 1 //can be 1 or 0
}
{
"id":"accumulator1",
"type":"accumulator",
"used":132,
"free":83,
"total":215
}
规则应为:
1.-如果typeEvent为1,则used属性将为加1,而free属性将为小于1
2.-如果typeEvent为0,则used属性将小于1,而free属性将为加1
是否可以使用perseo规则和订阅?
更多信息:
执行规则后,结果将是:
-----> typeEvent:1
{
"id":"accumulator1",
"type":"accumulator",
"used":133,
"free":82,
"total":215,
}
---> typeEvent:0
{
"id":"accumulator1",
"type":"accumulator",
"used":131,
"free":84,
"total":215
}
答案 0 :(得分:1)
当前,上下文代理不允许直接增加属性。
我认为您可以使用“ win:time”规则来尝试处理这种情况,但是我认为实时保持实体“累加器”的一致性可能非常复杂。
要仅使用Perseo来解决此问题,也许关键是使用规则和订阅的组合,以允许增加和减少累加器实体的属性。
1。首先,我们需要将Perseo订阅所有typeEvent属性:
POST到OrionCB_URL / v2 / subscriptions:
{
“description”: “Notify Perseo when typeEvent changes”,
“subject”: {
“entities”: [
{
“idPattern”: “.*“,
“type”: “sensor”
}
],
“condition”: {
“attrs”: [
“typeEvent”
]
}
},
“notification”: {
“http”: {
“url”: “<perseoHost>/notices”
},
“attrs”: [
“typeEvent”,
“id”,
“id_accumulator”
]
},
“expires”: “2019-06-30T14:00:00.00Z”
}
POST到PERSEO_URL /规则:
{
“name”:“changeInAcumulator”,
“text”:“select \“changeInAcumulator\” as ruleName, ev.id_accumulator? as id_accumulator, ev.typeEvent? as typeEvent from pattern [every ev=iotEvent(type=\“sensor\“)]“,
“action”:{
“type”:“update”,
“parameters”:{
“id”:“${id_accumulator}“,
“type”:“accumulator”,
“attributes”: [
{
“name”:“action”,
“value”:“${typeEvent}”
}
]
}
}
}
POST到OrionCB_URL / v2 / subscriptions:
{
“description”: “Notify Perseo when accumulator changes”,
“subject”: {
“entities”: [
{
“idPattern”: “.*“,
“type”: “accumulator”
}
],
“condition”: {
“attrs”: [
“action”
]
}
},
“notification”: {
“http”: {
“url”: “http://host.docker.internal:9090/notices”
},
“attrs”: [
“id”,
“free”,
“used”,
“action”
]
},
“expires”: “2019-06-30T14:00:00.00Z”
}
POST到PERSEO_URL /规则:
{
“name”:“updateAcumulator”,
“text”:“select \“updateAcumulator\” as ruleName, ev.id? as id, case cast(cast(ev.action?,String),float) when 1 then cast(cast(ev.free?,String),float)-1 else cast(cast(ev.free?,String),float)+1 end as free, case cast(cast(ev.action?,String),float) when 1 then cast(cast(ev.used?,String),float)+1 else cast(cast(ev.used?,String),float)-1 end as used from pattern [every ev=iotEvent(type=\“accumulator\“)]“,
“action”:{
“type”:“update”,
“parameters”:{
“id”:“${id}“,
“type”:“accumulator”,
“attributes”: [
{
“name”:“free”,
“value”:“${free}”
},
{
“name”:“used”,
“value”:“${used}”
} (editado)
]
}
}
}
我希望我对此做出了帮助。