Add logging of hub if hub has no available rider. #543

This commit is contained in:
Korina Cordero 2021-03-22 07:16:30 +00:00
parent 4966e7e0c6
commit a5aef93ccb

View file

@ -38,6 +38,7 @@ use App\Service\InventoryManager;
use App\Service\RiderAssignmentHandlerInterface;
use App\Service\HubSelector;
use App\Service\HubDistributor;
use App\Service\HubFilterLogger;
use App\Entity\MobileSession;
use App\Entity\Customer;
@ -2334,7 +2335,7 @@ class APIController extends Controller implements LoggedController
public function newRequestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo,
MapTools $map_tools, InventoryManager $im, MQTTClient $mclient,
RiderAssignmentHandlerInterface $rah, HubSelector $hub_select,
HubDistributor $hub_dist)
HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger)
{
// check required parameters and api key
$required_params = [
@ -2548,38 +2549,52 @@ class APIController extends Controller implements LoggedController
// TODO: this might need changes after the new hub selector
if (!empty($nearest_hubs))
{
// go through the hub list, find the nearest hub
// with an available rider
//error_log('found nearest hub ' . $nearest_hub->getID());
// assign rider
$available_riders = $nearest_hubs[0]['hub']->getAvailableRiders();
if (count($available_riders) > 0)
foreach ($nearest_hubs as $nearest_hub)
{
$assigned_rider = null;
if (count($available_riders) > 1)
$available_riders = $nearest_hub['hub']->getAvailableRiders();
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)
$assigned_rider = null;
if (count($available_riders) == 1)
{
$riders[] = $rider;
$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);
}
$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
$assigned_rider = $available_riders[0];
//error_log('found rider ' . $assigned_rider->getID());
$jo->setHub($nearest_hubs[0]['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_hubs[0]['hub']);
{
// log hub into hub_filter_log
$hub_filter_logger->logFilteredHub($nearest_hub['hub'], 'no_available_rider');
// continue to go through list to find hub with an available rider
}
}
}
}