1
我最近开始使用Drools Fusion进行编程,我有一台智能可穿戴设备,可将计步器和心率数据发送到我的笔记本电脑。然后我使用drools规则语言来处理这些数据。但假设我有多个智能可穿戴设备,每个唯一的MAC地址。我使用时间窗口,我的问题是如何更改我的规则文件,以便规则只针对具有相同macaddress的事件触发,并基于此MAC地址采取适当的操作。 我现在的规则文件如下:不同用户的Drools规则
import hellodrools.Steps
import hellodrools.HeartRate
import hellodrools.AppInfo
declare AppInfo
@role(event)
end
declare Steps
@role(event)
end
declare HeartRate
@role(event)
end
rule "ACC STEPS RULE"
when
accumulate(Steps($s : steps)
over window:time(1h) from entry-point "entrySteps";
$fst: min($s), $lst: max($s);
$lst - $fst < 50)
then
System.out.println("STEPS RULE: get moving!");
System.out.println($lst + " " + $fst);
end
rule "HEARTRATE RULE 1"
when
$heartrate : HeartRate(heartRate >= 150) from entry-point "entryHeartRate"
then
System.out.println("Heartrate is to high!");
end
rule "HEARTRATE RULE 2"
when
$heartrate : HeartRate(heartRate <= 50 && heartRate >= 35) from entry- point "entryHeartRate"
then
System.out.println("Heartrate is to low!");
end
rule "HEARTRATE RULE 3"
when
$heartrate : HeartRate(heartRate < 35 && heartRate >= 25) from entry-point "entryHeartRate"
then
System.out.println("Heartrate is critical low!");
end
rule "HEARTRATE RULE 4"
when
$max : Double() from accumulate(
HeartRate($heartrates : heartRate) over window:time(10s) from entry-point "entryHeartRate",
max($heartrates))&&
$min : Double() from accumulate(
HeartRate($heartrates : heartRate) over window:time(10s) from entry-point "entryHeartRate",
min($heartrates))&&
eval(($max - $min) >= 50)
then
System.out.println("Heartrate to much difference in to little time!");
end
我的心率事件有以下字段:
int heartRate;
Date timeStamp;
String macAddress;
我的脚步事件有以下字段:
double steps;
Date timeStamp;
String macAddress;
谢谢你的回答。就像我说的,我刚开始用口水,我不明白它的完整性。我创建了一个带有字段macAddress的新类Walker。然后在我的规则文件中将其声明为事实:'声明Walker @role(fact)end'并更新我的规则。然后,我做了以下事情: 'Walker walker = new Walker(macAddress); entryPointSteps.insert(walker);'但是没有发生。你能解释一下吗?谢谢。 – Tim
如果使用'entryPointSteps'插入,则必须在规则中使用'from entrySteps'。你是否? – laune
不,这的确是问题,谢谢! – Tim