使用 Esper 查询语言查询道路上汽车的拥堵控制
Congestion Control Query for cars on road using Esper Query Language
我正在接收以下格式的模拟数据:
可以看出,目前有两辆车从 7 号街开往 11 号街(因为它们穿过许多区域,这些区域放置了传感器以监控运动)。
现在我想在 car#1 和 car#2 之间的最新时间差只有 3 秒或更短时停止信号。
我怎样才能用 esper 查询语言做到这一点。
我必须为复杂的事件处理编写一个查询,以便在满足上述条件后立即生成一个事件。
从数据可以看出,最初car#1进入Street#7的时间是42500,而car#2进入Street#7的时间是42508,相差8秒。
{ time: 42500,
location: { Zone: 'Z3', Street: 'Street#7' },
carID: 'car#1' }
---------------------------------------
{ time: 42502,
location: { Zone: 'Z5', Street: 'Street#7' },
carID: 'car#1' }
---------------------------------------
{ time: 42502,
location: { Zone: 'Z1', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42504,
location: { Zone: 'Z4', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42505,
location: { Zone: 'Z5', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42505,
location: { Zone: 'Z1', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42507,
location: { Zone: 'Z4', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z3', Street: 'Street#7' },
carID: 'car#2' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z5', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z1', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z4', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z5', Street: 'Street#7' },
carID: 'car#2' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z1', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z5', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z1', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z4', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z4', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z5', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z1', Street: 'Street#9' },
carID: 'car#2' }
---------------------------------------
{ time: 42513,
location: { Zone: 'Z5', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42513,
location: { Zone: 'Z1', Street: 'Street#12' },
carID: 'car#1' }
---------------------------------------
这听起来有点像汽车 1 的事件与汽车 2 的事件的连接。接下来的问题是要连接哪个事件子集。用例似乎需要保留每辆车经过的街道的一些历史记录。为此,我们可以使用长度 window 或唯一 window 或这些 windows 的并集。让我们使用考虑最近 10 条街道或事件的长度 window。例如这样的查询:
select * from Event(carID="car#1").win:length(20) as car1, Event(carID="car#2").win:length(20) as car2 where Math.abs(car1.time-car2.time) > 3 and car1.Location.Street = car2.Location.Street
我正在接收以下格式的模拟数据: 可以看出,目前有两辆车从 7 号街开往 11 号街(因为它们穿过许多区域,这些区域放置了传感器以监控运动)。
现在我想在 car#1 和 car#2 之间的最新时间差只有 3 秒或更短时停止信号。 我怎样才能用 esper 查询语言做到这一点。 我必须为复杂的事件处理编写一个查询,以便在满足上述条件后立即生成一个事件。 从数据可以看出,最初car#1进入Street#7的时间是42500,而car#2进入Street#7的时间是42508,相差8秒。
{ time: 42500,
location: { Zone: 'Z3', Street: 'Street#7' },
carID: 'car#1' }
---------------------------------------
{ time: 42502,
location: { Zone: 'Z5', Street: 'Street#7' },
carID: 'car#1' }
---------------------------------------
{ time: 42502,
location: { Zone: 'Z1', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42504,
location: { Zone: 'Z4', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42505,
location: { Zone: 'Z5', Street: 'Street#8' },
carID: 'car#1' }
---------------------------------------
{ time: 42505,
location: { Zone: 'Z1', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42507,
location: { Zone: 'Z4', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z3', Street: 'Street#7' },
carID: 'car#2' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z5', Street: 'Street#9' },
carID: 'car#1' }
---------------------------------------
{ time: 42508,
location: { Zone: 'Z1', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z4', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z5', Street: 'Street#7' },
carID: 'car#2' }
---------------------------------------
{ time: 42509,
location: { Zone: 'Z1', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z5', Street: 'Street#10' },
carID: 'car#1' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z1', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42511,
location: { Zone: 'Z4', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z4', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z5', Street: 'Street#8' },
carID: 'car#2' }
---------------------------------------
{ time: 42512,
location: { Zone: 'Z1', Street: 'Street#9' },
carID: 'car#2' }
---------------------------------------
{ time: 42513,
location: { Zone: 'Z5', Street: 'Street#11' },
carID: 'car#1' }
---------------------------------------
{ time: 42513,
location: { Zone: 'Z1', Street: 'Street#12' },
carID: 'car#1' }
---------------------------------------
这听起来有点像汽车 1 的事件与汽车 2 的事件的连接。接下来的问题是要连接哪个事件子集。用例似乎需要保留每辆车经过的街道的一些历史记录。为此,我们可以使用长度 window 或唯一 window 或这些 windows 的并集。让我们使用考虑最近 10 条街道或事件的长度 window。例如这样的查询:
select * from Event(carID="car#1").win:length(20) as car1, Event(carID="car#2").win:length(20) as car2 where Math.abs(car1.time-car2.time) > 3 and car1.Location.Street = car2.Location.Street