[rules-users] Monitoring sensor parameter change

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jun 11 23:28:45 EDT 2013


My intent was to have a single LastReading, updated with the latest Reading
- hence no constraint in the rule responsible for creating this singleton
fact.
-W


On 11 June 2013 21:37, Greg Barton <greg_barton at yahoo.com> wrote:

> rule "first Reading"
> when
>    $r: Reading()
>    not LastReading( this == $r )
> then
>    insert( new LastReading( $r ) );
> end
>
>   ------------------------------
>  *From:* Wolfgang Laun <wolfgang.laun at gmail.com>
> *To:* Rules Users List <rules-users at lists.jboss.org>
> *Sent:* Tuesday, June 11, 2013 12:07 PM
> *Subject:* Re: [rules-users] Monitoring sensor parameter change
>
> 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<http://nabble.com/>
> .
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> 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/20130612/5adbdc4c/attachment-0001.html 


More information about the rules-users mailing list