From 406568ab3dcf89c6996ff75b1a13e6722493e762 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 30 Jul 2021 08:03:40 +0000 Subject: [PATCH 1/4] Add the two flags to Hub. #607 --- src/Entity/Hub.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Entity/Hub.php b/src/Entity/Hub.php index 2d742b73..4e24ac0a 100644 --- a/src/Entity/Hub.php +++ b/src/Entity/Hub.php @@ -80,6 +80,18 @@ class Hub */ protected $payment_methods; + // flag if hub can be auto assigned + /** + * @ORM\Column(type="boolean") + */ + protected $flag_hub_auto_assign; + + // flag if riders assigned to hub can be auto assigned + /** + * @ORM\Column(type="boolean") + */ + protected $flag_rider_auto_assign; + public function __construct() { $this->time_open = new DateTime(); @@ -90,6 +102,8 @@ class Hub $this->flag_hub_view = false; $this->notif_number = ''; $this->payment_methods = new ArrayCollection(); + $this->flag_hub_auto_assign = false; + $this->flag_rider_auto_assign = false; } public function getRiders() @@ -232,4 +246,28 @@ class Hub $this->payment_methods = new ArrayCollection(); return $this; } + + public function setAutoAssignHubFlag($flag_hub_auto_assign = true) + { + $this->flag_hub_auto_assign = $flag_hub_auto_assign; + return $this; + } + + public function isAutoAssignHub() + { + return $this->flag_hub_auto_assign; + } + + public function setAutoAssignRiderFlag($flag_rider_auto_assign = true) + { + $this->flag_rider_auto_assign = $flag_rider_auto_assign; + return $this; + } + + public function isAutoAssignRider() + { + return $this->flag_rider_auto_assign; + } + + } From 04e803510ca52a8a9b7f6237c3add47a61a95782 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 30 Jul 2021 08:34:12 +0000 Subject: [PATCH 2/4] Set default value for flags. #607 --- src/Entity/Hub.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/Hub.php b/src/Entity/Hub.php index 4e24ac0a..2d98ea7f 100644 --- a/src/Entity/Hub.php +++ b/src/Entity/Hub.php @@ -82,13 +82,13 @@ class Hub // flag if hub can be auto assigned /** - * @ORM\Column(type="boolean") + * @ORM\Column(type="boolean", options={"default"=false}) */ protected $flag_hub_auto_assign; // flag if riders assigned to hub can be auto assigned /** - * @ORM\Column(type="boolean") + * @ORM\Column(type="boolean", options={"default"=false}) */ protected $flag_rider_auto_assign; From 49fdfa9ea6ae6edc230bbd06e5c6c159b3f3e770 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 30 Jul 2021 17:16:43 +0800 Subject: [PATCH 3/4] Update hub form and controller to support the new auto assign flags #607 --- src/Controller/HubController.php | 2 ++ src/Entity/Hub.php | 4 ++-- templates/hub/form.html.twig | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Controller/HubController.php b/src/Controller/HubController.php index 21c4758d..74c05a7a 100644 --- a/src/Controller/HubController.php +++ b/src/Controller/HubController.php @@ -161,6 +161,8 @@ class HubController extends Controller ->setRiderSlots($req->request->get('rider_slots', 0)) ->setHubViewFlag($req->request->get('flag_hub_view', false)) ->setNotifNumber($req->request->get('notif_number')) + ->setAutoAssignHub($req->request->get('flag_hub_auto_assign', false)) + ->setAutoAssignRider($req->request->get('flag_rider_auto_assign', false)) ->clearPaymentMethods(); // set payment methods diff --git a/src/Entity/Hub.php b/src/Entity/Hub.php index 2d98ea7f..c76f35bc 100644 --- a/src/Entity/Hub.php +++ b/src/Entity/Hub.php @@ -247,7 +247,7 @@ class Hub return $this; } - public function setAutoAssignHubFlag($flag_hub_auto_assign = true) + public function setAutoAssignHub($flag_hub_auto_assign = true) { $this->flag_hub_auto_assign = $flag_hub_auto_assign; return $this; @@ -258,7 +258,7 @@ class Hub return $this->flag_hub_auto_assign; } - public function setAutoAssignRiderFlag($flag_rider_auto_assign = true) + public function setAutoAssignRider($flag_rider_auto_assign = true) { $this->flag_rider_auto_assign = $flag_rider_auto_assign; return $this; diff --git a/templates/hub/form.html.twig b/templates/hub/form.html.twig index 3c8947c1..324a396b 100644 --- a/templates/hub/form.html.twig +++ b/templates/hub/form.html.twig @@ -118,6 +118,22 @@ +
+ + + + + + +
From f54476a1737a12c7faa19f1ecae2763aaaac16d6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 30 Jul 2021 10:46:20 +0000 Subject: [PATCH 4/4] Add checking of flags for JO auto assignment. #607 --- src/Controller/APIController.php | 94 +++++++++++++++++++++----------- src/Controller/HubController.php | 4 +- src/Entity/Hub.php | 8 +-- src/Service/MapTools.php | 8 ++- templates/hub/form.html.twig | 4 +- 5 files changed, 76 insertions(+), 42 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index b87bc73b..cfe35773 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2814,49 +2814,81 @@ class APIController extends Controller implements LoggedController { // go through the hub list, find the nearest hub // with an available rider - //error_log('found nearest hub ' . $nearest_hub->getID()); + // error_log('found nearest hub ' . $nearest_hub->getID()); foreach ($nearest_hubs as $nearest_hub) { - $available_riders = $nearest_hub['hub']->getAvailableRiders(); - if (count($available_riders) >= 1) + // check if hub can be auto assigned + // if not, move on to the next hub in the list + if (($nearest_hub['hub']->isHubAutoAssign())) { - $assigned_rider = null; - if (count($available_riders) == 1) + // check if hub has riders that can be auto assigned + // if not, move on to the next hub + if (($nearest_hub['hub']->isRiderAutoAssign())) { - $assigned_rider = $available_riders[0]; + $available_riders = $nearest_hub['hub']->getAvailableRiders(); + if (count($available_riders) >= 1) + { + $assigned_rider = null; + if (count($available_riders) == 1) + { + $assigned_rider = $available_riders[0]; + } + else + { + // TODO: the setting of riders into an array + // will no longer be necessary when the contents + // of randomizeRider changes + $riders = []; + foreach ($available_riders as $rider) + { + $riders[] = $rider; + } + + $assigned_rider = $this->randomizeRider($riders); + } + + $jo->setHub($nearest_hub['hub']); + $jo->setRider($assigned_rider); + $jo->setStatus(JOStatus::ASSIGNED); + $jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED); + + $assigned_rider->setAvailable(false); + + // update redis hub_jo_count for hub + $hub_dist->incrementJoCountForHub($nearest_hub['hub']); + + // break out of loop + break; + } + else + { + // we just create the JO and let admin panel handle the hub assignment + // log hub into hub_filter_log + $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID()); + // continue to go through list to find hub with an available rider + } } else { - // TODO: the setting of riders into an array - // will no longer be necessary when the contents - // of randomizeRider changes - $riders = []; - foreach ($available_riders as $rider) - { - $riders[] = $rider; - } + // TODO: log hub as cannot be auto rider assigned somewhere + // assign hub + error_log('Rider cannot be auto assigned ' . $nearest_hub['hub']->getID()); + $jo->setHub($nearest_hub['hub']); + $jo->setStatus(JOStatus::RIDER_ASSIGN); + $jo->setStatusAutoAssign(AutoAssignStatus::HUB_ASSIGNED); - $assigned_rider = $this->randomizeRider($riders); + // update redis hub_jo_count for hub + $hub_dist->incrementJoCountForHub($nearest_hub['hub']); + + break; } - - $jo->setHub($nearest_hub['hub']); - $jo->setRider($assigned_rider); - $jo->setStatus(JOStatus::ASSIGNED); - $jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED); - - $assigned_rider->setAvailable(false); - - // update redis hub_jo_count for hub - $hub_dist->incrementJoCountForHub($nearest_hub['hub']); - - // break out of loop - break; } else { - // log hub into hub_filter_log - $hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider', null, $cust->getID()); - // continue to go through list to find hub with an available rider + // TODO: log hub as cannot be auto assigned somewhere + // move to next hub + error_log('Hub cannot be auto-assigned ' . $nearest_hub['hub']->getID()); + continue; } } } diff --git a/src/Controller/HubController.php b/src/Controller/HubController.php index 74c05a7a..09eca4bf 100644 --- a/src/Controller/HubController.php +++ b/src/Controller/HubController.php @@ -161,8 +161,8 @@ class HubController extends Controller ->setRiderSlots($req->request->get('rider_slots', 0)) ->setHubViewFlag($req->request->get('flag_hub_view', false)) ->setNotifNumber($req->request->get('notif_number')) - ->setAutoAssignHub($req->request->get('flag_hub_auto_assign', false)) - ->setAutoAssignRider($req->request->get('flag_rider_auto_assign', false)) + ->setHubAutoAssign($req->request->get('flag_hub_auto_assign', false)) + ->setRiderAutoAssign($req->request->get('flag_rider_auto_assign', false)) ->clearPaymentMethods(); // set payment methods diff --git a/src/Entity/Hub.php b/src/Entity/Hub.php index c76f35bc..da3a44b9 100644 --- a/src/Entity/Hub.php +++ b/src/Entity/Hub.php @@ -247,24 +247,24 @@ class Hub return $this; } - public function setAutoAssignHub($flag_hub_auto_assign = true) + public function setHubAutoAssign($flag_hub_auto_assign = true) { $this->flag_hub_auto_assign = $flag_hub_auto_assign; return $this; } - public function isAutoAssignHub() + public function isHubAutoAssign() { return $this->flag_hub_auto_assign; } - public function setAutoAssignRider($flag_rider_auto_assign = true) + public function setRiderAutoAssign($flag_rider_auto_assign = true) { $this->flag_rider_auto_assign = $flag_rider_auto_assign; return $this; } - public function isAutoAssignRider() + public function isRiderAutoAssign() { return $this->flag_rider_auto_assign; } diff --git a/src/Service/MapTools.php b/src/Service/MapTools.php index e1eac52e..13e3c9f8 100644 --- a/src/Service/MapTools.php +++ b/src/Service/MapTools.php @@ -154,11 +154,13 @@ class MapTools */ } - // NOTE: only the API calls this + // NOTE: only the API(findAdvanceNearestHubAndSlots) calls this public function getClosestOpenHubs(Point $point, $limit, $time = false) { // get closest hubs based on st_distance function from db - $query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h WHERE h.status_open = true'; + $query_string = 'SELECT h, st_distance(h.coordinates, point(:lng, :lat)) as dist FROM App\Entity\Hub h + WHERE h.status_open = true + AND h.flag_hub_auto_assign = true'; if ($time) $query_string .= ' AND :time BETWEEN h.time_open AND h.time_close'; $query_string .= ' ORDER BY dist'; @@ -172,7 +174,7 @@ class MapTools $query->setMaxResults($limit); - // error_log($query->getSql()); + //error_log($query->getSql()); $result = $query->getResult(); $hubs = []; diff --git a/templates/hub/form.html.twig b/templates/hub/form.html.twig index 324a396b..9ed950f4 100644 --- a/templates/hub/form.html.twig +++ b/templates/hub/form.html.twig @@ -121,14 +121,14 @@