Add customer distance limit to .env and checking if hub within the limit. #377
This commit is contained in:
parent
7bf9a7435c
commit
b545750910
5 changed files with 24 additions and 8 deletions
|
|
@ -66,3 +66,6 @@ INVENTORY_API_AUTH_TOKEN=insert_auth_token_here
|
||||||
|
|
||||||
# API logging
|
# API logging
|
||||||
API_LOGGING=set_to_true_or_false
|
API_LOGGING=set_to_true_or_false
|
||||||
|
|
||||||
|
# customer distance limit in km
|
||||||
|
CUST_DISTANCE_LIMIT=set_to_number
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
||||||
|
$cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%"
|
||||||
|
|
||||||
App\Service\RisingTideGateway:
|
App\Service\RisingTideGateway:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
||||||
|
$cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%"
|
||||||
|
|
||||||
App\Service\RisingTideGateway:
|
App\Service\RisingTideGateway:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$em: "@doctrine.orm.entity_manager"
|
$em: "@doctrine.orm.entity_manager"
|
||||||
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
$gmaps_api_key: "%env(GMAPS_API_KEY)%"
|
||||||
|
$cust_dist_limit: "%env(CUST_DISTANCE_LIMIT)%"
|
||||||
|
|
||||||
App\Service\RisingTideGateway:
|
App\Service\RisingTideGateway:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,15 @@ class MapTools
|
||||||
// google maps api key
|
// google maps api key
|
||||||
protected $gmaps_api_key;
|
protected $gmaps_api_key;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em, $gmaps_api_key)
|
// customer distance limit
|
||||||
|
protected $cust_dist_limit;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em, $gmaps_api_key,
|
||||||
|
$cust_dist_limit)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->gmaps_api_key = $gmaps_api_key;
|
$this->gmaps_api_key = $gmaps_api_key;
|
||||||
|
$this->cust_dist_limit = $cust_dist_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mapGetDistances(Point $point, $hubs)
|
protected function mapGetDistances(Point $point, $hubs)
|
||||||
|
|
@ -148,7 +153,8 @@ class MapTools
|
||||||
return $final_data;
|
return $final_data;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: only the API calls this
|
||||||
public function getClosestOpenHubs(Point $point, $limit, $time = false)
|
public function getClosestOpenHubs(Point $point, $limit, $time = false)
|
||||||
{
|
{
|
||||||
// get closest hubs based on st_distance function from db
|
// get closest hubs based on st_distance function from db
|
||||||
|
|
@ -184,14 +190,18 @@ class MapTools
|
||||||
// get distance in kilometers from customer point to hub point
|
// get distance in kilometers from customer point to hub point
|
||||||
$dist = $this->distance($cust_lat, $cust_lng, $hub_lat, $hub_lng);
|
$dist = $this->distance($cust_lat, $cust_lng, $hub_lat, $hub_lng);
|
||||||
|
|
||||||
$final_data[] = [
|
if ($dist < $this->cust_dist_limit)
|
||||||
'hub' => $row[0],
|
{
|
||||||
'db_distance' => $row['dist'],
|
$final_data[] = [
|
||||||
'distance' => $dist,
|
'hub' => $row[0],
|
||||||
'duration' => 0,
|
'db_distance' => $row['dist'],
|
||||||
];
|
'distance' => $dist,
|
||||||
|
'duration' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log('nearest open hubs count: ' . count($final_data));
|
||||||
return $final_data;
|
return $final_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue