[英]Drools rule fire only for inserted event
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:
我有一个基于macAddress的规则文件,将触发该规则:
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
My User has just a field macAddress
and Steps events have the following fields: 我的用户只有一个
macAddress
字段,而Steps事件具有以下字段:
double steps;
Date timeStamp;
String 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. 现在,当我为每个 macAddress插入一个事件时,如果具有该macAddress的用户在过去一小时内的步数少于50,则该规则将触发。因此,如果满足此条件,则将为每个macAddress触发该规则。 But I want that the rule can only fire for the macAddress of the inserted Step event.
但我希望该规则只能针对插入的Step事件的macAddress触发。 How can I adjust my rule?
如何调整规则?
Strangely enough, there's also a firing when there is just a User and no Steps for that User, ie, the window is empty. 奇怪的是,当只有一个用户并且没有该用户的任何步骤时,也会触发,即窗口为空。 The output contains minimum and maximum double values - not sure whether this is a bug in Drools.
输出包含最小和最大double值-不确定这是否是Drools中的错误。
As a workaround, add a test of the accumulated count, perhaps greater 0 or greater 1. 解决方法是添加一个对累积计数的测试,可能大于0或大于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 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.