Drools-expert 5.1.1
Does window:length work in Drools version 5.1.1 ?
It seems that "over window:length( 5 )" in rule
"PossibleFFF_launch_level1"
does not work.
It seems that it returns only the last MMMBean added in trackers in rules
"PossibleFFF_Level1_update_tracker_count" and
"PossibleFFF_Level2_update_tracker_count".
The idea here is that trackers keep count of how many MMMBeans have entered
the system, after incoming BBBBean with bbbEmpty == true have initiated the
tracking (PossibleFFF).
App domain specific operations are launched if there is no active counts
(actCount) in a series of MMMBeans ("PossibleFFF_launch_level1" and
"PossibleFFF_launch_level2").
actCount is an integer but accumulate function sum apparently returns a
floating point number, hence the check "doubleValue < 0.5".
Rules "PossibleFFF_kill_tracker_with_bbb" and
"PossibleFFF_kill_tracker_with_count" are to retract the trackers from
memory, so ending the tracking.
Rule "PossibleFFF_kill_tracker_with_bbb" kills this profileID's tracker if
bbbEmpty == false.
Rule "PossibleFFF_kill_tracker_with_count" kills tracker if count > 5, count
indicating that no operations were launched ("PossibleFFF_launch_level1" and
"PossibleFFF_launch_level2").
Problem is, that the condition
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.mdsBeanList,
MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.getMdsBeanList(),
sum( $actCount ) )
in rules
"PossibleFFF_launch_level1" and "PossibleFFF_launch_level2"
does not seem to work as expected.
I expected that the sum would be calculated from field MMMBean.actCount over
all MMMBean members of list $tracker.mdsBeanList.
It seems that sum returns only the actCount of last MMMBean which was
inserted in $tracker.mdsBeanList.
Is there something wrong with the rules ?
Rules are like these:
// RULES -->
rule "PossibleFFF" dialect "mvel"
when
$bsb : BBBBean(bbbEmpty == true)
not FFFTracker(profileID == $bsb.profileID)
then
FFFTracker $tracker = new FFFTracker();
$tracker.level = 1;
$tracker.count = 0;
$tracker.profileID = $bsb.profileID;
$tracker.location = $bsb.location;
retract($bsb);
$tracker.sensorBean = $bsb;
insert($tracker);
end
rule "PossibleFFF_Level1_update_tracker_count" dialect "mvel"
when
$tracker : FFFTracker(level == 1)
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
then
drools.retract($mds);
$tracker.addMdsBean($mds);
$tracker.count = $tracker.count + 1;
drools.update($tracker);
end
rule "PossibleFFF_launch_level1" dialect "mvel"
when
$tracker : FFFTracker(level == 1, count == 5, $prof : profileID)
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.mdsBeanList,
MMMBean( $actCount : activeCount) over window:length( 5 ) from
$tracker.getMdsBeanList(),
sum( $actCount ) )
then
retract($tracker);
FFFTracker $tracker2 = new FFFTracker();
$tracker2.level = 2;
$tracker2.profileID = $tracker.profileID;
$tracker2.location = $tracker.location;
$tracker2.sensorBean = $tracker.sensorBean;
$tracker2.count = 0;
// Tracker2 is set to track further conditions
insert($tracker2);
// launch the app domain specific things
end
rule "PossibleFFF_Level2_update_tracker_count" dialect "mvel"
when
$tracker : FFFTracker(level == 2)
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)
then
drools.retract($mds);
$tracker.addMdsBean($mds);
$tracker.count = $tracker.count + 1;
drools.update($tracker);
end
rule "PossibleFFF_launch_level2" dialect "mvel"
when
$tracker : FFFTracker(level == 2, count == 5, $prof : profileID)
$theSum : Number(doubleValue < 0.5) from accumulate(
// MMMBean( $actCount : activeCount, profileID == $prof) over
window:length( 5 ) from $tracker.mdsBeanList,
MMMBean( $actCount : activeCount, profileID == $prof) over
window:length( 5 ) from $tracker.getMdsBeanList(),
sum( $actCount ) )
then
retract($tracker);
// launch the app domain specific things
end
rule "PossibleFFF_kill_tracker_with_bbb" dialect "mvel"
when
$tracker : FFFTracker($prof : profileID, $loc : location)
$bsb : BBBBean(profileID == $prof, location == $loc, bbbEmpty == false,
this after $tracker)
then
retract($tracker);
end
rule "PossibleFFF_kill_tracker_with_count" dialect "mvel"
when
$tracker : FFFTracker(count > 5, $prof : profileID)
then
retract($tracker);
end
// <-- RULES
BBBBean, MMMBean, FFFTracker are declared as events.
class FFFTracker:
public class FFFTracker extends Tracker
{
private ArrayList<MMMMBean> mdsBeanList = new ArrayList<MMMMBean>();
public ArrayList<MMMBean> getMdsBeanList()
{
return mdsBeanList;
}
public void setMdsBeanList(ArrayList<MMMBean> pmdsbeanlist)
{
this.mdsBeanList = pmdsbeanlist;
}
public void addMdsBean(MMMBean pbean)
{
this.mdsBeanList.add(pbean);
}
}
class Tracker:
public class Tracker
{
private long profileID = 0;
private short location = 0;
private int level = 0;
private int count = 0;
private ASensorBean sensorBean = null; // AsensorBean is an abstract
class from which BBBBean and MMMBean are derived
// getters and setters goes here
}
Best Regards,
Esko
------
Esko Hujanen
www.ebsolut.fi
--
View this message in context:
http://drools.46999.n3.nabble.com/Does-window-length-work-in-Drools-versi...
Sent from the Drools: User forum mailing list archive at
Nabble.com.