gpt4 book ai didi

java - Drools 规则仅针对插入的事件触发

转载 作者:行者123 更新时间:2023-12-01 10:14:10 28 4
gpt4 key购买 nike

每个发送计步器数据的传感器都有多种用途。我有一个基于 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

我的用户只有一个字段macAddress,而步骤事件具有以下字段:

double steps;
Date timeStamp;
String macAddress;

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

最佳答案

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

作为解决方法,添加累积计数的测试,可能大于 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 )

关于java - Drools 规则仅针对插入的事件触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36008719/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com