Things Cloud で書いたいくつかのルールをテストしていましたが、望む結果が得られなかったので、比較のためにEsper EPL オンライン ツールを使用してみました。説明できない 2 つの出力の違いが見つかりました。
基本的に、私がやりたいことは、ソースによって分割され、「開始」イベントと「停止」イベントで区切られたコンテキストを作成することです。次に、コンテキストが終了したら、開始イベントと終了イベントのみの詳細 (タイプと時間) を表示したいと思います (現時点では、その間のイベントは気にしません)。
これが私のルールです (作成スキーマは既に「ネイティブに」定義されているため、Things Cloud では削除する必要があります):
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']}
これは私が望むものです。期待どおり、最初と最後のイベントから詳細を取得しました。これが私が Things Cloud で得たものです:
{
"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"
}
(日付は無視してください。私は Things Cloud でリアルタイムで作業しています)。ご覧のとおり、最後のイベントは、DisconnectionReport ではなく FixedReport であると見なされます。つまり、Things Cloud で基本的に発生すること (さまざまな状況を試しました) は、コンテキストの終了イベントが毎回無視されるため、最後から 2 番目のイベントしか取得できないということです。
エスパーエンジンとの違いは?私が思うようにこれを機能させるにはどうすればよいですか?