简体   繁体   English

WSO2 CEP-Siddhi查询将不同事件流的坐标关联起来

[英]WSO2 CEP - Siddhi queries correlate coordinates of different event streams

I'm new to WSO2 CEP and Siddhi queries. 我是WSO2 CEP和Siddhi查询的新手。 I have created three different event streams, each stream is about an particular sensor, as shown in the image below: 我创建了三个不同的事件流,每个流都与一个特定的传感器有关,如下图所示:

在此处输入图片说明

Each event stream of sensors has the latitude and longitude of the sensor. 传感器的每个事件流都具有传感器的纬度和经度。 The sensors placed on different coordinates and I want to compare/correlate their coordinates (latitude and longitude). 传感器放置在不同的坐标上,我想比较/关联它们的坐标(纬度和经度)。 How can I compare their coordinates through Siddhi query (coordinates do not vary by more than 4 meters)? 如何通过Siddhi查询比较坐标(坐标相差不超过4米)? Thanks a lot! 非常感谢!

Siddhi has a separate set of operations for geo operations. 西提有一组独立的操作进行地理操作。 To calculate the distance between the sensors, you will be able to use geo distance function . 要计算传感器之间的距离,您将可以使用地理距离功能

Since you want to compare the sensor distance, you will have to keep the sensor locations in a window or in a table . 由于要比较传感器距离,因此必须将传感器位置保持在窗口表格中 Whenever a sensor location comes in the stream, you will be able to store it in the window or in the table, and join with the rest of the table contents and get the relevant output adheres to your requirement(within 4 meters) 每当传感器位置出现在流中时,您都可以将其存储在窗口或表格中,并与表格的其余内容结合在一起,并获得符合您要求的相关输出(4米之内)

/* Enter a unique ExecutionPlan */
@Plan:name('ExecutionPlan')

/* Enter a unique description for ExecutionPlan */
-- @Plan:description('ExecutionPlan')

/* define streams/tables and write queries here ... */

@Import('sensor4:1.0.0')
define stream sensor4 (id int, lat double, long double);

@Import('sensor3:1.0.0')
define stream sensor3 (id int, lat double, long double);

@Import('sensor2:1.0.0')
define stream sensor2 (id int, lat double, long double);

@Import('sensor1:1.0.0')
define stream sensor1 (id int, lat double, long double);

@Export('measuredStream:1.0.0')
define stream measuredStream (sensor1Id int, sensor2Id int);

define table sensorTable (id int, lat double, long double);

from sensor1
select *
insert into sensorTable;

from sensor2
select *
insert into sensorTable;

from sensor1 join sensorTable
    on sensorTable.id != sensor1.id and 4 > geo:distance(sensorTable.lat, sensorTable.long, sensor1.lat, sensor1.long)
select sensorTable.id as sensor1Id, sensor1.id as sensor2Id
insert into measuredStream;

from sensor2 join sensorTable
    on sensorTable.id != sensor2.id and 4 > geo:distance(sensorTable.lat, sensorTable.long, sensor2.lat, sensor2.long)
select sensorTable.id as sensor1Id, sensor2.id as sensor2Id
insert into measuredStream;

The above execution plan will work, since you have after you create 2 more queries each to insert to the event table and join with event table. 上面的执行计划将起作用,因为您在创建2个以上的查询后将分别插入事件表并与事件表联接。 You can verify the results by adding a logger publisher(the events in the measured stream will be logged in the terminal) to the measured stream. 您可以通过将记录器发布者(测得的流中的事件将记录在终端中)添加到测得的流中来验证结果。 And using event simulator, simulate the event flow. 并使用事件模拟器来模拟事件流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM