[rules-dev] Rule syntax to accumulate time segments over a limited set of date ranges

Greg Barton greg_barton at yahoo.com
Fri May 7 12:59:26 EDT 2010


Two suggestions:

1) Use the joda time library for representing date/time if possible.  It's bundled with droole because of fusion and is much easier to work with.

2) If you use some "ugly" pattern often, define a custom operator to makw the syntax cleaner. 

GreG

On May 7, 2010, at 11:13, Bill Hainaut <billhainaut at gmail.com> wrote:


This seems to do the trick.  I hate the ugly date math, but otherwise, I'm
satisfied:

   $s : SeatAssignment ( )
   $mission : CrewSegment( taskBeingTested == true )
       $total : Number( doubleValue > 56 ) 
              from accumulate( CrewSegment( personId == $s.personId,
endDate.time <= $mission.endDate.time, startDate.time >
($mission.endDate.time - (7L * 24L * 60L * 60L * 1000L)), $crewHours :
crewHours ),
                               sum( $crewHours ) )



Bill Hainaut wrote:

Drools Experts:

I have a list of the following fact objects sent to my rules:

CrewSegment
Date startDate
Date endDate
double crewHours
int personId

along with an object to designate seats:

SeatAssignment
int seatId
int personId

Here is the rule I want to enforce in English: No crew member (uniquely  
identified by personId) can have more than 56 hours of total crewHours in  
any 7 day period. The rule I've written so far is:

when
$s : SeatAssignment ( )
$total : Number( doubleValue > 56 )
from accumulate( CrewSegment( personId == $s.personId, $crewHours :  
crewHours ),
sum( $crewHours ) )

This rule nicely catches any instance where more than 56 hours are  
committed by a person, but does not limit the time period to 7 days.

How do I limit the search to be sure that it is 56 hours WITHIN 7 days,
and  
not just 56 hours total over ANY time period?

Thanks in advance for any help you can provide!!!

Bill

_______________________________________________
rules-dev mailing list
rules-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Rule-syntax-to-accumulate-time-segments-over-a-limited-set-of-date-ranges-tp782165p784099.html
Sent from the Drools - Dev mailing list archive at Nabble.com.
_______________________________________________
rules-dev mailing list
rules-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



      


More information about the rules-dev mailing list