fiware - 我怎么能用 Fiware-Perseo-fe 做下面的例子
问题描述
我正在尝试执行以下示例:
我在 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/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”
}
- 然后,我们现在创建一个规则,在累加器中添加一个属性,以指示每次传感器更改其 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}”
}
]
}
}
}
- 我们为 Perseo 订阅所有累加器类型实体的新属性“action”中发生的更改。
发布到 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”
}
- 我们在 Perseo 中创建一个新规则,用于管理新的累加器通知,并根据“action”属性的值修改累加器实体,该属性包含由第一条规则更改的最后一个“typeEvent”值。
发布到 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)
]
}
}
}
我希望我对这个回复有所帮助。
推荐阅读
- java - 使用 MAVEN 在 Databricks Spark Scala AWS 中解析 XML - DailyMed 的 HL7 V3 文件
- imagemagick - ImageMagick Montage:设置图像大小和页面大小
- flutter - 列表的空安全?来自 GET http 请求的不可为空的 Json 映射
- sql - 取消连接列 SQL
- recaptcha - reCaptcha 导致 WordFence 出现问题 - 不想激活 2FA 并且 reCaptcha 分数低 (0.5)
- ios - 显示 int 数组列表的优雅方式
- javascript - 当用户在Vue中注销时重定向到登录页面
- javascript - 从 json 文件中读取未定义的变量
- python - PySide2/PyQt5中如何更改QMediaPlayer的音频输出设备
- python - 使用数据加载器对异常进行批处理