<div><br></div>   Hi Diana,<div><br></div><div>   This happens because the order in which things happen. Up to Drools 5.3, Drools apply first filters (a.k.a., alpha constraints or literal constraints), then the sliding windows, then the joins.</div>
<div><br></div><div>   So in your case, <br><br></div><div>Notif( specificProblem == &quot;New ONT&quot; ) over window:length(2)</div><div><br></div><div>   Drools is first filtering your Notif events with specificProblem == &quot;New ONT&quot;, and on those it is applying the sliding window.</div>
<div><br></div><div>   To do what you want, you need to separate the definition of the window from the actual filter:</div><div><br></div><div>$last2: List() from collect( Notif() over window:length(2) ) </div><div>$nNewONT : Number() from accumulate ( Notif( specificProblem == &quot;New ONT&quot; ) from $last2, count() )<br>
</div><div><br></div><div>   I know this is confusing in some cases and for Drools 5.4 we will add explicit window declarations, so that (among other advantages) we reduce surprises like that and completely separate window-scoped filters from rule-scoped filters.</div>
<div><br></div><div>   Edson</div><div><br><div class="gmail_quote">2011/10/20 diana-mendes <span dir="ltr">&lt;<a href="mailto:diana-mendes@hotmail.com">diana-mendes@hotmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br>
<br>
<br>
I&#39;m having trouble using sliding length windows. Either I&#39;m implementing<br>
them wrong or I have misunderstood how they&#39;re supposed to work.<br>
<br>
<br>
I have a class named Notif:<br>
<br>
*public class Notif implements Serializable{<br>
   ...<br>
   private String specificProblem;<br>
   ...<br>
   public String getSpecificProblem() {<br>
        return specificProblem;<br>
   }<br>
<br>
   public void setSpecificProblem(String specificProblem) {<br>
        this.specificProblem = specificProblem;<br>
   }<br>
}*<br>
<br>
<br>
These Notif&#39;s represent my events. I want to know how many Notifs with<br>
specificProblem &quot;New ONT&quot; are there in the last 2 received events.<br>
<br>
My .drl file looks like this:<br>
<br>
<br>
*declare Notif<br>
        @role( event )<br>
end<br>
<br>
rule &quot;Rule1&quot;<br>
        when<br>
                $event : Notif()<br>
                $nNewONT : Number() from accumulate (<br>
                Notif( specificProblem == &quot;New ONT&quot; ) over window:length(2), count() )<br>
        then<br>
                System.out.println(&quot;In the last 2 events there were &quot;+$nNewONT+&quot; events<br>
&#39;New ONT&#39;&quot;);<br>
end*<br>
<br>
<br>
My test file:<br>
<br>
*...<br>
                 session.insert(ONTIsInactive1);<br>
                 session.insert(newONT1);<br>
                 session.insert(ONTIsInactive2);<br>
                 session.insert(newONT2);<br>
                 session.insert(LOKS1);<br>
                 session.insert(LOKS2);<br>
                 session.insert(LOKS3);<br>
                 session.insert(newONT3);<br>
                 session.fireAllRules(); *<br>
<br>
As you probably can tell by the names, the events I&#39;m looking for are the<br>
2nd, the 4th and the last one.<br>
<br>
But the output I get is:<br>
<br>
<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
In the last 2 events there were 2 events &#39;New ONT&#39;<br>
<br>
<br>
The output I&#39;m looking for is:<br>
<br>
In the last 2 events there were 0 events &#39;New ONT&#39; (because the received<br>
event is &quot;ONTIsInactive&quot;)<br>
In the last 2 events there were 1 events &#39;New ONT&#39; (because the last 2<br>
received events are &quot;ONTIsInactive&quot; and &quot;New ONT&quot;)<br>
In the last 2 events there were 1 events &#39;New ONT&#39; (because the last 2<br>
received events are &quot;New ONT&quot; and &quot;ONTIsInactive&quot;)<br>
...<br>
and so on...<br>
<br>
What am I doing wrong? Any help would be appreciated!<br>
Thanks in advance,<br>
<br>
Diana<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Sliding-Length-Windows-tp3438408p3438408.html" target="_blank">http://drools.46999.n3.nabble.com/Sliding-Length-Windows-tp3438408p3438408.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><br clear="all"><div><br></div>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>