Esper 规则语言:使用规则的计时器



我想在 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 分钟内没有采取任何步骤,我只希望规则触发。现在,当两个步骤事件具有相同的步骤数时,它将触发。我知道我可能必须使用 timer.interval,但我不知道如何编写此规则。有人可以帮助我吗?

要求定义不明确。"心率高于 120"到底是什么意思,是一次还是 15 分钟或 1 分钟,此外,"心率高于 120"如何与步数条件重叠或巧合。

我建议将问题分解为两个独立的条件检测,然后进行联接以检测这两个条件是否在某个时间发生。这也使测试变得容易,因为您可以看到每个条件都单独指示。例如大致像这样:

// detect the steps condition
insert into StepConditionDetected 
select *, current_timestamp as detectedTime select * from pattern[...];
// detect the heartrate condition
insert into HeartrateConditionDetected 
select *, current_timestamp as detectedTime from pattern[...];
// join step and heartrate condition to see if they co-occur in some way
select * from StepConditionDetected.std:unique(macAddress).win:time(15 min) as a,
HeartrateConditionDetected.std:unique(macAddress).win:time(15 min) as b
where a.macAddress = b.macAddress

您可以在 where-子句中添加连接这两个条件并使用"overlap"来实现一些艾伦区间代数,即"和 a.detecttime.overlaps(b.detectTime, x, y)"

最新更新