Modify auto-assign with advance order, based on code review. #381

This commit is contained in:
Korina Cordero 2020-04-21 03:23:23 +00:00
parent a7b5bf18ff
commit 21700e7922

View file

@ -1015,7 +1015,7 @@ class APIController extends Controller implements LoggedController
} }
else else
{ {
$nearest_hub = $this->findAdvanceNearestHub($jo, $request_time, $em, $map_tools); $nearest_hub = $this->findAdvanceNearestHub($jo, $request_time_in_int, $em, $map_tools);
} }
if (!empty($nearest_hub)) if (!empty($nearest_hub))
@ -2731,40 +2731,88 @@ class APIController extends Controller implements LoggedController
{ {
// get time schedule // get time schedule
$date_schedule = $advance_jo->getDateSchedule(); $date_schedule = $advance_jo->getDateSchedule();
$time_schedule = $date_schedule->format('H'); $time_schedule = $date_schedule->format('H:i');
switch ($time_schedule) { $hour_schedule = $date_schedule->format('H');
case '8': $minute_schedule = $date_schedule->format('i');
$hub_rider_slots[0]--;
break; // check minutes. for now, if not 00, take up current slot and next one
case '9': // if hour fits in the last slot but minutes is not 00, move to the next available hub
$hub_rider_slots[1]--; // TODO: need to add custom minutes threshold
break; if ($minute_schedule != '00')
case '10': {
$hub_rider_slots[2]--; switch($hour_schedule) {
break; case '8':
case '11': $hub_rider_slots[0]--;
$hub_rider_slots[3]--; $hub_rider_slots[1]--;
break; break;
case '12': case '9':
$hub_rider_slots[4]--; $hub_rider_slots[1]--;
break; $hub_rider_slots[2]--;
case '13': break;
$hub_rider_slots[5]--; case '10':
break; $hub_rider_slots[2]--;
case '14': $hub_rider_slots[3]--;
$hub_rider_slots[6]--; break;
break; case '11':
case '15': $hub_rider_slots[3]--;
$hub_rider_slots[7]--; $hub_rider_slots[4]--;
break; break;
default: case '12':
error_log('Does not fit in any time slot.'); $hub_rider_slots[4]--;
$hub_rider_slots[5]--;
break;
case '13':
$hub_rider_slots[5]--;
$hub_rider_slots[6]--;
break;
case '14':
$hub_rider_slots[6]--;
$hub_rider_slots[7]--;
break;
case '15':
error_log('No slots for the day');
break;
default:
error_log('Does not fit in any time slot. ' . $time_schedule);
}
} }
else
{
switch ($hour_schedule) {
case '8':
$hub_rider_slots[0]--;
break;
case '9':
$hub_rider_slots[1]--;
break;
case '10':
$hub_rider_slots[2]--;
break;
case '11':
$hub_rider_slots[3]--;
break;
case '12':
$hub_rider_slots[4]--;
break;
case '13':
$hub_rider_slots[5]--;
break;
case '14':
$hub_rider_slots[6]--;
break;
case '15':
$hub_rider_slots[7]--;
break;
default:
error_log('Does not fit in any time slot.' . $time_schedule);
}
}
} }
// find first free slot // find first free slot
foreach ($hub_rider_slots as $index=>$rider_slot) foreach ($hub_rider_slots as $index => $rider_slot)
{ {
if ($rider_slot > 0) if ($rider_slot > 0)
{ {
@ -2808,9 +2856,6 @@ class APIController extends Controller implements LoggedController
break; break;
} }
} }
return $results; return $results;
} }
} }