簡體   English   中英

如何在Esper中正確創建閾值警報語句

[英]How to properly create a threshold alert statements in Esper

我正在嘗試創建一組EPL語句,以允許引擎在值未超過閾值時發出警報。 理解它的另一種方式就像是“柵欄”或地理圍欄。

該語句集必須在值進入或離開該區域時發出警報。 例如,只有當值大於45或小於或等於45時,下一個“圍欄”值> 45才必須發出警報,但只有當值超過閾值時才發出警報。

這是一個I / O示例。 對於保存屬性距離且圍柵距離> 45的DistanceEvents。

輸入項

DistanceEvents={distance=50}

DistanceEvents={distance=40}

DistanceEvents={distance=33}

DistanceEvents={distance=60}

DistanceEvents={distance=55}

DistanceEvents={distance=45}

DistanceEvents={distance=15}

產出

1 - output= {distance=50.0}
2 - output= {a.distance=50.0, b.distance=40.0}
3 - output= {a.distance=40.0, b.distance=60.0}
4 - output= {a.distance=60.0, b.distance=45.0}

有人可以幫我嗎?

我想出了以下。 我沒有為您測試過。 使用@Audit調試是否無效。 優化后,請發布最終的EPL。

create schema Event(distance double);

create table CurrentStateTable(inside boolean);

on Event(distance > 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select false as inside
  when matched and cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = false;

on Event(distance < 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select true as inside
  when matched and not cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = true;

select * from AlertStream; // listen here for alerts

這工作正常:

create schema DistanceEvents(distance double);
create table CurrentStateTable(inside boolean);

insert into CurrentStateTable select true as inside from DistanceEvents(distance>45)#firstevent;


on DistanceEvents(distance > 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select false as inside
  when matched and cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = false;


on DistanceEvents(distance <= 45) as arriving merge CurrentStateTable as cst
  when not matched then 
    insert select true as inside
  when matched and not cst.inside
    then insert into AlertStream select arriving.distance
    then update set inside = true;


select * from AlertStream; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM