From: "lin.lin [via Drools]" <ml-node+s46999n4028540h77@n3.nabble.com>
Date: March 5, 2014 at 10:47:14 AM CST
To: "lin.lin" <lin.lin@comcast.net>
Subject: Re: [rules-users] sliding window question

Hi Walfgang,

  Thanks a lot for the pointers. My goal is to try detect a situation when readings about a user is consistent high for the last 30 seconds. The reading comes every 10 seconds. I have tried many different ways and still can not get it working.  Here are a list of things that I found not working, I am wondering whether anyone has encountered some of this before or whether there is a known issue related to some of this or whether there is some configuration that I am missing in my environment.  Also, what is a good way to find out whether a event has expired or still in working memory?  I am stuck, please help.

1) the following rule does not work, according to drools book, this should work.

rule "rule1"
       dialect "mvel"
       when
         $user: mUser(status==true)
         not (Reading ($user.userid== userid, reading<=90) over window :time (30s) from entry-point ReadingStream
       then

2) the following rules work on its own, (that is if I only include one rule in the .drl file), but when I put both rules in the .drl file,  only the acumtest rule works but nothing comes out from  "rule1"  

rule "acumtest"
dialect "mvel"
  when
   accumulate( Reading( $r:reading) over windiw:time(30s) from entry-point ReadingStream, $sum : sum($r))
  then
    System.out.print ("sum=" +$sum+"\n");
end

rule "rule1"
dialect "mvel"
    when
      $user: mUser(status==true)
      $hr1 : Reading ($user.userid==$hr1.userid, reading>90) from entry-point ReadingStream
      $hr2 : Reading ($user.userid==$hr2.userid, reading>90, this after [30s,30s] $hr1) from entry-point ReadingStream
      not Reading ($user.userid == userid, reading<=90, this after $hr1, this before $hr2) from entry-point ReadingStream
    then

3) The following rule does not work, but if I comment out the accumulate line in the condition, it works.  Somehow, the accumulate function does not work with other rules or making event expired ??

rule "rule1"
dialect "mvel"
    when
      $user: mUser(status==true)
      $hr1 : Reading ($user.userid==$hr1.userid, reading>90) from entry-point ReadingStream
      $hr2 : Reading ($user.userid==$hr2.userid, reading>90, this after [30s,30s] $hr1) from entry-point ReadingStream
      not Reading ($user.userid == userid, reading<=90, this after $hr1, this before $hr2) from entry-point ReadingStream
      $test: Number( doubleValue>0 ) from accumulate ( Reading( userid==$user.userid, $r:reading) over window:time(30s) from entry-point ReadingStream, sum($r))
    then

4) This does work, but if I uncomment out the $hr4 line, then it does not work anymore
rule "rule1"
dialect "mvel"
    when
      $user: mUser(status==true)
      $hr1 : Reading ($user.userid==$hr1.userid, reading>90) from entry-point ReadingStream
      $hr2 : Reading ($user.userid==$hr2.userid, reading>90, this after [10s,10s] $hr1) from entry-point ReadingStream
      $hr3 : Reading ($user.userid==$hr3.userid, reading>90, this after [10s,10s] $hr2) from entry-point ReadingStream
      // $hr4 : Reading ($user.userid==$hr4.userid, reading>90, this after [10s,10s] $hr3) from entry-point ReadingStream
      $test: Number( doubleValue>0 ) from accumulate ( Reading( userid==$user.userid, $r:reading) over window:time(30s) from entry-point ReadingStream, sum($r))
    then


Thanks  a lot!

Lin


If you reply to this email, your message will be added to the discussion below:
http://drools.46999.n3.nabble.com/sliding-window-question-tp4028367p4028540.html
To unsubscribe from sliding window question, click here.
NAML