[rules-users] Another solution for: Detecting more than 3 occurrences within 1 hour

Tina Vießmann tviessmann at stud.hs-bremen.de
Thu Aug 5 13:49:22 EDT 2010


Hi,

I'm working on thinking in Drools rules. Right now I'm trying to solve this:
   The rule shall fire if _a special event occurs more than 3 times 
within 1 hour_.

My _first thought of a solution_ was to count the count the detected 
events using a counter. But the counter has to be a global variable, 
hasn't it? And global variables are not to be used to frequently, aren't 
they?
And global variables must always be initialized from outside the rules 
file, don't they?

Because of these thoughts I've looked for a _different solution without 
global variables_. I came up with:

    function boolean valueExceededLimit(Set<Alarms> alarmSet) {
        //....
    }

    rule "more than 3 occurs within 1 hour"

         when
             // event #1
             $eventA : Value(
    eval(parameterValueExceededLimit($eventA.getAlarms())) )
             // event #2
             $eventB : Value( this after[0ms,1h] $eventA &&
                                         this != $eventA &&
                                       
      eval(valueExceededLimit($eventB.getAlarms())) )
             // event #3
             $eventC : Value( this after[0ms,1h] $eventA &&
                                         this != $eventA &&
                                         this != $eventB &&
                                       
      eval(valueExceededLimit($eventC.getAlarms())) )
             // event #4  ->  4 > 3
             $eventD : Value( this after[0ms,1h] $eventA &&
                                         this != $eventA &&
                                         this != $eventB &&
                                         this != $eventC &&
                                       
      eval(valueExceededLimit($eventD.getAlarms())) )

         then
             // ... do something ...

    end


More than 3 is kind of a doable task. But I think of this solution as 
heavy in case its needed to detect a larger number of events. I would be 
thankful for other approaches to the problem.


Thanks :)
Tina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100805/49e7fe87/attachment.html 


More information about the rules-users mailing list