Add arranging of hubs, based on job orders assigned to hub. #543
This commit is contained in:
parent
1abaad1727
commit
0115328801
3 changed files with 56 additions and 17 deletions
|
|
@ -37,6 +37,7 @@ use App\Service\MapTools;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
use App\Service\RiderAssignmentHandlerInterface;
|
use App\Service\RiderAssignmentHandlerInterface;
|
||||||
use App\Service\HubSelector;
|
use App\Service\HubSelector;
|
||||||
|
use App\Service\HubDistributor;
|
||||||
|
|
||||||
use App\Entity\MobileSession;
|
use App\Entity\MobileSession;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
|
|
@ -2520,9 +2521,9 @@ class APIController extends Controller implements LoggedController
|
||||||
// TODO: set this properly. This is test data
|
// TODO: set this properly. This is test data
|
||||||
$hub_criteria = new HubCriteria();
|
$hub_criteria = new HubCriteria();
|
||||||
$hub_criteria->setPoint($jo->getCoordinates())
|
$hub_criteria->setPoint($jo->getCoordinates())
|
||||||
->setLimitResults(1)
|
->setLimitResults(50)
|
||||||
->setLimitDistance(5)
|
->setLimitDistance(100)
|
||||||
->setInventoryCheck(true)
|
->setInventoryCheck(false)
|
||||||
->setJoType($jo->getServiceType())
|
->setJoType($jo->getServiceType())
|
||||||
->setDateTime(new DateTime());
|
->setDateTime(new DateTime());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
|
|
||||||
use App\Service\RedisClientProvider;
|
use App\Service\RedisClientProvider;
|
||||||
|
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
|
@ -13,8 +11,7 @@ class HubDistributor
|
||||||
protected $redis;
|
protected $redis;
|
||||||
protected $hub_jo_key;
|
protected $hub_jo_key;
|
||||||
|
|
||||||
public function __construct(RedisClientProvider $redis,
|
public function __construct(RedisClientProvider $redis, $hub_jo_key)
|
||||||
$hub_jo_key)
|
|
||||||
{
|
{
|
||||||
$this->redis = $redis->getRedisClient();
|
$this->redis = $redis->getRedisClient();
|
||||||
$this->hub_jo_key = $hub_jo_key;
|
$this->hub_jo_key = $hub_jo_key;
|
||||||
|
|
@ -22,32 +19,68 @@ class HubDistributor
|
||||||
|
|
||||||
public function addJoCountForHub(Hub $hub)
|
public function addJoCountForHub(Hub $hub)
|
||||||
{
|
{
|
||||||
$key = $hub->gtID();
|
$key = $hub->getID();
|
||||||
|
|
||||||
// get current count
|
// get current count
|
||||||
$result = $this->redis->hget($this->hub_jo_key, $key);
|
$jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||||
if ($result == true)
|
if ($jo_count == false)
|
||||||
{
|
|
||||||
// hub exist in hash
|
|
||||||
// add to count
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// hub not in hash
|
// hub not in hash
|
||||||
// add hub to hash
|
// add hub to hash
|
||||||
|
// set to 1 since this is first jo for hub
|
||||||
|
$this->redis->hset($this->hub_jo_key, $key, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// hub exist in hash
|
||||||
|
// add to count
|
||||||
|
$this->redis->hset($this->hub_jo_key, $key, $jo_count + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function arrangeHubs($hubs)
|
public function arrangeHubs($hubs)
|
||||||
{
|
{
|
||||||
|
if (count($hubs) == 1)
|
||||||
|
return $hubs;
|
||||||
|
|
||||||
$arranged_hubs = [];
|
$arranged_hubs = [];
|
||||||
|
|
||||||
foreach ($hubs as $hub_data)
|
foreach ($hubs as $hub_data)
|
||||||
{
|
{
|
||||||
$hub = $hub_data['hub'];
|
$hub = $hub_data['hub'];
|
||||||
|
|
||||||
// get hub in hash
|
// need the id of hub
|
||||||
|
$key = $hub->getID();
|
||||||
|
|
||||||
|
// get jo count of hub
|
||||||
|
$hub_jo_count = $this->redis->hget($this->hub_jo_key, $key);
|
||||||
|
|
||||||
|
// check if hub is in hash. if not, hub has no jobs
|
||||||
|
// but should still be added to results
|
||||||
|
$arranged_hubs[] = [
|
||||||
|
'hub' => $hub,
|
||||||
|
'db_distance' => $hub_data['db_distance'],
|
||||||
|
'distance' => $hub_data['distance'],
|
||||||
|
'duration' => $hub_data['duration'],
|
||||||
|
'jo_count' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($hub_jo_count != null)
|
||||||
|
{
|
||||||
|
$arranged_hubs['jo_count'] = $hub_jo_count;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($arranged_hubs, function($a, $b) {
|
||||||
|
if ($a['jo_count'] == $b['jo_count'])
|
||||||
|
return 0;
|
||||||
|
if ($a['jo_count'] < $b['jo_count'])
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
//error_log('arranged hubs ' . json_encode($arranged_hubs));
|
||||||
|
|
||||||
return $arranged_hubs;
|
return $arranged_hubs;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,12 +60,16 @@ class HubSelector
|
||||||
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
||||||
$filtered_hubs = $hubs_round_robin;
|
$filtered_hubs = $hubs_round_robin;
|
||||||
|
|
||||||
|
//error_log(json_encode($filtered_hubs));
|
||||||
|
|
||||||
// max results filter
|
// max results filter
|
||||||
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
||||||
$filtered_hubs = $hubs_max_result;
|
$filtered_hubs = $hubs_max_result;
|
||||||
|
|
||||||
$results = $filtered_hubs;
|
$results = $filtered_hubs;
|
||||||
|
|
||||||
|
//error_log(json_encode($results));
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,6 +97,7 @@ class HubSelector
|
||||||
$results = [];
|
$results = [];
|
||||||
for ($i = 0; $i < $limit_result; $i++)
|
for ($i = 0; $i < $limit_result; $i++)
|
||||||
{
|
{
|
||||||
|
if ($i < count($hubs))
|
||||||
$results[] = $hubs[$i];
|
$results[] = $hubs[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue