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