Add HubDistributor service. #543
This commit is contained in:
parent
0f245e9038
commit
1abaad1727
5 changed files with 76 additions and 8 deletions
|
|
@ -57,6 +57,7 @@ COUNTRY_CODE=+insert_country_code_here
|
||||||
|
|
||||||
# redis hash
|
# redis hash
|
||||||
LATEST_ACTIVE_JO=latest_active_jo
|
LATEST_ACTIVE_JO=latest_active_jo
|
||||||
|
HUB_JO_KEY=hub_jo_count
|
||||||
|
|
||||||
# dashboard
|
# dashboard
|
||||||
DASHBOARD_ENABLE=set_to_true_or_false
|
DASHBOARD_ENABLE=set_to_true_or_false
|
||||||
|
|
|
||||||
|
|
@ -271,3 +271,10 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
$im: "@App\\Service\\InventoryManager"
|
$im: "@App\\Service\\InventoryManager"
|
||||||
|
$hub_distributor: "@App\\Service\\HubDistributor"
|
||||||
|
|
||||||
|
# hub distributor
|
||||||
|
App\Service\HubDistributor:
|
||||||
|
arguments:
|
||||||
|
$redis: "@App\\Service\\RedisClientProvider"
|
||||||
|
$hub_jo_key: "%env(HUB_JO_KEY)%"
|
||||||
|
|
|
||||||
|
|
@ -2546,6 +2546,7 @@ class APIController extends Controller implements LoggedController
|
||||||
$nearest_hubs = $hub_select->find($hub_criteria);
|
$nearest_hubs = $hub_select->find($hub_criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this might need changes after the new hub selector
|
||||||
if (!empty($nearest_hubs))
|
if (!empty($nearest_hubs))
|
||||||
{
|
{
|
||||||
//error_log('found nearest hub ' . $nearest_hub->getID());
|
//error_log('found nearest hub ' . $nearest_hub->getID());
|
||||||
|
|
|
||||||
54
src/Service/HubDistributor.php
Normal file
54
src/Service/HubDistributor.php
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
use App\Service\RedisClientProvider;
|
||||||
|
|
||||||
|
use App\Entity\Hub;
|
||||||
|
|
||||||
|
class HubDistributor
|
||||||
|
{
|
||||||
|
protected $redis;
|
||||||
|
protected $hub_jo_key;
|
||||||
|
|
||||||
|
public function __construct(RedisClientProvider $redis,
|
||||||
|
$hub_jo_key)
|
||||||
|
{
|
||||||
|
$this->redis = $redis->getRedisClient();
|
||||||
|
$this->hub_jo_key = $hub_jo_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addJoCountForHub(Hub $hub)
|
||||||
|
{
|
||||||
|
$key = $hub->gtID();
|
||||||
|
|
||||||
|
// get current count
|
||||||
|
$result = $this->redis->hget($this->hub_jo_key, $key);
|
||||||
|
if ($result == true)
|
||||||
|
{
|
||||||
|
// hub exist in hash
|
||||||
|
// add to count
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// hub not in hash
|
||||||
|
// add hub to hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrangeHubs($hubs)
|
||||||
|
{
|
||||||
|
$arranged_hubs = [];
|
||||||
|
|
||||||
|
foreach ($hubs as $hub_data)
|
||||||
|
{
|
||||||
|
$hub = $hub_data['hub'];
|
||||||
|
|
||||||
|
// get hub in hash
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arranged_hubs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
||||||
|
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
|
||||||
use App\Service\RedisClientProvider;
|
use App\Service\HubDistributor;
|
||||||
use App\Service\InventoryManager;
|
use App\Service\InventoryManager;
|
||||||
|
|
||||||
use App\Ramcar\HubCriteria;
|
use App\Ramcar\HubCriteria;
|
||||||
|
|
@ -18,14 +18,14 @@ class HubSelector
|
||||||
{
|
{
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $im;
|
protected $im;
|
||||||
protected $redis;
|
protected $hub_distributor;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, InventoryManager $im,
|
public function __construct(EntityManagerInterface $em, InventoryManager $im,
|
||||||
RedisClientProvider $redis)
|
HubDistributor $hub_distributor)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->im = $im;
|
$this->im = $im;
|
||||||
$this->redis = $redis;
|
$this->hub_distributor = $hub_distributor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find(HubCriteria $criteria)
|
public function find(HubCriteria $criteria)
|
||||||
|
|
@ -57,8 +57,8 @@ class HubSelector
|
||||||
$filtered_hubs = $hubs_inventory;
|
$filtered_hubs = $hubs_inventory;
|
||||||
|
|
||||||
// round robin filter
|
// round robin filter
|
||||||
//$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs);
|
||||||
//$filtered_hubs = $hubs_round_robin;
|
$filtered_hubs = $hubs_round_robin;
|
||||||
|
|
||||||
// max results filter
|
// max results filter
|
||||||
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
$hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results);
|
||||||
|
|
@ -74,8 +74,13 @@ class HubSelector
|
||||||
if (empty($hubs))
|
if (empty($hubs))
|
||||||
return $hubs;
|
return $hubs;
|
||||||
|
|
||||||
// for now only
|
$results = [];
|
||||||
return $hubs;
|
// call hub distributor service
|
||||||
|
$arranged_hubs = $this->hub_distributor->arrangeHubs($hubs);
|
||||||
|
$results = $arranged_hubs;
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHubsByMaxResults($hubs, $limit_result)
|
protected function filterHubsByMaxResults($hubs, $limit_result)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue