Add normalize name method to process special cases for battery size. #270
This commit is contained in:
parent
6d0af26981
commit
906cf2b6af
2 changed files with 157 additions and 46 deletions
|
|
@ -122,32 +122,51 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$battery_size = trim($battery_info[3]);
|
||||
}
|
||||
|
||||
// check if battery size has ()
|
||||
// if so, trim it to ignore the parenthesis and what's after (.
|
||||
$pos = stripos($battery_size, '(');
|
||||
if ($pos == true)
|
||||
{
|
||||
$sizes = explode('(', $battery_size);
|
||||
$clean_size = trim($sizes[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$clean_size = $battery_size;
|
||||
}
|
||||
|
||||
//error_log('battery manufacturer ' . $battery_manufacturer);
|
||||
//error_log('battery model ' . $battery_model);
|
||||
//error_log('battery size ' . $battery_size);
|
||||
|
||||
// normalize the manufacturer, model and size for the hash
|
||||
// when we add to db for manufacturer, model, and size, we do not use the normalized versions
|
||||
$normalized_manu = $this->normalizeName($battery_manufacturer);
|
||||
$normalized_model = $this->normalizeName($battery_model);
|
||||
$normalized_size = $this->normalizeName($clean_size);
|
||||
|
||||
// save battery manufacturer if not yet in system
|
||||
if (!isset($this->bmanu_hash[$battery_manufacturer]))
|
||||
if (!isset($this->bmanu_hash[$normalized_manu]))
|
||||
{
|
||||
$this->addBatteryManufacturer($battery_manufacturer);
|
||||
}
|
||||
|
||||
// save battery model if not yet in system
|
||||
if (!isset($this->bmodel_hash[$battery_model]))
|
||||
if (!isset($this->bmodel_hash[$normalized_model]))
|
||||
{
|
||||
$this->addBatteryModel($battery_model);
|
||||
}
|
||||
|
||||
// save battery size if not yet in system
|
||||
if (!isset($this->bsize_hash[$battery_size]))
|
||||
if (!isset($this->bsize_hash[$normalized_size]))
|
||||
{
|
||||
$this->addBatterySize($battery_size);
|
||||
$this->addBatterySize($clean_size);
|
||||
}
|
||||
|
||||
// save battery if not yet in system
|
||||
if (!isset($this->batt_hash[$battery_manufacturer][$battery_model][$battery_size]))
|
||||
if (!isset($this->batt_hash[$normalized_manu][$normalized_model][$normalized_size]))
|
||||
{
|
||||
$this->addBattery($battery_manufacturer, $battery_model, $battery_size, $code, $clean_price);
|
||||
$this->addBattery($normalized_manu, $normalized_model, $normalized_size, $code, $clean_price);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -163,7 +182,8 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$this->em->flush();
|
||||
|
||||
// add new manufacturer to hash
|
||||
$this->bmanu_hash[$name] = $batt_manufacturer;
|
||||
$normalized_name = $this->normalizeName($name);
|
||||
$this->bmanu_hash[$normalized_name] = $batt_manufacturer;
|
||||
}
|
||||
|
||||
protected function addBatteryModel($name)
|
||||
|
|
@ -176,7 +196,8 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$this->em->flush();
|
||||
|
||||
// add new model to hash
|
||||
$this->bmodel_hash[$name] = $batt_model;
|
||||
$normalized_name = $this->normalizeName($name);
|
||||
$this->bmodel_hash[$normalized_name] = $batt_model;
|
||||
}
|
||||
|
||||
protected function addBatterySize($name)
|
||||
|
|
@ -192,7 +213,8 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$this->em->flush();
|
||||
|
||||
// add new size into hash
|
||||
$this->bsize_hash[$name] = $batt_size;
|
||||
$normalized_name = $this->normalizeName($name);
|
||||
$this->bsize_hash[$normalized_name] = $batt_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +261,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$batt_manufacturers = $this->em->getRepository(BatteryManufacturer::class)->findAll();
|
||||
foreach ($batt_manufacturers as $batt_manu)
|
||||
{
|
||||
$name = $batt_manu->getName();
|
||||
$name = $this->normalizeName($batt_manu->getName());
|
||||
$this->bmanu_hash[$name] = $batt_manu;
|
||||
}
|
||||
}
|
||||
|
|
@ -251,7 +273,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$batt_models = $this->em->getRepository(BatteryModel::class)->findAll();
|
||||
foreach ($batt_models as $batt_model)
|
||||
{
|
||||
$name = $batt_model->getName();
|
||||
$name = $this->normalizeName($batt_model->getName());
|
||||
$this->bmodel_hash[$name] = $batt_model;
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +285,7 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$batt_sizes = $this->em->getRepository(BatterySize::class)->findAll();
|
||||
foreach ($batt_sizes as $batt_size)
|
||||
{
|
||||
$name = $batt_size->getName();
|
||||
$name = $this->normalizeName($batt_size->getName());
|
||||
$this->bsize_hash[$name] = $batt_size;
|
||||
}
|
||||
}
|
||||
|
|
@ -275,12 +297,19 @@ class ImportCMBBatteryDataCommand extends Command
|
|||
$batts = $this->em->getRepository(Battery::class)->findAll();
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
$brand = $batt->getManufacturer()->getName();
|
||||
$model = $batt->getModel()->getName();
|
||||
$size = $batt->getSize()->getName();
|
||||
$brand = $this->normalizeName($batt->getManufacturer()->getName());
|
||||
$model = $this->normalizeName($batt->getModel()->getName());
|
||||
$size = $this->normalizeName($batt->getSize()->getName());
|
||||
|
||||
$this->batt_hash[$brand][$model][$size] = $batt;
|
||||
}
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
$normalized_key = trim(strtolower($name));
|
||||
|
||||
return $normalized_key;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
const F_VEHICLE_MAKE = 2;
|
||||
const F_VEHICLE_YEAR = 3;
|
||||
const F_BATT_SDFC = 4;
|
||||
// const F_BATT_ULTRAMAX = 5;
|
||||
const F_BATT_ULTRAMAX = 5;
|
||||
const F_BATT_MOTOLITE = 6;
|
||||
const F_BATT_MARATHONER = 7;
|
||||
// const F_BATT_EXCEL = 8;
|
||||
const F_BATT_EXCEL = 8;
|
||||
|
||||
const STR_CENTURY = 'Century';
|
||||
const STR_MOTOLITE = 'Motolite';
|
||||
|
|
@ -34,7 +34,11 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
const STR_SDFC = 'SDFC';
|
||||
const STR_MARATHONER = 'Marathoner';
|
||||
const STR_WETCHARGED = 'Classic WetCharged';
|
||||
const STR_ULTRAMAX = 'ULTRAMAX';
|
||||
const STR_EXCEL = 'Excel';
|
||||
const STR_PRESENT = 'Present';
|
||||
const STR_M_42 = 'M-42';
|
||||
const STR_M42 = 'M42';
|
||||
|
||||
protected $em;
|
||||
|
||||
|
|
@ -101,22 +105,24 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
|
||||
// initialize size battery array for cases where the battery size has '/'
|
||||
$sdfc_sizes = [];
|
||||
$ultramax_sizes = [];
|
||||
$motolite_sizes = [];
|
||||
$marathoner_sizes = [];
|
||||
$excel_sizes = [];
|
||||
|
||||
// battery info
|
||||
$sdfc_size = trim($fields[self::F_BATT_SDFC]);
|
||||
//$ultramax = trim($fields[self::F_BATT_ULTRAMAX]);
|
||||
$ultramax_size = trim($fields[self::F_BATT_ULTRAMAX]);
|
||||
$motolite_size = trim($fields[self::F_BATT_MOTOLITE]);
|
||||
$marathoner_size = trim($fields[self::F_BATT_MARATHONER]);
|
||||
//$excel = trim($fields[self::F_BATT_EXCEL]);
|
||||
$excel_size = trim($fields[self::F_BATT_EXCEL]);
|
||||
|
||||
// check the sizes for '/'
|
||||
$pos = stripos($sdfc_size, '/');
|
||||
if ($pos == false)
|
||||
{
|
||||
// no '/' in size
|
||||
$sdfc_sizes[] = $sdfc_size;
|
||||
$sdfc_sizes[] = $this->normalizeName($sdfc_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -124,8 +130,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$sizes = explode('/', $sdfc_size);
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$clean_size = trim($size);
|
||||
$sdfc_sizes[] = $clean_size;
|
||||
$sdfc_sizes[] = $this->normalizeName($size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +138,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
if ($pos == false)
|
||||
{
|
||||
// no '/' in size
|
||||
$motolite_sizes[] = $motolite_size;
|
||||
$motolite_sizes[] = $this->normalizeName($motolite_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -141,8 +146,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$sizes = explode('/', $motolite_size);
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$clean_size = trim($size);
|
||||
$motolite_sizes[] = $clean_size;
|
||||
$motolite_sizes[] = $this->normalizeName($size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +154,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
if ($pos == false)
|
||||
{
|
||||
// no '/' in size
|
||||
$marathoner_sizes[] = $marathoner_size;
|
||||
$marathoner_sizes[] = $this->normalizeName($marathoner_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -158,11 +162,52 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$sizes = explode('/', $marathoner_size);
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$clean_size = trim($size);
|
||||
$marathoner_sizes[] = $clean_size;
|
||||
$marathoner_sizes[] = $this->normalizeName($size);
|
||||
}
|
||||
}
|
||||
|
||||
$pos = stripos($ultramax_size, '/');
|
||||
if ($pos == false)
|
||||
{
|
||||
// no '/' in size
|
||||
$ultramax_sizes[] = $this->normalizeName($ultramax_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have '/' in size so we have to explode
|
||||
$sizes = explode('/', $ultramax_size);
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$ultramax_sizes[] = $this->normalizeName($size);
|
||||
}
|
||||
}
|
||||
|
||||
$pos = stripos($excel_size, '/');
|
||||
if ($pos == false)
|
||||
{
|
||||
// no '/' in size
|
||||
$excel_sizes[] = $this->normalizeName($excel_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have '/' in size so we have to explode
|
||||
$sizes = explode('/', $excel_size);
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$excel_sizes[] = $this->normalizeName($size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// normalize the battery manufacturers and battery models
|
||||
$norm_century = $this->normalizeName(self::STR_CENTURY);
|
||||
$norm_sdfc = $this->normalizeName(self::STR_SDFC);
|
||||
$norm_motolite = $this->normalizeName(self::STR_MOTOLITE);
|
||||
$norm_wetcharged = $this->normalizeName(self::STR_WETCHARGED);
|
||||
$norm_marathoner = $this->normalizeName(self::STR_MARATHONER);
|
||||
$norm_ultramax = $this->normalizeName(self::STR_ULTRAMAX);
|
||||
$norm_excel = $this->normalizeName(self::STR_EXCEL);
|
||||
|
||||
//foreach($sdfc_sizes as $size)
|
||||
//{
|
||||
// error_log('sdfc size ' . $size);
|
||||
|
|
@ -193,31 +238,52 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
{
|
||||
if (!(empty($size)))
|
||||
{
|
||||
if (isset($this->batt_hash[self::STR_CENTURY][self::STR_SDFC][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[self::STR_CENTURY][self::STR_SDFC][$size];
|
||||
if (isset($this->batt_hash[$norm_century][$norm_sdfc][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[$norm_century][$norm_sdfc][$size];
|
||||
else
|
||||
error_log('Not in the system: ' . $norm_century . ' ' . $norm_sdfc . ' ' . $size);
|
||||
}
|
||||
}
|
||||
//if (!(empty($ultramax)))
|
||||
// $comp_batteries[] = $this->batt_hash[$brand_ultramax][$brand_ultramax][$ultramax];
|
||||
}
|
||||
foreach($ultramax_sizes as $size)
|
||||
{
|
||||
if (!(empty($size)))
|
||||
{
|
||||
if (isset($this->batt_hash[$norm_ultramax][$norm_ultramax][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[$norm_ultramax][$norm_ultramax][$size];
|
||||
else
|
||||
error_log('Not in the system: ' . $norm_ultramax . ' ' . $norm_ultramax . ' ' . $size);
|
||||
}
|
||||
}
|
||||
foreach($motolite_sizes as $size)
|
||||
{
|
||||
if (!(empty($size)))
|
||||
{
|
||||
if (isset($this->batt_hash[self::STR_MOTOLITE][self::STR_WETCHARGED][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[self::STR_MOTOLITE][self::STR_WETCHARGED][$size];
|
||||
if (isset($this->batt_hash[$norm_motolite][$norm_wetcharged][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[$norm_motolite][$norm_wetcharged][$size];
|
||||
else
|
||||
error_log('Not in the system: ' . $norm_motolite . ' ' . $norm_wetcharged . ' ' . $size);
|
||||
}
|
||||
}
|
||||
foreach($marathoner_sizes as $size)
|
||||
{
|
||||
if (!(empty($size)))
|
||||
{
|
||||
if (isset($this->batt_hash[self::STR_CENTURY][self::STR_MARATHONER][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[self::STR_CENTURY][self::STR_MARATHONER][$size];
|
||||
if (isset($this->batt_hash[$norm_century][$norm_marathoner][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[$norm_century][$norm_marathoner][$size];
|
||||
else
|
||||
error_log('Not in the system: ' . $norm_century . ' ' . $norm_marathoner . ' ' . $size);
|
||||
}
|
||||
}
|
||||
foreach($excel_sizes as $size)
|
||||
{
|
||||
if (!(empty($size)))
|
||||
{
|
||||
if (isset($this->batt_hash[$norm_excel][$norm_excel][$size]))
|
||||
$comp_batteries[] = $this->batt_hash[$norm_excel][$norm_excel][$size];
|
||||
else
|
||||
error_log('Not in the system: ' . $norm_excel . ' ' . $norm_excel . ' ' . $size);
|
||||
}
|
||||
}
|
||||
//if (!(empty($excel)))
|
||||
// $comp_batteries[] = $this->batt_hash[$brand_excel][$brand_excel][$excel];
|
||||
|
||||
$this->addVehicleMake($manufacturer, $make, $year, $comp_batteries);
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +359,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$batt_manufacturers = $this->em->getRepository(BatteryManufacturer::class)->findAll();
|
||||
foreach ($batt_manufacturers as $batt_manu)
|
||||
{
|
||||
$name = $batt_manu->getName();
|
||||
$name = $this->normalizeName($batt_manu->getName());
|
||||
$this->bmanu_hash[$name] = $batt_manu;
|
||||
}
|
||||
}
|
||||
|
|
@ -305,7 +371,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$batt_models = $this->em->getRepository(BatteryModel::class)->findAll();
|
||||
foreach ($batt_models as $batt_model)
|
||||
{
|
||||
$name = $batt_model->getName();
|
||||
$name = $this->normalizeName($batt_model->getName());
|
||||
$this->bmodel_hash[$name] = $batt_model;
|
||||
}
|
||||
}
|
||||
|
|
@ -317,7 +383,7 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$batt_sizes = $this->em->getRepository(BatterySize::class)->findAll();
|
||||
foreach ($batt_sizes as $batt_size)
|
||||
{
|
||||
$name = $batt_size->getName();
|
||||
$name = $this->normalizeName($batt_size->getName());
|
||||
$this->bsize_hash[$name] = $batt_size;
|
||||
}
|
||||
}
|
||||
|
|
@ -329,9 +395,9 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$batts = $this->em->getRepository(Battery::class)->findAll();
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
$brand = $batt->getManufacturer()->getName();
|
||||
$model = $batt->getModel()->getName();
|
||||
$size = $batt->getSize()->getName();
|
||||
$brand = $this->normalizeName($batt->getManufacturer()->getName());
|
||||
$model = $this->normalizeName($batt->getModel()->getName());
|
||||
$size = $this->normalizeName($batt->getSize()->getName());
|
||||
|
||||
$this->batt_hash[$brand][$model][$size] = $batt;
|
||||
}
|
||||
|
|
@ -362,4 +428,20 @@ class ImportCMBVehicleCompatibilityCommand extends Command
|
|||
$this->vmake_hash[$manufacturer][$make] = $vmake;
|
||||
}
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
// check for M-42. Need to convert to M42
|
||||
if (strcasecmp($name, self::STR_M_42) == 0)
|
||||
{
|
||||
$normalized_key = strtolower(self::STR_M42);
|
||||
}
|
||||
else
|
||||
{
|
||||
$normalized_key = trim(strtolower($name));
|
||||
}
|
||||
|
||||
return $normalized_key;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue