如何获得“仅重大事件”?

时间:2018-11-19 17:16:35

标签: esper

我有传感器报告事件。每个事件都有唯一的设备ID,一些测量值以及报告序列ID(仅用于调试)。

我只想获取重要的事件(即它们的测量值是迄今为止观测到的最大值的两倍),所有这些都基于时间-即我想获取第一个事件,然后在时间段T中阻止N个后续事件,除非其中一个事件的有效负载很大。 我设法通过这种方式完成了(或多或少):

create schema Alerts(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alerts;

create constant variable int WindowTimeSec = 29;

@Name('Out') 
context SegmentedByAsset 
select e2 from Alerts.win:time(WindowTimeSec sec).std:firstevent() as e1, 
               Alerts.std:lastevent() as e2 
where e2.seq = e1.seq or e2.load > 2* (select max(prev(load)) 
from Alerts.win:time(WindowTimeSec sec))
  • 首先-这很丑。
  • 第二个-我有种“胆量”,感觉效率不是很高。
  • 第三-如果特殊事件检测的条件变得更复杂,则简单的子查询将无法工作(即,除了load事件还将具有更多属性,例如时间和类型,我需要比较时间和类型具有最大负载的事件,以决定是否应发布或阻止上一个事件。

推荐的模式是什么?

10x

2 个答案:

答案 0 :(得分:1)

您可以设计一个表行来保存聚合,并使用@priority表示更新时间。

create schema Alert(feeder string, load double, seq int);
create context SegmentedByAsset partition by feeder from Alert;

create constant variable int WindowTimeSec = 29;

context SegmentedByAsset create table LoadAggTable(maxLoad max(double)); 

// select first (priority is 1)
@name('out') @priority(1) context SegmentedByAsset select * from Alert where load > LoadAggTable.maxLoad;

// update table next (priority is 0)
@priority(0) context SegmentedByAsset into table LoadAggTable select max(load) as maxLoad from Alert#time(WindowTimeSec sec);

该表可以包含“ maxBy”,这也是贡献最大或其他聚合的事件。

答案 1 :(得分:0)

我想出了一些基于Windows的东西(以前的答案,建议使用带有聚合列的表,也许可以,但是我不明白为什么:))

$.ajax({
   type: 'POST',
   url: 'submit1.php',
   data: $("#regist").serialize(),
   dataType: 'json',
   success: function() {
      $("#loading").append("<h2>you are here</h2>");
   },
   error: function(jqXhr, textStatus, errorMessage){
      console.log("Error: ", errorMessage);
   }
});

从本质上讲,它只会在命名窗口中保留过去WindowTimeSec时段内具有最大负载的事件,如果新事件具有更大的负载,它将被发布,如果时间段到期且命名窗口为空-任何新事件都将被发布。这并不完全是我的初衷,但是对于此特定用例而言,它也可以正常工作,并且“旁路条件”可以具有任何复杂性,因为完整的事件数据都保存在窗口中。