add sparse workload placement
This commit is contained in:
parent
ff8efd7f4a
commit
90dcc8665a
3 changed files with 55 additions and 16 deletions
|
|
@ -18,7 +18,7 @@ class EvenDistributionScheduler
|
|||
$differenceInDays = $startDate->diff($targetDate)->days;
|
||||
$dayCount = $differenceInDays + 1;
|
||||
|
||||
if ($assignmentCount < $dayCount) {
|
||||
if ($workloadPlacement === WorkloadPlacement::Spread) {
|
||||
return $this->sparseDates(
|
||||
assignmentCount: $assignmentCount,
|
||||
dayCount: $dayCount,
|
||||
|
|
@ -26,7 +26,7 @@ class EvenDistributionScheduler
|
|||
);
|
||||
}
|
||||
|
||||
return $this->dailyDates(
|
||||
return $this->groupedDates(
|
||||
assignmentCount: $assignmentCount,
|
||||
dayCount: $dayCount,
|
||||
startDate: $startDate,
|
||||
|
|
@ -63,17 +63,17 @@ class EvenDistributionScheduler
|
|||
/**
|
||||
* @return list<DateTimeImmutable>
|
||||
*/
|
||||
private function dailyDates(
|
||||
private function groupedDates(
|
||||
int $assignmentCount,
|
||||
int $dayCount,
|
||||
DateTimeImmutable $startDate,
|
||||
WorkloadPlacement $workloadPlacement,
|
||||
): array {
|
||||
$assignmentsPerDay = intdiv($assignmentCount, $dayCount);
|
||||
$heavierDayCount = $assignmentCount % $dayCount;
|
||||
$heavierBlockStart = $this->heavierBlockStart(
|
||||
$remainderDayCount = $assignmentCount % $dayCount;
|
||||
$remainderBlockStart = $this->remainderBlockStart(
|
||||
dayCount: $dayCount,
|
||||
heavierDayCount: $heavierDayCount,
|
||||
remainderDayCount: $remainderDayCount,
|
||||
workloadPlacement: $workloadPlacement,
|
||||
);
|
||||
$dates = [];
|
||||
|
|
@ -81,8 +81,8 @@ class EvenDistributionScheduler
|
|||
for ($dayIndex = 0; $dayIndex < $dayCount; $dayIndex++) {
|
||||
$assignmentCountForDay = $assignmentsPerDay;
|
||||
if (
|
||||
$dayIndex >= $heavierBlockStart
|
||||
&& $dayIndex < $heavierBlockStart + $heavierDayCount
|
||||
$dayIndex >= $remainderBlockStart
|
||||
&& $dayIndex < $remainderBlockStart + $remainderDayCount
|
||||
) {
|
||||
$assignmentCountForDay++;
|
||||
}
|
||||
|
|
@ -96,9 +96,9 @@ class EvenDistributionScheduler
|
|||
return $dates;
|
||||
}
|
||||
|
||||
private function heavierBlockStart(
|
||||
private function remainderBlockStart(
|
||||
int $dayCount,
|
||||
int $heavierDayCount,
|
||||
int $remainderDayCount,
|
||||
WorkloadPlacement $workloadPlacement,
|
||||
): int {
|
||||
if ($workloadPlacement === WorkloadPlacement::Start) {
|
||||
|
|
@ -106,9 +106,9 @@ class EvenDistributionScheduler
|
|||
}
|
||||
|
||||
if ($workloadPlacement === WorkloadPlacement::End) {
|
||||
return $dayCount - $heavierDayCount;
|
||||
return $dayCount - $remainderDayCount;
|
||||
}
|
||||
|
||||
return intdiv($dayCount - $heavierDayCount, 2);
|
||||
return intdiv($dayCount - $remainderDayCount, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue