There <i>may</i> be a problem in 5.1.1 due to using window:length on objects produced<br>by "from" when these objects aren't facts.<br><br>Since you discard Tracker facts as soon as the 6th MMMBean arrives I suggest that you calculate the sum when you add another Bean to the Tracker, and store the sum in the Tracker, which needs to be updated anyway.<br>
<br>Also, I don't see the need for creating a Tracker in order to advance it to level two; a simple update of the Tracker would work just as well.<br><br>Cheers<br>Wolfgang<br><br><br><br><div class="gmail_quote">On 28 October 2011 12:39, eskomk <span dir="ltr"><<a href="mailto:esko.hujanen@ebsolut.fi">esko.hujanen@ebsolut.fi</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Drools-expert 5.1.1<br>
<br>
Does window:length work in Drools version 5.1.1 ?<br>
<br>
It seems that "over window:length( 5 )" in rule "PossibleFFF_launch_level1"<br>
does not work.<br>
It seems that it returns only the last MMMBean added in trackers in rules<br>
"PossibleFFF_Level1_update_tracker_count" and<br>
"PossibleFFF_Level2_update_tracker_count".<br>
<br>
The idea here is that trackers keep count of how many MMMBeans have entered<br>
the system, after incoming BBBBean with bbbEmpty == true have initiated the<br>
tracking (PossibleFFF).<br>
App domain specific operations are launched if there is no active counts<br>
(actCount) in a series of MMMBeans ("PossibleFFF_launch_level1" and<br>
"PossibleFFF_launch_level2").<br>
actCount is an integer but accumulate function sum apparently returns a<br>
floating point number, hence the check "doubleValue < 0.5".<br>
Rules "PossibleFFF_kill_tracker_with_bbb" and<br>
"PossibleFFF_kill_tracker_with_count" are to retract the trackers from<br>
memory, so ending the tracking.<br>
Rule "PossibleFFF_kill_tracker_with_bbb" kills this profileID's tracker if<br>
bbbEmpty == false.<br>
Rule "PossibleFFF_kill_tracker_with_count" kills tracker if count > 5, count<br>
indicating that no operations were launched ("PossibleFFF_launch_level1" and<br>
"PossibleFFF_launch_level2").<br>
<br>
Problem is, that the condition<br>
$theSum : Number(doubleValue < 0.5) from accumulate(<br>
// MMMBean( $actCount : activeCount) over window:length( 5 ) from<br>
$tracker.mdsBeanList,<br>
MMMBean( $actCount : activeCount) over window:length( 5 ) from<br>
$tracker.getMdsBeanList(),<br>
sum( $actCount ) )<br>
in rules<br>
"PossibleFFF_launch_level1" and "PossibleFFF_launch_level2"<br>
does not seem to work as expected.<br>
I expected that the sum would be calculated from field MMMBean.actCount over<br>
all MMMBean members of list $tracker.mdsBeanList.<br>
It seems that sum returns only the actCount of last MMMBean which was<br>
inserted in $tracker.mdsBeanList.<br>
<br>
Is there something wrong with the rules ?<br>
<br>
Rules are like these:<br>
<br>
// RULES --><br>
rule "PossibleFFF" dialect "mvel"<br>
<br>
when<br>
$bsb : BBBBean(bbbEmpty == true)<br>
not FFFTracker(profileID == $bsb.profileID)<br>
then<br>
FFFTracker $tracker = new FFFTracker();<br>
$tracker.level = 1;<br>
$tracker.count = 0;<br>
<br>
$tracker.profileID = $bsb.profileID;<br>
$tracker.location = $bsb.location;<br>
<br>
retract($bsb);<br>
<br>
$tracker.sensorBean = $bsb;<br>
<br>
insert($tracker);<br>
end<br>
<br>
<br>
rule "PossibleFFF_Level1_update_tracker_count" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker(level == 1)<br>
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)<br>
then<br>
drools.retract($mds);<br>
<br>
$tracker.addMdsBean($mds);<br>
$tracker.count = $tracker.count + 1;<br>
drools.update($tracker);<br>
end<br>
<br>
<br>
rule "PossibleFFF_launch_level1" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker(level == 1, count == 5, $prof : profileID)<br>
$theSum : Number(doubleValue < 0.5) from accumulate(<br>
// MMMBean( $actCount : activeCount) over window:length( 5 ) from<br>
$tracker.mdsBeanList,<br>
MMMBean( $actCount : activeCount) over window:length( 5 ) from<br>
$tracker.getMdsBeanList(),<br>
sum( $actCount ) )<br>
then<br>
retract($tracker);<br>
<br>
FFFTracker $tracker2 = new FFFTracker();<br>
$tracker2.level = 2;<br>
<br>
$tracker2.profileID = $tracker.profileID;<br>
$tracker2.location = $tracker.location;<br>
$tracker2.sensorBean = $tracker.sensorBean;<br>
$tracker2.count = 0;<br>
<br>
// Tracker2 is set to track further conditions<br>
insert($tracker2);<br>
<br>
// launch the app domain specific things<br>
end<br>
<br>
rule "PossibleFFF_Level2_update_tracker_count" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker(level == 2)<br>
$mds : MMMBean(profileID == $tracker.profileID, this after $tracker)<br>
then<br>
drools.retract($mds);<br>
<br>
$tracker.addMdsBean($mds);<br>
$tracker.count = $tracker.count + 1;<br>
drools.update($tracker);<br>
end<br>
<br>
<br>
rule "PossibleFFF_launch_level2" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker(level == 2, count == 5, $prof : profileID)<br>
$theSum : Number(doubleValue < 0.5) from accumulate(<br>
// MMMBean( $actCount : activeCount, profileID == $prof) over<br>
window:length( 5 ) from $tracker.mdsBeanList,<br>
MMMBean( $actCount : activeCount, profileID == $prof) over<br>
window:length( 5 ) from $tracker.getMdsBeanList(),<br>
sum( $actCount ) )<br>
then<br>
retract($tracker);<br>
<br>
// launch the app domain specific things<br>
end<br>
<br>
<br>
rule "PossibleFFF_kill_tracker_with_bbb" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker($prof : profileID, $loc : location)<br>
$bsb : BBBBean(profileID == $prof, location == $loc, bbbEmpty == false,<br>
this after $tracker)<br>
then<br>
retract($tracker);<br>
end<br>
<br>
<br>
rule "PossibleFFF_kill_tracker_with_count" dialect "mvel"<br>
<br>
when<br>
$tracker : FFFTracker(count > 5, $prof : profileID)<br>
then<br>
retract($tracker);<br>
end<br>
// <-- RULES<br>
<br>
BBBBean, MMMBean, FFFTracker are declared as events.<br>
<br>
class FFFTracker:<br>
public class FFFTracker extends Tracker<br>
{<br>
private ArrayList<MMMMBean> mdsBeanList = new ArrayList<MMMMBean>();<br>
<br>
public ArrayList<MMMBean> getMdsBeanList()<br>
{<br>
return mdsBeanList;<br>
}<br>
<br>
public void setMdsBeanList(ArrayList<MMMBean> pmdsbeanlist)<br>
{<br>
this.mdsBeanList = pmdsbeanlist;<br>
}<br>
<br>
public void addMdsBean(MMMBean pbean)<br>
{<br>
this.mdsBeanList.add(pbean);<br>
}<br>
}<br>
<br>
class Tracker:<br>
public class Tracker<br>
{<br>
private long profileID = 0;<br>
private short location = 0;<br>
private int level = 0;<br>
private int count = 0;<br>
private ASensorBean sensorBean = null; // AsensorBean is an abstract<br>
class from which BBBBean and MMMBean are derived<br>
<br>
// getters and setters goes here<br>
}<br>
<br>
Best Regards,<br>
Esko<br>
------<br>
Esko Hujanen<br>
<a href="http://www.ebsolut.fi" target="_blank">www.ebsolut.fi</a><br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Does-window-length-work-in-Drools-version-5-1-1-tp3460621p3460621.html" target="_blank">http://drools.46999.n3.nabble.com/Does-window-length-work-in-Drools-version-5-1-1-tp3460621p3460621.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>