[rules-users] Collect with same value

wendy w.mungovan at yahoo.com
Thu Aug 11 07:06:49 EDT 2011


I'm still not sure I can make my rule work like that.  Sorry, my real problem
is a little more complicated then I initially described.

We are trying to detect if some set of conditions stay within a set of
ranges over a period of time.  So still using the example below.  The color
is really the key for the shape and the size can change over time.  For
example, we would want to know if any shape's size was larger than 5 for 20
min.

I see how you are making a map that would have a list of all the shapes of
the same color.  So $map['BLUE'] would return all shapes

and $shape: Shapes( $color: color, size > 5 ) could change to $shape:
Shapes( $color: color, size > 5 ) over window:time(20m) to only get Shape
sizes for the last 20 min.

now this would be a map where the key would be the color and the value would
be the min size over a 20 min window.

//untested
$map: Map()
    from accumulate ( $shape: Shapes( $color: color) over window:time(20m),
      init( Map m = new HashMap(); ),
      action( Number min = m.get( $color );
                 if( min == null ) m.put($shape.size);
                 else if (min > $shape.size) m.put($shape.size);),
      result( m ) )

and then I would need to iterate through the map and find all the ones whose
min size > 5?



--
View this message in context: http://drools.46999.n3.nabble.com/Collect-with-same-value-tp3242904p3245580.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list