[rules-users] Monitoring sensor parameter change

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jun 11 13:07:35 EDT 2013


Basically a good approach.

declare LastReading
  last : Reading
end

// fire once, to set up LastReading with the very first Reading
rule "first Reading"
when
   $r: Reading()
   not LastReading()
then
   insert( new LastReading( $r ) );
end

// based on the existence of a previous reading...
rule "next Reading"
when
  $lr: LastReading( $last: last )
  Reading( this == $last, $pp: power )
then
end

// ...detect and handle an increment beyond the threshold
rule "next Reading, big increment"
extends "next Reading"
when
  $new: Reading( $np: power > $pp + 2 )
then
  update( $lr ){ setLast( $new ) }
  ... code for big increment
end

// ...detect and handle an increment below the threshold
rule "next Reading, small increment"
extends "next Reading"
when
   $new: Reading( this != $last, $np: power <= $pp + 2 )
then
  update( $lr ){ setLast( $new ) }
end

All of this is untested and may contain syntax errors. - The additional
constraint (this != $last) in the last rule avoids looping.
-W





On 11 June 2013 14:46, rjr201 <rich.j.riley at gmail.com> wrote:

> If I understand your question right, you could create a class called
> LastReading( SensorRead() ) and then your rules would look something like:
>
> rule 1 //check to see if the increase is > 2
> when
>    $last : LastReading( SensorRead($lastPower : power) )
>    SensorRead( $lastPower - power > 2)
> then
>    System.out.println("Power increased more than 2")
> end
>
> rule2 //update which sensor read is the lastest reading
> salience 100
> when
>    $last : LastReading( )
>    $new : SensorRead()
> then
>    retract($last)
>    insert(new LastReading($new))
> end
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/rules-users-Monitoring-sensor-parameter-change-tp4024242p4024243.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130611/89e35b29/attachment.html 


More information about the rules-users mailing list