Add logging for filtered hubs. #543

This commit is contained in:
Korina Cordero 2021-03-17 07:12:25 +00:00
parent 2db7c6791f
commit 4966e7e0c6
4 changed files with 61 additions and 10 deletions

View file

@ -272,9 +272,15 @@ services:
$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"
$hub_filter_logger: "@App\\Service\\HubFilterLogger"
# hub distributor # hub distributor
App\Service\HubDistributor: App\Service\HubDistributor:
arguments: arguments:
$redis: "@App\\Service\\RedisClientProvider" $redis: "@App\\Service\\RedisClientProvider"
$hub_jo_key: "%env(HUB_JO_KEY)%" $hub_jo_key: "%env(HUB_JO_KEY)%"
# hub filter logger
App\Service\HubFilterLogger:
arguments:
$em: "@doctrine.orm.entity_manager"

View file

@ -2519,14 +2519,11 @@ class APIController extends Controller implements LoggedController
// check if hub is null // check if hub is null
if ($hub == null) if ($hub == null)
{ {
// TODO: set this properly. This is test data // TODO: set this properly, since the other flags
// are on default values
$hub_criteria = new HubCriteria(); $hub_criteria = new HubCriteria();
$hub_criteria->setPoint($jo->getCoordinates()) $hub_criteria->setPoint($jo->getCoordinates())
->setLimitResults(50) ->setJoType($jo->getServiceType());
->setLimitDistance(100)
->setInventoryCheck(false)
->setJoType($jo->getServiceType())
->setDateTime(new DateTime());
// add battery to items // add battery to items
$sku = $batt->getSAPCode(); $sku = $batt->getSAPCode();

View file

@ -0,0 +1,29 @@
<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Hub;
use App\Entity\HubFilterLog;
class HubFilterLogger
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function logFilteredHub(Hub $hub, $filter_type)
{
$hub_filter_log = new HubFilterLog();
$hub_filter_log->setHub($hub)
->setFilterTypeId($filter_type);
$this->em->persist($hub_filter_log);
$this->em->flush();
}
}

View file

@ -10,6 +10,7 @@ use App\Entity\Hub;
use App\Service\HubDistributor; use App\Service\HubDistributor;
use App\Service\InventoryManager; use App\Service\InventoryManager;
use App\Service\HubFilterLogger;
use App\Ramcar\HubCriteria; use App\Ramcar\HubCriteria;
use App\Ramcar\ServiceType; use App\Ramcar\ServiceType;
@ -19,13 +20,15 @@ class HubSelector
protected $em; protected $em;
protected $im; protected $im;
protected $hub_distributor; protected $hub_distributor;
protected $hub_filter_logger;
public function __construct(EntityManagerInterface $em, InventoryManager $im, public function __construct(EntityManagerInterface $em, InventoryManager $im,
HubDistributor $hub_distributor) HubDistributor $hub_distributor, HubFilterLogger $hub_filter_logger)
{ {
$this->em = $em; $this->em = $em;
$this->im = $im; $this->im = $im;
$this->hub_distributor = $hub_distributor; $this->hub_distributor = $hub_distributor;
$this->hub_filter_logger = $hub_filter_logger;
} }
public function find(HubCriteria $criteria) public function find(HubCriteria $criteria)
@ -97,10 +100,12 @@ class HubSelector
return $hubs; return $hubs;
$results = []; $results = [];
for ($i = 0; $i < $limit_result; $i++) for ($i = 0; $i < count($hubs); $i++)
{ {
if ($i < count($hubs)) if ($i < $limit_result)
$results[] = $hubs[$i]; $results[] = $hubs[$i];
else
$this->hub_filter_logger->logFilteredHub($hubs[$i]['hub'], 'max_results');
} }
return $results; return $results;
@ -129,6 +134,8 @@ class HubSelector
'distance' => $hub_data['distance'], 'distance' => $hub_data['distance'],
'duration' => $hub_data['duration'], 'duration' => $hub_data['duration'],
]; ];
else
$this->hub_filter_logger->logFilteredHub($hub, 'job_order_type');
} }
return $results; return $results;
@ -149,6 +156,8 @@ class HubSelector
// go through each hub's opening times to check if hub is open // go through each hub's opening times to check if hub is open
// for the specified time // for the specified time
// get hub opening and closing times // get hub opening and closing times
// TODO: maybe in the future, might also have to check if hub
// is open/available on date/day
$hub = $hub_data['hub']; $hub = $hub_data['hub'];
$time_open = $hub->getTimeOpen()->format("H:i:s"); $time_open = $hub->getTimeOpen()->format("H:i:s");
@ -166,6 +175,8 @@ class HubSelector
'duration' => $hub_data['duration'], 'duration' => $hub_data['duration'],
]; ];
} }
else
$this->hub_filter_logger->logFilteredHub($hub, 'date_and_time');
} }
return $results; return $results;
@ -196,7 +207,9 @@ class HubSelector
'db_distance' => $hub_data['db_distance'], 'db_distance' => $hub_data['db_distance'],
'distance' => $hub_data['distance'], 'distance' => $hub_data['distance'],
'duration' => $hub_data['duration'], 'duration' => $hub_data['duration'],
]; ];
else
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
} }
if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY) if ($jo_type == ServiceType::BATTERY_REPLACEMENT_WARRANTY)
{ {
@ -209,6 +222,8 @@ class HubSelector
'distance' => $hub_data['distance'], 'distance' => $hub_data['distance'],
'duration' => $hub_data['duration'], 'duration' => $hub_data['duration'],
]; ];
else
$this->hub_filter_logger->logFilteredHub($hub, 'inventory');
} }
} }
} }
@ -255,6 +270,10 @@ class HubSelector
'duration' => 0, 'duration' => 0,
]; ];
} }
else
{
$this->hub_filter_logger->logFilteredHub($row[0], 'distance');
}
} }
return $hubs_data; return $hubs_data;