有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案

  1. # 1 楼答案

    这些要求定义不清。“心率高于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”实现一些Allen区间代数,即“和a.detectedTime.overlaps(b.detectedTime,x,y)”