我如何使用Fiware Perseo fe执行以下示例

我如何使用Fiware Perseo fe执行以下示例,fiware,fiware-orion,fiware-perseo,Fiware,Fiware Orion,Fiware Perseo,我正在尝试执行以下示例: 我在orionCB中创建了两个实体 服务=测试 子服务=/子测试 { "id":"sensor1", "type":"sensor", "id_accumulator":"accumulator1", "typeEvent": 1 //can be 1 or 0 } { "id":"accumulator1", "type":"accumulator", "used":132, "free":8

我正在尝试执行以下示例:

我在orionCB中创建了两个实体

  • 服务=测试
  • 子服务=/子测试

    {    
    "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    
}

当前,上下文代理不允许直接增加属性

我认为您可以使用一些win:time规则来尝试管理这个案例,但是我发现实时保持实体“累加器”中的一致性可能会非常复杂

要仅使用Perseo解决此问题,关键可能是使用允许增加和减少累加器实体属性的规则和订阅的组合

1.首先我们需要订阅Perseo的所有typeEvent属性:

发布到OrionCB_URL/v2/订阅:

   {
     “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”
   }
{
     “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”
   }
  • 对于所有累加器类型的实体,我们订阅Perseo以了解在这个新属性“action”中发生的更改
  • 发布到OrionCB_URL/v2/订阅:

       {
         “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”
       }
    
    {
         “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”
       }
    
  • 我们在Perseo中创建了一个新规则,用于管理新的累加器通知,并根据“action”属性的值修改累加器实体,该属性包含由第一个规则更改的最后一个“typeEvent”值
  • 发布到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}”
                       }
                 ]
             }
          }
       }
    
    {
          “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)
                 ]
             }
          }
       }
    

    我希望我对这个回答有所帮助。

    我在github上写了同样的问题。\u__PerseO有更新CB中属性的操作,但它通常使用固定值,而不是现有值的增量。。。不确定如何利用现有的Perseo和CB功能解决这种情况。可能在向CB发送“固定”更新之前,会在Perseo内存中完成某些内存窗口的值的增加/减少。非常感谢Hello carlos Blanco:你好carlos Blanco,我有另一个问题,现在我使用数字2,如停止累加器,我在EPL的官方文档中找到了控制0,1,2值的方法,但我还没有找到解决方案。你能帮助我吗?请