我有一个非常简单的模型化问题,而且我没有Esper的经验,所以我可能会走错路,所以我想要一些见解。
这里是场景:我有一个事件流" ParkingEvent",有两种类型的事件" SpotTaken"和#34; SpotFree"。所以我有一个Esper context ,它们都按id分区,并以" SpotTaken"类型的起始事件为界。和#34; SpotFree"类型的结束事件。我们的想法是使用传感器监控停车位,然后汇总数据以计算现场拍摄的次数以及占用时间。
它是,没有时间窗口或任何时间,所以看起来很简单,但我很难聚合数据。这是我到目前为止的代码:
create context ParkingSpotOccupation
context PartionBySource
partition by source from SmartParkingEvent,
context ContextBorders
initiated by SmartParkingEvent(
type = "SpotTaken") as startEvent
terminated by SmartParkingEvent(
type = "SpotFree") as endEvent;
@Name("measurement_occupation")
context ParkingSpotOccupation
insert into CreateMeasurement
select
e.source as source,
"ParkingSpotOccupation" as type,
{
"startDate", min(e.time),
"endDate", max(e.time),
"duration", dateDifferenceInSec(max(e.time), min(e.time))
} as fragments
from
SmartParkingEvent e
output
snapshot when terminated;
我得到了最小和最大的相同数据,所以我猜测我做错了。
当我使用context.ContextBorders.startEvent.time和context.ContextBorders.endEvent.time而不是min和max时,不会触发measurement_occupation语句。
答案 0 :(得分:0)
鉴于已经通过您提供的EPL计算了测量值,这将计算拍摄(和释放)点的总次数并总计持续时间:
select source, count(*), sum(duration) from CreateMeasurement group by source