<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey,&nbsp;<div><br></div><div>I try to use drools fusion to detect patterns in an event stream.</div><div>Each time an event occurs I insert it into my ksession and call fireAllRules().</div><div><br></div><div>Most of my rules need to reason over the newest event (the one that just came in) in conjunction with events that happend before or after that.&nbsp;</div><div>I also have a "state" within my environment. e.g. temperature (HIGH, MEDIUM, LOW). (but also other state variables)</div><div><br></div><div>e.g. [pseudo code]</div><div>WHEN</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>temperature MEDIUM or LOW</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>newest event (value &gt;= 20)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>last&nbsp;previous event (value &gt;= 20)</div><div>then</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>set temperature to HIGH</div><div><br></div><div><br></div><div>Now I run into lots of problems with this e.g. that I can not easily get the "newest" and "last previous" events. When i get Events() there is usually more than one (as some of them are not immediately expired)</div><div>Also the rule is triggert when temperature is changed without a new event being inserted.&nbsp;</div><div><br></div><div>I could theoretically "mark" events that have been used, but I might run into problems when other rules are added that depend on the same events. Also it seems to be untidy to do so.</div><div>For now I used this to get the "newest" event, but it seems to be very non-declarative to do it like that</div><div><br></div><div><div style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(146, 144, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>//most recent event<span class="Apple-tab-span" style="white-space:pre">        </span></div><div style="margin: 0px; font-size: 12px; font-family: Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>Stack(size &gt; 0, $event: pop, $event.value == 1)&nbsp;</div><div style="margin: 0px; font-size: 12px; font-family: Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #a91500">from</span> <span style="color: #a91500">collect</span>( Event())<span class="Apple-tab-span" style="white-space:pre">        </span></div></div><div><br></div><div><br></div><div>Are there any best practices especially for working with the "newest" event and with events + facts (as "states")?</div><div><br></div><div>- Alex</div></body></html>