I would recommend you to read the drools manual and the examples, especially
the introduction... rule based programming is somewhat different from more
traditional procedural (e.g. java) programming. It may let you solve your
problems efficiently and elegantly, or just give you headaches.. :)
Now, as for the examples:
1) the "then" in a rule is a "when premise then conclusion", as in (a
of) "logic", not a "then" as in "first this then that", as
programming. SO, the premise is about collecting (joining) and matching
(selecting) data against patterns. This said, the accumulate has to be in
the LHS, not in the RHS.
2) I guess you're trying to compare the average temperature against ? is
$max the max temperature? Or a threshold you provide from somewhere else?
3) I also guess you want to use the average temperature in the other rule...
As Wolfgang pointed out,
you have to insert it in the working memory (or use a global, but this may
not the best of practices). Moreover, it's more useful to use the value to
create an instance of a more "meaningful" class than simply inserting a
Number. What if other rules insert Numbers?
4) Maybe you also want to make the number related to the person? It's an
interesting exercise on joins, to see what happens if you add that "foreign
key" or not
5) You may not need to use agenda groups, if your rules are implicitly made
sequential by the patterns. If a rule can only matched something potentially
inserted by another, there is no way for that rule to fire until the other
has been fired itself.
// pers : Person
avg : double
$pers : person : Person( gender == 'M' )
SensorReading( $temp : temperature ) over window:time( 10m ),
$max : max( $temp ), // this is the max temperature over
the window, but this can't be your "$max"...
$avg : average( $temp )
// $avg > MAX // where do you get the threshold from?
insertLogical( /*$pers,*/ new AverageTempRecord( $avg ) );
rule "Hello MR"
$p : Person()
$a : AverageTemperatureRecord( /* pers == $p, */ $avg : avg )
System.out.println( "Hello mr " + $p.getName() + ", your temp is "
retract( $p );
View this message in context:
Sent from the Drools: User forum mailing list archive at Nabble.com