Hi Diana,

   This happens because the order in which things happen. Up to Drools 5.3,
Drools apply first filters (a.k.a., alpha constraints or literal
constraints), then the sliding windows, then the joins.

   So in your case,

Notif( specificProblem == "New ONT" ) over window:length(2)

   Drools is first filtering your Notif events with specificProblem == "New
ONT", and on those it is applying the sliding window.

   To do what you want, you need to separate the definition of the window
from the actual filter:

$last2: List() from collect( Notif() over window:length(2) )
$nNewONT : Number() from accumulate ( Notif( specificProblem == "New ONT" )
from $last2, count() )

   I know this is confusing in some cases and for Drools 5.4 we will add
explicit window declarations, so that (among other advantages) we reduce
surprises like that and completely separate window-scoped filters from
rule-scoped filters.

   Edson

2011/10/20 diana-mendes <diana-men...@hotmail.com>

> Hello,
>
>
> I'm having trouble using sliding length windows. Either I'm implementing
> them wrong or I have misunderstood how they're supposed to work.
>
>
> I have a class named Notif:
>
> *public class Notif implements Serializable{
>   ...
>   private String specificProblem;
>   ...
>   public String getSpecificProblem() {
>        return specificProblem;
>   }
>
>   public void setSpecificProblem(String specificProblem) {
>        this.specificProblem = specificProblem;
>   }
> }*
>
>
> These Notif's represent my events. I want to know how many Notifs with
> specificProblem "New ONT" are there in the last 2 received events.
>
> My .drl file looks like this:
>
>
> *declare Notif
>        @role( event )
> end
>
> rule "Rule1"
>        when
>                $event : Notif()
>                $nNewONT : Number() from accumulate (
>                Notif( specificProblem == "New ONT" ) over window:length(2),
> count() )
>        then
>                System.out.println("In the last 2 events there were
> "+$nNewONT+" events
> 'New ONT'");
> end*
>
>
> My test file:
>
> *...
>                 session.insert(ONTIsInactive1);
>                 session.insert(newONT1);
>                 session.insert(ONTIsInactive2);
>                 session.insert(newONT2);
>                 session.insert(LOKS1);
>                 session.insert(LOKS2);
>                 session.insert(LOKS3);
>                 session.insert(newONT3);
>                 session.fireAllRules(); *
>
> As you probably can tell by the names, the events I'm looking for are the
> 2nd, the 4th and the last one.
>
> But the output I get is:
>
>
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
> In the last 2 events there were 2 events 'New ONT'
>
>
> The output I'm looking for is:
>
> In the last 2 events there were 0 events 'New ONT' (because the received
> event is "ONTIsInactive")
> In the last 2 events there were 1 events 'New ONT' (because the last 2
> received events are "ONTIsInactive" and "New ONT")
> In the last 2 events there were 1 events 'New ONT' (because the last 2
> received events are "New ONT" and "ONTIsInactive")
> ...
> and so on...
>
> What am I doing wrong? Any help would be appreciated!
> Thanks in advance,
>
> Diana
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Sliding-Length-Windows-tp3438408p3438408.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to