Hi Greg,<div><br></div><div>Thanks for the response. Unfortunately your example doesn&#39;t appear to work, the SpeedIndicator doesn&#39;t get retracted, causing the consequence to only ever trigger once. However, I could add another rule to remove the SpeedingIndicator - meaning I no longer have to use the nasty global &quot;state&quot; object from my example.</div>
<div><br></div><div>Any other suggestions greatly appreciated.</div><div><br></div><div>Cheers,</div><div><br></div><div>Paul</div><div><br><div class="gmail_quote">On Thu, Dec 3, 2009 at 7:14 PM, Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Have you tried truth maintenance? (i.e. insertLogical)<br>
<div class="im"><br>
rule &quot;OverSpeedLimit&quot; no-loop true<br>
when<br>
</div>    not SpeedingIndicator();<br>
    $minSpeed : Double(doubleValue &gt; 100) from accumulate(<br>
<div class="im">        $speedingEvent : SpeedingEvent ($speed : speed)<br>
            over window:time( 30s )<br>
            from entry-point SpeedingStream,<br>
        min($speed)<br>
    );<br>
</div>then<br>
    insertLogical(new SpeedingIndicator());<br>
end<br>
<br>
Though I&#39;m not sure this will work, because inserting the SpeedingIndicator negates the first condition, probably causing the SpeedingIndicator to be retracted automatically. :)  But it&#39;s worth a try just to see if no-loop would override that somehow.<br>

<br>
Apart from that, note that you can test the results of an accumulate in the returned value. (The &quot;Double(doubleValue &gt; 100)&quot; part.)  YOu don&#39;t need the eval.<br>
<br>
Also, where is the &quot;state&quot; object coming from?  If it&#39;s a global, it&#39;s not a good idea to use them in the conditions of your rules.  Changes to them are not tracked by the rete.<br>
<br>
--- On Thu, 12/3/09, reverselogic &lt;<a href="mailto:reverselogic@gmail.com">reverselogic@gmail.com</a>&gt; wrote:<br>
<br>
&gt; From: reverselogic &lt;<a href="mailto:reverselogic@gmail.com">reverselogic@gmail.com</a>&gt;<br>
&gt; Subject: [rules-users] CEP + prevent consequences from triggering multiple times?<br>
&gt; To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; Date: Thursday, December 3, 2009, 12:41 PM<br>
<div><div></div><div class="h5">&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; I&#39;m trying to write a rule in drools, which triggers once<br>
&gt; some condition is<br>
&gt; active for a specified time interval. For example, if a<br>
&gt; vehicle is over a<br>
&gt; speed limit (100 mph) for 30 seconds, I want to trigger an<br>
&gt; action. However,<br>
&gt; once this rule has fired, I don&#39;t want it to fire again<br>
&gt; until the vehicle<br>
&gt; has dropped below the speed limit (and gone over the limit<br>
&gt; again). The only<br>
&gt; way I&#39;ve managed to model this is by defining two rules;<br>
&gt; one for determining<br>
&gt; when the vehicle is speeding and one for determining when<br>
&gt; it is not speeding<br>
&gt; and using a global object to track the state of the vehicle<br>
&gt; (see rules<br>
&gt; below).<br>
&gt;<br>
&gt; rule &quot;OverSpeedLimit&quot; no-loop true<br>
&gt; when<br>
&gt;     $minSpeed : Double() from accumulate(<br>
&gt;         $speedingEvent :<br>
&gt; SpeedingEvent ($speed : speed)<br>
&gt;            <br>
&gt; over window:time( 30s )<br>
&gt;            <br>
&gt; from entry-point SpeedingStream,<br>
&gt;         min($speed)<br>
&gt;     );<br>
&gt;    <br>
&gt;     eval ($minSpeed &gt; 100.0 &amp;&amp;<br>
&gt; !state.speeding)<br>
&gt; then<br>
&gt;     state.speeding = true<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;!OverSpeedLimit&quot; no-loop true<br>
&gt; when<br>
&gt;     $speedingEvent : SpeedingEvent()<br>
&gt;         from entry-point<br>
&gt; SpeedingStream<br>
&gt;     eval ($speedingEvent.speed &lt;= 100.0)<br>
&gt; then<br>
&gt;     state.speeding = false<br>
&gt; end<br>
&gt;<br>
&gt; My questions is: Is there a better way to model the above<br>
&gt; behaviour,<br>
&gt; preferably as a single rule? The reason I ask is because I<br>
&gt; believe it would<br>
&gt; be too complicated for my users to define rules like this.<br>
&gt; Ideally, I would<br>
&gt; like to be able to create a DSL such as: &quot;when Speed is<br>
&gt; above X for Y<br>
&gt; seconds then ...&quot;<br>
&gt;<br>
&gt; Any help greatly appreciated.<br>
&gt;<br>
&gt; Thanks,<br>
&gt;<br>
&gt; Paul<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; View this message in context: <a href="http://n3.nabble.com/CEP-prevent-consequences-from-triggering-multiple-times-tp67424p67424.html" target="_blank">http://n3.nabble.com/CEP-prevent-consequences-from-triggering-multiple-times-tp67424p67424.html</a><br>

&gt; Sent from the Drools - User mailing list archive at<br>
&gt; 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>
<br>
<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>
</div></div></blockquote></div><br></div>