Fill the task calendar's working days in order instead of evenly
A task's estimate now takes each working day of its planned period up to the assignee's free capacity before the next day gets anything, so 9 h is booked as 7.5 h + 1.5 h rather than 4.5 h + 4.5 h. What does not fit in the period still moves past its end and makes the task end later. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -11,19 +11,16 @@ use DateTimeImmutable;
|
||||
/**
|
||||
* Books a task's estimated time from its assignee's days (spec 18.3).
|
||||
*
|
||||
* The estimate is split evenly over the working days of the planned
|
||||
* period (not Saturdays, Sundays or holidays); a period of only such days
|
||||
* splits it over all its days. No day gets more than the assignee's free
|
||||
* capacity (the daily maximum minus what other open tasks already book):
|
||||
* what does not fit moves to the next day of the period, and past its
|
||||
* end to the next working days, which makes the task end later. Other
|
||||
* tasks' bookings never move.
|
||||
* The estimate fills the working days of the planned period in order
|
||||
* (not Saturdays, Sundays or holidays; a period of only such days uses
|
||||
* all its days): each day gets the assignee's free capacity (the daily
|
||||
* maximum minus what other open tasks already book) before the next day
|
||||
* gets anything. What does not fit in the period moves to the next
|
||||
* working days after it, which makes the task end later. Other tasks'
|
||||
* bookings never move.
|
||||
*/
|
||||
final class TaskScheduler
|
||||
{
|
||||
/** Bookings are made in quarter hours, like time entries. */
|
||||
private const int STEP_MINUTES = 15;
|
||||
|
||||
/** How far past the planned end the overflow may go. */
|
||||
private const int MAX_EXTRA_DAYS = 366;
|
||||
|
||||
@@ -51,14 +48,16 @@ final class TaskScheduler
|
||||
$targets = $days;
|
||||
}
|
||||
|
||||
$shares = self::split($minutes, count($targets));
|
||||
$booked = [];
|
||||
$carry = 0;
|
||||
$carry = $minutes;
|
||||
|
||||
foreach ($targets as $index => $day) {
|
||||
$wanted = $shares[$index] + $carry;
|
||||
$booking = min($wanted, self::free($day, $otherMinutes, $capacityMinutes));
|
||||
$carry = $wanted - $booking;
|
||||
foreach ($targets as $day) {
|
||||
if ($carry === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$booking = min($carry, self::free($day, $otherMinutes, $capacityMinutes));
|
||||
$carry -= $booking;
|
||||
|
||||
if ($booking > 0) {
|
||||
$booked[$day] = $booking;
|
||||
@@ -198,27 +197,6 @@ final class TaskScheduler
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the minutes into equal quarter-hour shares; the first days get
|
||||
* the remainder. Odd minutes go to the first day.
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
private static function split(int $minutes, int $parts): array
|
||||
{
|
||||
$steps = intdiv($minutes, self::STEP_MINUTES);
|
||||
$odd = $minutes % self::STEP_MINUTES;
|
||||
$shares = [];
|
||||
|
||||
for ($index = 0; $index < $parts; $index++) {
|
||||
$shares[] = (intdiv($steps, $parts) + ($index < $steps % $parts ? 1 : 0)) * self::STEP_MINUTES;
|
||||
}
|
||||
|
||||
$shares[0] += $odd;
|
||||
|
||||
return $shares;
|
||||
}
|
||||
|
||||
/**
|
||||
* Books the carried minutes on the working days after the day; what
|
||||
* finds no free time within MAX_EXTRA_DAYS goes on the last day tried.
|
||||
|
||||
+1
-1
@@ -527,7 +527,7 @@ Jokainen sivu täyttää saavutettavuusvaatimukset ja saa selaintestin (vaalea/t
|
||||
### 18.3 Tehtäväkalenteri *(valmis)*
|
||||
- Valikon Kalenteri (`/jobs/calendar`, kaikki kirjautuneet): rullaava kaksi viikkoa tästä päivästä, painikkeet Edelliset 2 viikkoa / Tänään / Seuraavat 2 viikkoa. Rivi jokaiselle aktiiviselle käyttäjälle (oma rivi ensin) ja rivi Ei tekijää; suodattimet palveluyksikkö ja Vain oma rivi. Alihankkija näkee vain oman rivinsä ja liitettyjen töidensä tehtävät, ja hän voi vaihtaa vain tilaa.
|
||||
- Tehtävällä on aikataulu (suunniteltu alku ja loppu), joka näkyy palkkina tekijän rivillä (jäsenten riveillä ei). Päällekkäiset tehtävät pinotaan omille kaistoilleen, joten samalle päivälle voi asettaa useita lyhyitä tehtäviä. Palkissa näkyvät nimi, työn numero, tila tekstinä ja tunnit; jos aikataulu päättyy määräpäivän jälkeen, palkissa on "Myöhässä" kuvakkeineen.
|
||||
- **Päiväkuorma:** tehtävän arvioitu aika varataan tekijältä (jäseniltä ei) ja jaetaan tasan jakson arkipäiville; arkipäiviä eivät ole la, su eivätkä käytössä olevat arkipyhät. Jos jaksossa on vain viikonloppu- tai pyhäpäiviä, arvio jaetaan niille. Henkilön päivään varataan enintään päiväkatto (Yritystiedoissa, oletus 7,5 h, asetus `shared.daily_capacity_hours`) miinus muiden avoimien tehtävien varaukset; ylittävä osa siirtyy seuraavalle arkipäivälle, ja tehtävän loppu siirtyy myöhemmäksi (ilmoitetaan). Muiden tehtävien varaukset eivät muutu. Valmiit tehtävät eivät vie kapasiteettia. Päivän solussa näkyy kuorma, esim. "6 / 8 h". Ilman arviota tehtävä ei kuormita.
|
||||
- **Päiväkuorma:** tehtävän arvioitu aika varataan tekijältä (jäseniltä ei) jakson arkipäiville järjestyksessä: ensimmäinen päivä täytetään ennen seuraavaa (esim. 9 h → 7,5 h + 1,5 h). Arkipäiviä eivät ole la, su eivätkä käytössä olevat arkipyhät. Jos jaksossa on vain viikonloppu- tai pyhäpäiviä, arvio varataan niille. Henkilön päivään varataan enintään päiväkatto (Yritystiedoissa, oletus 7,5 h, asetus `shared.daily_capacity_hours`) miinus muiden avoimien tehtävien varaukset; ylittävä osa siirtyy seuraavalle arkipäivälle. Jos arvio ei mahdu jaksoon, loput varataan jakson jälkeisille arkipäiville ja tehtävän loppu siirtyy myöhemmäksi (ilmoitetaan). Muiden tehtävien varaukset eivät muutu. Valmiit tehtävät eivät vie kapasiteettia. Päivän solussa näkyy kuorma, esim. "6 / 8 h". Ilman arviota tehtävä ei kuormita.
|
||||
- **Muutokset hiirellä:** palkin rungosta vetämällä tehtävä siirtyy ajassa ja toisen henkilön riville (uuden rivin henkilöstä tulee tekijä, jäsenet säilyvät); reunoista vetämällä muuttuu alku tai loppu. Aikatauluttamattomat avoimet tehtävät listataan kalenterin alla, ja ne voi vetää päivälle; ilman loppua tehtävä saa niin monta arkipäivää kuin arvio päiväkatolla vaatii.
|
||||
- **Näppäimistöllä:** jokainen palkki on painike, joka avaa dialogin: alkaa, päättyy, tekijä, tila, linkit työhön ja tehtävän muokkaukseen sekä Poista aikataulu. Muutos ilmoitetaan `aria-live`-alueella ja fokus palaa palkkiin. Puhelimella ja kapeassa ikkunassa ruudukon sijaan näytetään lista henkilöittäin samoin dialogein.
|
||||
- Tehtävän lomakkeella on kentät Aikataulu alkaa ja Aikataulu päättyy, ja työn sivun tehtäväkortissa näkyy aikataulu.
|
||||
|
||||
@@ -55,7 +55,7 @@ it('moves a task to another person by dropping it and books their days', functio
|
||||
expect($task->refresh()->planned_from?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and($task->planned_to?->format('Y-m-d'))->toBe('2026-12-29')
|
||||
->and($task->assignee_user_id)->toBe($this->other->id)
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 360, '2026-12-29' => 360]);
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 450, '2026-12-29' => 270]);
|
||||
});
|
||||
|
||||
it('continues a task on the next working day when the day is full', function () {
|
||||
|
||||
@@ -156,11 +156,11 @@ it('does not remove a task with time entries', function () {
|
||||
->and(JobStatus::OnHold->locksTime())->toBeFalse();
|
||||
});
|
||||
|
||||
it('books a scheduled task evenly from the working days of its period', function () {
|
||||
it('books a scheduled task by filling the working days of its period in order', function () {
|
||||
$taskId = $this->addTask->execute($this->jobId, new TaskData('Taitto', 11, 'waiting', estimatedHours: '12', assigneeUserId: 10, plannedFrom: '2026-12-04', plannedTo: '2026-12-07'), 10);
|
||||
$oneDayId = $this->addTask->execute($this->jobId, new TaskData('Palaveri', 91, 'waiting', assigneeUserId: 10, plannedFrom: '2026-12-08'), 10);
|
||||
|
||||
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 360, '2026-12-07' => 360])
|
||||
expect($this->bookings->of($taskId, 10))->toBe(['2026-12-04' => 480, '2026-12-07' => 240])
|
||||
->and($this->tasks->findForJob($this->jobId, $oneDayId)?->plannedTo()?->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and($this->bookings->of($oneDayId, 10))->toBe([]);
|
||||
});
|
||||
|
||||
@@ -7,11 +7,11 @@ function scheduleDay(string $date): DateTimeImmutable
|
||||
return new DateTimeImmutable($date);
|
||||
}
|
||||
|
||||
it('splits the estimate evenly over the working days of the period', function () {
|
||||
it('fills the working days of the period in order', function () {
|
||||
// Fri 4.12.2026 – Tue 8.12.2026; the weekend in between gets nothing.
|
||||
$schedule = TaskScheduler::schedule(scheduleDay('2026-12-04'), scheduleDay('2026-12-08'), 600, [], 480, []);
|
||||
|
||||
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 210, '2026-12-07' => 195, '2026-12-08' => 195])
|
||||
expect($schedule->minutesByDay)->toBe(['2026-12-04' => 480, '2026-12-07' => 120])
|
||||
->and($schedule->end->format('Y-m-d'))->toBe('2026-12-08')
|
||||
->and($schedule->extended)->toBeFalse();
|
||||
});
|
||||
@@ -21,7 +21,7 @@ it('skips holidays and uses weekend days when the period has nothing else', func
|
||||
$weekend = TaskScheduler::schedule(scheduleDay('2026-12-05'), scheduleDay('2026-12-06'), 300, [], 480, []);
|
||||
|
||||
expect($overHolidays->minutesByDay)->toBe(['2026-12-28' => 240])
|
||||
->and($weekend->minutesByDay)->toBe(['2026-12-05' => 150, '2026-12-06' => 150]);
|
||||
->and($weekend->minutesByDay)->toBe(['2026-12-05' => 300]);
|
||||
});
|
||||
|
||||
it('moves what does not fit to the next working days and ends later', function () {
|
||||
|
||||
Reference in New Issue
Block a user