First time around I also stumbled over this, especially because the documention fails to describe the actual behaviour, which is certainly not intuitive. All uses of &quot;length n&quot; that I know <i>do not</i> include things of length n-1, n-2,... 1. Imagine going into a shop and asking for a belt of length 60&quot; and getting one of 12&quot;. A Java array of length 10 isn&#39;t 3 or 5 or 9 elements long. Many mathematical procedures that use a data window of length n must avoid shorter samples, or use different treatment, e.g., an initial value problem, or statistical evaluation.<br>
<br>-W<br><br><br><div class="gmail_quote">On 18 October 2011 23:33, Mark Proctor <span dir="ltr">&lt;<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</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;">
Think about the logic you have written.<br>
<br>
length(3) does not mean that it must have 3, but that it is the last<br>
three. So it could be 0, 1, 2 or 3 in length.<br>
<br>
As soon s you have 1, 2, or 3 insertions if any one of those creates an<br>
average of &gt; 30 the rule fires.<br>
<br>
So you are inserting  a ZZZBean that creates an average, even if it&#39;s an<br>
average with a count of 1, over 30.<br>
<br>
Mark<br>
On 18/10/2011 07:20, eskomk wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; Here is the rule:<br>
&gt;<br>
&gt; CLIP --&gt;<br>
&gt; rule &quot;ZZZOver30&quot; dialect &quot;mvel&quot;<br>
&gt;<br>
&gt; when<br>
&gt;      $tsb : ZZZBean($prof : profileID)<br>
&gt;      $avg : Number( doubleValue&gt;  30 ) from accumulate(<br>
&gt;          ZZZBean( $tempr : temperature, profileID == $prof) over<br>
&gt; window:length( 3 ),<br>
&gt;          average( $tempr ) )<br>
&gt; then<br>
&gt;      // do something<br>
&gt; end<br>
&gt; CLIP&lt;--<br>
&gt;<br>
&gt; The intention as you can see is that the rule fires if the average<br>
&gt; temperature rises above 30 degrees (of Celsius) in some measuring period.<br>
&gt; For testing purposes the rule takes a specific number of temperatures<br>
&gt; (window:length), in production environment the window will be time<br>
&gt; (window:time(Xm)).<br>
&gt;<br>
&gt; My question is, why this rule fires immediately after drools-expert is<br>
&gt; started ?<br>
&gt; Is there something wrong in syntax ?<br>
&gt;<br>
&gt; In startup there are obviously no objects of this kind (ZZZBean) in Working<br>
&gt; Set&#39;s memory, so it really shouldn&#39;t fire.<br>
&gt;<br>
&gt; We are running Drools ver. 5.1.1 as a web service on top of apache, and the<br>
&gt; facts (events) are fed to Drools via REST interface as XML.<br>
&gt;<br>
&gt; thanks and regards,<br>
&gt; Esko<br>
&gt; -----<br>
&gt; Esko Hujanen<br>
&gt; <a href="http://www.ebsolut.fi" target="_blank">www.ebsolut.fi</a><br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; View this message in context: <a href="http://drools.46999.n3.nabble.com/Why-this-rule-fires-immediately-tp3430427p3430427.html" target="_blank">http://drools.46999.n3.nabble.com/Why-this-rule-fires-immediately-tp3430427p3430427.html</a><br>

&gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
<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>
</blockquote></div><br>