Use what I call "peephole technique" in my paper on design patterns. Here,
the peephole would hold references to the last,next-to-last, last but
two,... event, to be updated with each new event.
The stack/pop looks rather horrid, if I'm permitted to say so... ;-)
-WL
On 16/10/2013, Alexander Wolf <mail(a)alexander-wolf.net> wrote:
Hey,
I try to use drools fusion to detect patterns in an event stream.
Each time an event occurs I insert it into my ksession and call
fireAllRules().
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.
I also have a "state" within my environment. e.g. temperature (HIGH, MEDIUM,
LOW). (but also other state variables)
e.g. [pseudo code]
WHEN
temperature MEDIUM or LOW
newest event (value >= 20)
last previous event (value >= 20)
then
set temperature to HIGH
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)
Also the rule is triggert when temperature is changed without a new event
being inserted.
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.
For now I used this to get the "newest" event, but it seems to be very
non-declarative to do it like that
//most recent event
Stack(size > 0, $event: pop, $event.value == 1)
from collect( Event())
Are there any best practices especially for working with the "newest" event
and with events + facts (as "states")?
- Alex