Add all other services to auto assign hub / rider #374
This commit is contained in:
parent
9c0f86e588
commit
1ee744eba0
1 changed files with 71 additions and 24 deletions
|
|
@ -992,33 +992,38 @@ class APIController extends Controller implements LoggedController
|
|||
{
|
||||
// get nearest hub
|
||||
$nearest_hub = $this->findNearestHubWithInventory($jo, $batt, $em, $map_tools, $im);
|
||||
if (!empty($nearest_hub))
|
||||
}
|
||||
else
|
||||
{
|
||||
$nearest_hub = $this->findNearestHub($jo, $em, $map_tools, $im);
|
||||
}
|
||||
|
||||
if (!empty($nearest_hub))
|
||||
{
|
||||
// assign rider
|
||||
$available_riders = $nearest_hub->getAvailableRiders();
|
||||
if (count($available_riders) > 0)
|
||||
{
|
||||
// assign rider
|
||||
$available_riders = $nearest_hub->getAvailableRiders();
|
||||
if (count($available_riders) > 0)
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) > 1)
|
||||
{
|
||||
$assigned_rider = null;
|
||||
if (count($available_riders) > 1)
|
||||
// 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)
|
||||
{
|
||||
// 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);
|
||||
$riders[] = $rider;
|
||||
}
|
||||
else
|
||||
$assigned_rider = $available_riders[0];
|
||||
|
||||
$jo->setHub($nearest_hub);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
$assigned_rider = $this->randomizeRider($riders);
|
||||
}
|
||||
else
|
||||
$assigned_rider = $available_riders[0];
|
||||
|
||||
$jo->setHub($nearest_hub);
|
||||
$jo->setRider($assigned_rider);
|
||||
$jo->setStatus(JOStatus::ASSIGNED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2253,6 +2258,48 @@ class APIController extends Controller implements LoggedController
|
|||
return $cust;
|
||||
}
|
||||
|
||||
protected function findNearestHub($jo, Battery $batt, EntityManagerInterface $em,
|
||||
MapTools $map_tools, InventoryManager $im)
|
||||
{
|
||||
// get the nearest 10 hubs
|
||||
$selected_hub = null;
|
||||
$hubs = $map_tools->getClosestOpenHubs($jo->getCoordinates(), 10, date("H:i:s"));
|
||||
|
||||
$nearest_hubs_with_distance = [];
|
||||
$nearest_branch_codes = [];
|
||||
foreach ($hubs as $hub)
|
||||
{
|
||||
$nearest_hubs_with_distance[] = $hub;
|
||||
//if (!empty($hub['hub']->getBranchCode()))
|
||||
// $nearest_branch_codes[] = $hub['hub']->getBranchCode();
|
||||
}
|
||||
|
||||
// check if nearest hubs have branch codes
|
||||
//if (count($nearest_branch_codes) == 0)
|
||||
// return $selected_hub;
|
||||
|
||||
// assume all 10 have stock
|
||||
// find the nearest hub with available riders
|
||||
$nearest = null;
|
||||
foreach ($nearest_hubs_with_distance as $nhd)
|
||||
{
|
||||
if (count($nhd['hub']->getAvailableRiders()) > 0)
|
||||
{
|
||||
if (empty($nearest))
|
||||
$nearest = $nhd;
|
||||
else
|
||||
{
|
||||
if ($nhd['distance'] < $nearest['distance'])
|
||||
$nearest = $nhd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selected_hub = $nearest['hub'];
|
||||
|
||||
return $selected_hub;
|
||||
}
|
||||
|
||||
protected function findNearestHubWithInventory($jo, Battery $batt, EntityManagerInterface $em,
|
||||
MapTools $map_tools, InventoryManager $im)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue