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(a)yahoo.com> wrote:
rule "first Reading"
when
$r: Reading()
not LastReading( this == $r )
then
insert( new LastReading( $r ) );
end
------------------------------
*From:* Wolfgang Laun <wolfgang.laun(a)gmail.com>
*To:* Rules Users List <rules-users(a)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(a)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...
Sent from the Drools: User forum mailing list archive at
Nabble.com<http://nabble.com/>
.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users