For an average, the accumulate CE would be best: accumulate( Reading( $reading: reading ) over window:time( 30s ); $avg: average( $reading ) )
You could add this as the last pattern to the rule where you raise the alarm. None of this was compiled or tested by me. -W On 27/02/2014, Lin Lin <lin....@comcast.net> wrote: > Hi Wolfgang, > > Thanks so much! I will try the sliding window over the time. I also > need to give the average reading over the last 30 seconds in the alert > message. How would I do that? > > Thanks > Lin > >> On Feb 27, 2014, at 1:01 AM, Wolfgang Laun <wolfgang.l...@gmail.com> >> wrote: >> >> The correct way to ascertain that something hasn't happened for >> a certain interval must be based on "staking out" this interval. One >> way is by means of two distinct events: >> >> when >> $r1: Reading( reading >90 ) >> $r2: Reading( reading > 90, this after[30s] $r1 ) >> not Reading( reading <= 90, this after $r1 && before $r2 ) >> then >> >> Clearly, this will only work if Readings arrive regularly, and you may >> have a >> certain amount of delay at the end. >> >> Another way would be to use a sliding window over time: >> >> when >> not Reading( reading <= 90 ) over window:time( 30s ) >> then >> >> Here's a snag, too: If there are no readings at all, you'll also get an >> alert. >> >> And then you'll have to think about the seconds following the 30th >> second: should another alert be emitted repeatedly... >> >> Most of the time, it's not an issue in CEP ;-) >> >> -W >> >> >> >> >> >> >>> On 27/02/2014, lin.lin <lin....@comcast.net> wrote: >>> Hi, >>> >>> I tried to create a rule that gives an alert when a machine reading is >>> high >>> for 30 seconds. I modeled the machine reading input as events. The >>> following is the rule: >>> >>> rule "rule1" >>> dialect "mvel" >>> when >>> $rd1 : mReading( reading >90 ) from entry-point ReadingStream >>> not ($rd2 : mReading (reading<=90 , this before [0s, 30s] $rd1 ) >>> from entry-point ReadingStream ) >>> then >>> System.out.print ("alert: Reading high for 30 seconds \n"); >>> end >>> >>> This does not detect detect the bad reading. However, If I changed the >>> rule >>> to be following (change second condition from "not" to "exists"), it >>> detects >>> all readings that are good. >>> >>> rule "rule1" >>> dialect "mvel" >>> when >>> $rd1 : mReading( reading >90 ) from entry-point ReadingStream >>> exists ($rd2 : mReading (reading<=90 , this before [0s, 30s] $rd1 ) >>> from entry-point ReadingStream ) >>> then >>> System.out.print ("alert: Reading high for 30 seconds \n"); >>> End >>> >>> >>> Is this an issue in CEP or did I do something wrong? >>> >>> Thanks a lot! >>> Lily >>> >>> >>> >>> -- >>> View this message in context: >>> http://drools.46999.n3.nabble.com/sliding-window-question-tp4028367.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 >> _______________________________________________ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users > > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users