[rules-users] Collect with same value

Wolfgang Laun wolfgang.laun at gmail.com
Thu Aug 11 08:39:30 EDT 2011


On 11 August 2011 13:06, wendy <w.mungovan at yahoo.com> wrote:

> 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.
>

Yes.


>
> 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?
>
> I don't see why you would need a map with mininum size per color. If you
restrict
   accumulate ( $shape: Shapes( $color: color, size > 5 )
you won't get any list in the map where there is a shape with size <= 5. By
investigating the map I proposed you can still find the minimum sizes > 5 -
these are the minimum sizes in each list.

-W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110811/79942b70/attachment.html 


More information about the rules-users mailing list