流口水仅对插入事件触发规则 [英] Drools rule fire only for inserted event

查看:95
本文介绍了流口水仅对插入事件触发规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每个传感器都有多种用途,可以发送计步器数据。我有一个基于macAddress的规则文件,将触发该规则:

I have a multiple uses with each a sensor that sends pedometer data. I have a rule file that based on the macAddress, fires the rule:

declare Steps
    @role(event)
end

declare User
    @role(fact)
end

rule "MAC"
when
  User( $mac: macAddress ) from entry-point "entrySteps"
then end

rule "ACC STEPS RULE" extends "MAC"
when
    accumulate( Steps( $s : steps , macAddress == $mac )
            over window:time( 1h ) from entry-point "entrySteps"; 
        $fst: min( $s ), $lst: max( $s );
        $lst - $fst < 50 )
then
    System.out.println($lst + "   " + $fst);
    Action.handleAction($mac,"STEPS RULE: get moving!");
end

我的用户只有一个字段 macAddress 和Steps事件具有以下字段:

My User has just a field macAddress and Steps events have the following fields:

double steps;
Date timeStamp;
String macAddress;

现在,当我插入一个事件,然后为每个 macAddress插入规则时,如果具有该macAddress的用户在过去一小时内的步数少于50,则触发该事件。因此,如果满足此条件,则将为每个macAddress触发该规则。
但我希望该规则只能对插入的Step事件的macAddress触发。我该如何调整规则?

Now when I insert an event then for each macAddress, the rule will fire if the number of steps of a user with that macAddress in the last hour is less then 50. So the rule will fire for every macAddress if this condition is fulfilled. But I want that the rule can only fire for the macAddress of the inserted Step event. How can I adjust my rule?

推荐答案

奇怪的是,当只有一个用户且没有任何步骤时,也会触发用户,即窗口为空。输出包含最小和最大值double值-不确定这是否是Drools中的错误。

Strangely enough, there's also a firing when there is just a User and no Steps for that User, i.e., the window is empty. The output contains minimum and maximum double values - not sure whether this is a bug in Drools.

作为解决方法,添加一个对累积计数的测试,也许大于0或大于1。

As a workaround, add a test of the accumulated count, perhaps greater 0 or greater 1.

accumulate( Steps( $s : steps , macAddress == $mac )
        over window:time( 1h ) from entry-point "entrySteps";
    $fst: min( $s ), $lst: max( $s ), $cnt: count( $s );
    $cnt > 0, $lst - $fst < 50 )

这篇关于流口水仅对插入事件触发规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆