【发布时间】:2016-10-26 21:35:51
【问题描述】:
我正在测试我在 Cumulocity 中编写的一些规则,由于无法获得我想要的结果,我尝试使用 Esper EPL online tool 进行比较。结果我发现两者之间的输出存在我无法解释的差异。
基本上,我想做的是创建一个由源分区并由“开始”和“停止”事件分隔的上下文。然后当我的上下文结束时,我只想显示我的开始和结束事件的一些细节(类型和时间)(我现在不关心中间的事件)。
这是我的规则(必须为 Cumulocity 删除创建模式,因为它们已经“本地”定义):
create schema EventCreated(
source String,
type String,
time Date
);
create schema CreateMeasurement(
source String,
type String,
time Date,
fragments Object
);
@Name("create_context")
create context Trip
context bySource
partition by source from EventCreated,
context byEvents
start EventCreated(
type = "c8y_ObdConnectionReport" or
type = "c8y_PowerOnReport" or
type = "c8y_FixedReport" or
type = "c8y_HarshBehaviorReport") as startEvent
end EventCreated(
type = "c8y_ObdDisconnectionReport" or
type = "c8y_PowerOffReport" or
type = "c8y_SilentTracker") as endEvent;
@Name("context_end")
context Trip
insert into
CreateMeasurement
select
context.bySource.key1 as source,
"Trip" as type,
e.time as time,
{
"startedBy", context.byEvents.startEvent.type,
"startedAt", context.byEvents.startEvent.time,
"endedBy", e.type,
"endedAt", e.time
} as fragments
from
EventCreated e
output
last when terminated;
这里有一个简单的事件序列来看看区别:
EventCreated = {
source = '1672192',
type = 'c8y_ObdConnectionReport',
time = '2016-10-07T10:00:00.000'
}
t = t.plus(5 minutes)
EventCreated = {
source = '1672192',
type = 'c8y_FixedReport',
time = '2016-10-07T10:05:00.000'
}
t = t.plus(5 minutes)
EventCreated = {
source = '1672192',
type = 'c8y_ObdDisconnectionReport',
time = '2016-10-07T10:10:00.000'
}
所以这是使用 EPL 在线模拟器的结果:
At: 2016-10-07 10:05:00.000
Statement: context_end
Insert
CreateMeasurement={
source='1672192',
type='Trip',
time='2016-10-07T10:05:00.000',
fragments[
'startedBy','c8y_ObdConnectionReport',
'startedAt','2016-10-07T10:00:00.000',
'endedBy','c8y_ObdDisconnectionReport',
'endedAt','2016-10-07T10:10:00.000']}
这就是我想要的,我从我的第一个和最后一个活动中得到了预期的详细信息。现在这就是我使用 Cumulocity 得到的结果:
{
"source":{
"id":"1672192",
"name":"Tracker 123456789000000",
"self":"http://tracker.post-iot.lu/inventory/managedObjects/1672192"},
"type":"Trip",
"time":"2016-10-25T11:56:46.983+02:00",
"self":"http://tracker.post-iot.lu/measurement/measurements/null",
"startedBy":"c8y_ObdConnectionReport",
"startedAt":"2016-10-25 11:56:44+0200",
"endedBy":"c8y_FixedReport",
"endedAt":"2016-10-25 11:56:46+0200"
}
(忽略日期,我正在使用 Cumulocity 实时工作)。 如您所见,它认为最后一个事件是 FixedReport 而不是 DisconnectionReport。所以在 Cumulocity 中基本上发生的事情(我尝试过各种情况),每次都会忽略上下文的结束事件,所以我只能检索倒数第二个事件。 p>
这与 Esper 引擎有何不同?我怎样才能使这项工作像我认为的那样工作?
【问题讨论】:
-
我现在对起始事件有同样的问题(我只在使用 context.byEvents.startEvent 时检索第二个)。
标签: esper cumulocity