diff --git a/.env.dist b/.env.dist index f6d35eec..33902df3 100644 --- a/.env.dist +++ b/.env.dist @@ -57,6 +57,7 @@ COUNTRY_CODE=+insert_country_code_here # redis hash LATEST_ACTIVE_JO=latest_active_jo +HUB_JO_KEY=hub_jo_count # dashboard DASHBOARD_ENABLE=set_to_true_or_false diff --git a/config/services.yaml b/config/services.yaml index 4fb5f088..988c1f95 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -271,3 +271,10 @@ services: arguments: $em: "@doctrine.orm.entity_manager" $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)%" diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 919c2b1e..850bddd9 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2546,6 +2546,7 @@ class APIController extends Controller implements LoggedController $nearest_hubs = $hub_select->find($hub_criteria); } + // TODO: this might need changes after the new hub selector if (!empty($nearest_hubs)) { //error_log('found nearest hub ' . $nearest_hub->getID()); diff --git a/src/Service/HubDistributor.php b/src/Service/HubDistributor.php new file mode 100644 index 00000000..acfafd1a --- /dev/null +++ b/src/Service/HubDistributor.php @@ -0,0 +1,54 @@ +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; + } +} diff --git a/src/Service/HubSelector.php b/src/Service/HubSelector.php index c5403dd2..58f8f99f 100644 --- a/src/Service/HubSelector.php +++ b/src/Service/HubSelector.php @@ -8,7 +8,7 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point; use App\Entity\Hub; -use App\Service\RedisClientProvider; +use App\Service\HubDistributor; use App\Service\InventoryManager; use App\Ramcar\HubCriteria; @@ -18,14 +18,14 @@ class HubSelector { protected $em; protected $im; - protected $redis; + protected $hub_distributor; public function __construct(EntityManagerInterface $em, InventoryManager $im, - RedisClientProvider $redis) + HubDistributor $hub_distributor) { $this->em = $em; $this->im = $im; - $this->redis = $redis; + $this->hub_distributor = $hub_distributor; } public function find(HubCriteria $criteria) @@ -57,8 +57,8 @@ class HubSelector $filtered_hubs = $hubs_inventory; // round robin filter - //$hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs); - //$filtered_hubs = $hubs_round_robin; + $hubs_round_robin = $this->filterHubsByRoundRobin($filtered_hubs); + $filtered_hubs = $hubs_round_robin; // max results filter $hubs_max_result = $this->filterHubsByMaxResults($filtered_hubs, $limit_results); @@ -74,8 +74,13 @@ class HubSelector if (empty($hubs)) return $hubs; - // for now only - return $hubs; + $results = []; + // call hub distributor service + $arranged_hubs = $this->hub_distributor->arrangeHubs($hubs); + $results = $arranged_hubs; + + return $results; + } protected function filterHubsByMaxResults($hubs, $limit_result)