From d8f5b7833d0b8f736fe61d24dc11ae0ca2efe290 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 23 Mar 2022 09:48:37 +0000 Subject: [PATCH 1/5] Add flag for unavailable slots. #651 --- src/Controller/APIController.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9fdd58a2..17aac2d9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4306,9 +4306,11 @@ class APIController extends Controller implements LoggedController // get the slots of hub $hub_slots = $this->getHubRiderSlots($hub, $em); + $slots = $hub_slots['slot_data']; + $hub_data = [ 'hub' => $hub, - 'slots' => $hub_slots, + 'slots' => $slots, ]; return $hub_data; } @@ -4328,6 +4330,8 @@ class APIController extends Controller implements LoggedController // find the nearest hub if (!empty($nearest_hubs_with_distance)) { + // TODO: get slots of nearest hub right after getting nearest hub. + // then check if hub has available slots. If not, get next nearest hub. foreach ($nearest_hubs_with_distance as $nhd) { if (empty($nearest)) @@ -4479,12 +4483,17 @@ class APIController extends Controller implements LoggedController protected function generateHubSlots($rider_slots, $slots) { $data = []; + $total_rslots = 0; + $total_unavailable_rslots = 0; foreach ($rider_slots as $day_id => $rslot) { $data[$day_id] = []; foreach ($rslot as $slot_id => $avail_slots) { + // increment total rider slots + $total_rslots++; + $slot_data = [ 'id' => $slot_id, 'label' => $slots[$slot_id], @@ -4493,14 +4502,27 @@ class APIController extends Controller implements LoggedController // mark unavailable ones if ($avail_slots <= 0) + { // increment total number of unavailable slots + $total_unavailable_rslots++; $slot_data['available'] = false; + } // add to day data $data[$day_id][] = $slot_data; } } - return $data; + // check if hub has available slots + $hub_unavailable = false; + if ($total_rslots == $total_unavailable_rslots) + $hub_unavailable = true; + + $hs_data = [ + 'flag_hub_available' => $hub_unavailable, + 'slot_data' => $data, + ]; + + return $hs_data; } protected function getTimeFromSlot($slot_id) -- 2.43.5 From b7c5f5dafe2edd38e56d7b3a2e0b6ad35851e069 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:07:26 +0000 Subject: [PATCH 2/5] Add checking for hub slots. #651 --- src/Controller/APIController.php | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 17aac2d9..5d6b16d2 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4330,7 +4330,7 @@ class APIController extends Controller implements LoggedController // find the nearest hub if (!empty($nearest_hubs_with_distance)) { - // TODO: get slots of nearest hub right after getting nearest hub. + // get slots of nearest hub right after getting nearest hub. // then check if hub has available slots. If not, get next nearest hub. foreach ($nearest_hubs_with_distance as $nhd) { @@ -4339,20 +4339,26 @@ class APIController extends Controller implements LoggedController else { if ($nhd['distance'] < $nearest['distance']) - $nearest = $nhd; + { + // get the slots for nearest which is nhd right now + $hub_slots = $this->getHubRiderSlots($nhd['hub'], $em); + + $flag_hub_available = $hub_slots['flag_hub_available']; + + // if hub is available, set hub to nearest + if ($flag_hub_available == true) + { + $nearest = $nhd; + + // temporarily set hub_data to nearest + $hub_data = [ + 'hub' => $nhd['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + } + } } } - - // get slots of nearest hub - if ($nearest != null) - { - $hub_slots = $this->getHubRiderSlots($nearest['hub'], $em); - - $hub_data = [ - 'hub' => $nearest['hub'], - 'slots' => $hub_slots, - ]; - } } return $hub_data; @@ -4477,6 +4483,8 @@ class APIController extends Controller implements LoggedController $hub_slots = $this->generateHubSlots($hub_rider_slots, $slots); + error_log(print_r($hub_slots, true)); + return $hub_slots; } @@ -4513,9 +4521,11 @@ class APIController extends Controller implements LoggedController } // check if hub has available slots - $hub_unavailable = false; + $hub_available = true; + error_log('total rider slots ' . $total_rslots); + error_log('total unavailable slots ' . $total_unavailable_slots); if ($total_rslots == $total_unavailable_rslots) - $hub_unavailable = true; + $hub_available = false; $hs_data = [ 'flag_hub_available' => $hub_unavailable, -- 2.43.5 From 457bbece2bdb1c04adcfb05944799b9fb458a7eb Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:28:15 +0000 Subject: [PATCH 3/5] Fix issues found while testing. #651 --- src/Controller/APIController.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 5d6b16d2..3e4d2906 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4326,6 +4326,7 @@ class APIController extends Controller implements LoggedController } $nearest = null; + $hub_slots = []; $slot_found = false; // find the nearest hub if (!empty($nearest_hubs_with_distance)) @@ -4349,18 +4350,18 @@ class APIController extends Controller implements LoggedController if ($flag_hub_available == true) { $nearest = $nhd; - - // temporarily set hub_data to nearest - $hub_data = [ - 'hub' => $nhd['hub'], - 'slots' => $hub_slots['slot_data'], - ]; } } } } } + // set hub data to what is in nearest + $hub_data = [ + 'hub' => $nearest['hub'], + 'slots' => $hub_slots['slot_data'], + ]; + return $hub_data; } @@ -4525,7 +4526,10 @@ class APIController extends Controller implements LoggedController error_log('total rider slots ' . $total_rslots); error_log('total unavailable slots ' . $total_unavailable_slots); if ($total_rslots == $total_unavailable_rslots) + { + error_log('hub has no available slots'); $hub_available = false; + } $hs_data = [ 'flag_hub_available' => $hub_unavailable, -- 2.43.5 From e80ce9db664e6884525f505f0568fc57b7458d84 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:38:18 +0000 Subject: [PATCH 4/5] Fix issues found while testing. #651 --- src/Controller/APIController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 3e4d2906..49cde869 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4336,7 +4336,16 @@ class APIController extends Controller implements LoggedController foreach ($nearest_hubs_with_distance as $nhd) { if (empty($nearest)) - $nearest = $nhd; + { + // get the slots for the hub to check if hub is available for assignment + $hub_slots = $this->getHubRiderSlots($nhd['hub'], $em); + + $flag_hub_available = $hub_slots['flag_hub_available']; + if ($flag_hub_available == true) + { + $nearest = $nhd; + } + } else { if ($nhd['distance'] < $nearest['distance']) -- 2.43.5 From 73f0e69b9ab4c815f66bbcb4749d9d672ba999fe Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 24 Mar 2022 05:50:02 +0000 Subject: [PATCH 5/5] Fix issues found while testing. #651 --- src/Controller/APIController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 49cde869..d10d8269 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -4533,7 +4533,7 @@ class APIController extends Controller implements LoggedController // check if hub has available slots $hub_available = true; error_log('total rider slots ' . $total_rslots); - error_log('total unavailable slots ' . $total_unavailable_slots); + error_log('total unavailable slots ' . $total_unavailable_rslots); if ($total_rslots == $total_unavailable_rslots) { error_log('hub has no available slots'); @@ -4541,7 +4541,7 @@ class APIController extends Controller implements LoggedController } $hs_data = [ - 'flag_hub_available' => $hub_unavailable, + 'flag_hub_available' => $hub_available, 'slot_data' => $data, ]; -- 2.43.5