I'm working in a nurseroster like project and I need a suggestion on a rule. The problem is: every employee can work in more than a flight per day, and the flights have different start time and end time. every employee is assigned to a flight in flightAssigment. Is there a rule able to calculate the total working hours considering the start time of the first flight and the end time of the last flight? for ex: flightAssignment1 employee1 start at 8:00 end at 10:00, flightAssigment2 employee1 start at 12:00 end at 15:00. The total working period for employee1 is 8:00 - 15:00 (7 hours).
I'm trying this one but it return an Unable to resolve ObjectType 'CheckinRoster.getEmployeeTotalHours' error:
rule "insertEmployeeAssignmentTotal"
salience 1 // Do these rules first (optional, for performance)
when
$employee : Employee()
$assignmentTotal : CheckinRoster.getEmployeeTotalHours($employee)
then
insertLogical(new EmployeeAssignmentTotal($employee, $assignmentTotal.intValue()));
end
OK I changed the rule in this way:
rule "test"
when
$employee : Employee()
accumulate(
FlightAssignment(employee == $employee, $start : minWorkedHour, $end : maxWorkedHour),
$max : max($end),
$min : min($start)
)
then
System.out.println($employee.getLabel() + " MIN: " + $min.intValue() + " --- MAX: " + $max.intValue());
scoreHolder.addSoftConstraintMatch(kcontext, -($max.intValue() - $min.intValue()));
end
Obtaining good results like this two:
Employee 1 MIN: 7 --- MAX: 21
Employee 2 MIN: 6 --- MAX: 21
But also bad results like this one that I related to something wrong in the integer conversion or other thing
Employee 3 MIN: 2147483647 --- MAX: -2147483648
The minWorkedHour and the maxWorkedHour are integer in the class FlightAssignemnt, the accumulator seems to be Double or float. What's the problem?