JavaESPER规则语言:使用计时器进行规则更新
我想在Esper中编写一条规则,当过去15分钟内的步数为0且心率高于120时触发。我提出了以下规则:
EPStatement cepStatementRule8 = cepRule.createEPL("context PartitionByMacSteps select * from "
+ "Steps.win:time(15 min) S, HeartRate.win:time(1 min) H "
+ "having (max(S.steps)-min(S.steps) = 0) and (H.heartrate > 120)");
cepStatementRule8.addListener(new rule8Listener());
我的心率类别包含以下字段:
int heartrate;
String heartratesTimestamp;
String macAddress;
我的步骤类有以下字段:
int steps;
String stepsTimestamp;
String macAddress;
我面临的问题是,如果在最后15分钟内没有采取任何措施,我只想启动规则。现在,当两个步骤事件的步骤数相同时,它将触发。我知道我可能得用定时器。但是我不知道如何写这个规则。有人能帮我吗
# 1 楼答案
这些要求定义不清。“心率高于120”的真正含义是什么?它是一次还是15分钟或1分钟?此外,“心率高于120”是如何重叠的,还是与条件一致的
我建议将问题分解为两个独立的条件检测,然后进行连接,以检测这两个条件是否在某个时间发生。这也使得测试变得容易,因为您可以看到每个条件都被单独指示。例如,大致如下:
您可以在where子句中添加这两个条件,并使用“overlap”实现一些Allen区间代数,即“和a.detectedTime.overlaps(b.detectedTime,x,y)”