There <i>may</i> be a problem in 5.1.1 due to using window:length on objects produced<br>by &quot;from&quot; when these objects aren&#39;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&#39;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">&lt;<a href="mailto:esko.hujanen@ebsolut.fi">esko.hujanen@ebsolut.fi</a>&gt;</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 &quot;over window:length( 5 )&quot; in rule &quot;PossibleFFF_launch_level1&quot;<br>
does not work.<br>
It seems that it returns only the last MMMBean added in trackers in rules<br>
&quot;PossibleFFF_Level1_update_tracker_count&quot; and<br>
&quot;PossibleFFF_Level2_update_tracker_count&quot;.<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 (&quot;PossibleFFF_launch_level1&quot; and<br>
&quot;PossibleFFF_launch_level2&quot;).<br>
actCount is an integer but accumulate function sum apparently returns a<br>
floating point number, hence the check &quot;doubleValue &lt; 0.5&quot;.<br>
Rules &quot;PossibleFFF_kill_tracker_with_bbb&quot; and<br>
&quot;PossibleFFF_kill_tracker_with_count&quot; are to retract the trackers from<br>
memory, so ending the tracking.<br>
Rule &quot;PossibleFFF_kill_tracker_with_bbb&quot; kills this profileID&#39;s tracker if<br>
bbbEmpty == false.<br>
Rule &quot;PossibleFFF_kill_tracker_with_count&quot; kills tracker if count &gt; 5, count<br>
indicating that no operations were launched (&quot;PossibleFFF_launch_level1&quot; and<br>
&quot;PossibleFFF_launch_level2&quot;).<br>
<br>
Problem is, that the condition<br>
    $theSum : Number(doubleValue &lt; 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>
&quot;PossibleFFF_launch_level1&quot; and &quot;PossibleFFF_launch_level2&quot;<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 --&gt;<br>
rule &quot;PossibleFFF&quot; dialect &quot;mvel&quot;<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 &quot;PossibleFFF_Level1_update_tracker_count&quot; dialect &quot;mvel&quot;<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 &quot;PossibleFFF_launch_level1&quot; dialect &quot;mvel&quot;<br>
<br>
when<br>
    $tracker : FFFTracker(level == 1, count == 5, $prof : profileID)<br>
    $theSum : Number(doubleValue &lt; 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 &quot;PossibleFFF_Level2_update_tracker_count&quot; dialect &quot;mvel&quot;<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 &quot;PossibleFFF_launch_level2&quot; dialect &quot;mvel&quot;<br>
<br>
when<br>
    $tracker : FFFTracker(level == 2, count == 5, $prof : profileID)<br>
    $theSum : Number(doubleValue &lt; 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 &quot;PossibleFFF_kill_tracker_with_bbb&quot; dialect &quot;mvel&quot;<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 &quot;PossibleFFF_kill_tracker_with_count&quot; dialect &quot;mvel&quot;<br>
<br>
when<br>
    $tracker : FFFTracker(count &gt; 5, $prof : profileID)<br>
then<br>
    retract($tracker);<br>
end<br>
// &lt;-- RULES<br>
<br>
BBBBean, MMMBean, FFFTracker are declared as events.<br>
<br>
class FFFTracker:<br>
public class FFFTracker extends Tracker<br>
{<br>
    private ArrayList&lt;MMMMBean&gt; mdsBeanList = new ArrayList&lt;MMMMBean&gt;();<br>
<br>
    public ArrayList&lt;MMMBean&gt; getMdsBeanList()<br>
    {<br>
        return mdsBeanList;<br>
    }<br>
<br>
    public void setMdsBeanList(ArrayList&lt;MMMBean&gt; 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>