Handling Variables with Same Name in Aggregation Functions #2468
-
Hi everyone, In the following graph rule, i try to compare the average of two temperatures (with same name Temperature) collected from two different devices using EdgeX Foundry but couldn't find a way to filter the inputs of each AVG function. {
"id": "rule1Graph",
"name": "rule1",
"graph": {
"nodes": {
"demo": {
"type": "source",
"nodeType": "edgex",
"props": {
"format": "json"
}
},
"compFilter": {
"type": "operator",
"nodeType": "filter",
"props": {
"expr": "(`Temperature` != nil AND meta(`Temperature`->deviceName)=\"Modbus-1\") or (`Temperature` != nil AND meta(`Temperature`->deviceName)=\"Modbus-2\")"
}
},
"window": {
"type": "operator",
"nodeType": "window",
"props": {
"type": "tumblingwindow",
"unit": "ss",
"size": 30
}
},
"avgfunc": {
"type": "operator",
"nodeType": "aggfunc",
"props": {
"expr": "cast(avg(Temperature) > avg(Temperature), \"boolean\") as comp_result"
}
},
"pick": {
"type": "operator",
"nodeType": "pick",
"props": {
"fields": [
"comp_result"
]
}
},
"logOut": {
"type": "sink",
"nodeType": "log",
"props": {}
},
"edgexOut": {
"type": "sink",
"nodeType": "edgex",
"props": {
"connectionSelector": "edgex.redisMsgBus",
"protocol": "redis",
"server": "localhost",
"port": 6379,
"topic": "edgex/rules-events",
"type": "redis",
"messageType": "event",
"contentType": "application/json",
"deviceName": "ekuiper",
"profileName": "ekuiper"
}
}
},
"topo": {
"sources": [
"demo"
],
"edges": {
"demo": [
"compFilter"
],
"compFilter": [
"window"
],
"window": [
"avgfunc"
],
"avgfunc": [
"pick"
],
"pick": [
"logOut",
"edgexOut"
]
}
}
}
} Thank you for your help |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello everyone, |
Beta Was this translation helpful? Give feedback.
-
Sorry that we forgot to take a look at this. It looks like you have Temperature from two devices. I assume they are in different message, correct? {Temperature: 12, device: 1} then {Temperature: 13, device: 2}. Can you do a pick to rename them right after the source node demo. "renamePick": {
"type": "operator",
"nodeType": "pick",
"props": {
"fields": [
"case when meta(`Temperature`->deviceName)=\"Modbus-1\") then Temperature end as temp1",
"case when meta(`Temperature`->deviceName)=\"Modbus-2\") then Temperature end as temp2"
]
}
}, Then use |
Beta Was this translation helpful? Give feedback.
Sorry that we forgot to take a look at this. It looks like you have Temperature from two devices. I assume they are in different message, correct? {Temperature: 12, device: 1} then {Temperature: 13, device: 2}. Can you do a pick to rename them right after the source node demo.
The…