Modify commands for importing battery information. #460

This commit is contained in:
Korina Cordero 2020-09-02 09:55:45 +00:00
parent 9b7fa2048a
commit b8885edaaa
2 changed files with 79 additions and 63 deletions

View file

@ -70,8 +70,8 @@ class ImportCMBBatteryDataCommand extends Command
error_log('Processing battery csv file...');
while (($fields = fgetcsv($fh)) !== false)
{
// data starts at row 2
if ($row_num < 2)
// data starts at row 1
if ($row_num < 1)
{
$row_num++;
continue;
@ -82,6 +82,10 @@ class ImportCMBBatteryDataCommand extends Command
$desc = trim($fields[self::F_BATT_DESC]);
$price = trim($fields[self::F_BATT_PRICE]);
error_log($code);
error_log($desc);
error_log($price);
$clean_price = trim($price, '$');
$battery_info = explode(' ', $desc);
@ -90,22 +94,42 @@ class ImportCMBBatteryDataCommand extends Command
// [0] = battery manufacturer
// [1] = battery model
// [2] = battery size
// if only 2, get both
// [0] = battery manufacturer and battery model
// [1] = battery size
// if 4,
// [0] = battery manufacturer
// concatenate [1] and [2] for the battery model
// [1] = battery model
// [2] = extra info
// [3] = battery size
// OR
// [0] = battery manufacturer
// [1] = battery model
// [2] = battery size
// [3] = battery size --> this one would have ()
// if 5,
// [0] = battery manufacturer
// [1] = battery model
// [2] = extra info
// [3] = extra info
// [4] = battery size
$battery_manufacturer = '';
$battery_model = '';
$battery_size = '';
if (count($battery_info) == 3)
{
// sample: Century Marathoner 120-7L
// sample: Century Marathoner M42(60B20L)
$battery_manufacturer = trim($battery_info[0]);
$battery_model = trim($battery_info[1]);
$battery_size = trim($battery_info[2]);
// check for parenthesis in battery_info[2]
if (strpos($battery_info[2], '(') === false)
{
// no parenthesis found
$battery_size = trim($battery_info[2]);
}
else
{
$battery_size = trim(str_replace('(', ' (', $battery_info[2]));
}
}
if (count($battery_info) == 2)
{
@ -117,13 +141,32 @@ class ImportCMBBatteryDataCommand extends Command
if (count($battery_info) == 4)
{
// sample: Motolite Classic Wetcharged DIN100L
// sample: Century Excel NS60LS (60B24LS)
$battery_manufacturer = trim($battery_info[0]);
$battery_model = trim($battery_info[1]) . ' ' . trim($battery_info[2]);
$battery_size = trim($battery_info[3]);
$battery_model = trim($battery_info[1]);
// check for parenthesis in battery_info[3]
if (strpos($battery_info[3], '(') === false)
{
// no parenthesis found
$battery_size = trim($battery_info[3]);
}
else
{
// need to concatenate [2] and [3]
$battery_size = trim($battery_info[2]) . ' ' . trim($battery_info[3]);
}
}
if (count($battery_info) == 5)
{
// sample: Century Marathoner Max Wet NS40ZL
$battery_manufacturer = trim($battery_info[0]);
$battery_model = trim($battery_info[1]);
$battery_size = trim($battery_info[4]);
}
// check if battery size has ()
// if so, trim it to ignore the parenthesis and what's after (.
/*
$pos = stripos($battery_size, '(');
if ($pos == true)
{
@ -133,17 +176,17 @@ class ImportCMBBatteryDataCommand extends Command
else
{
$clean_size = $battery_size;
}
} */
//error_log('battery manufacturer ' . $battery_manufacturer);
//error_log('battery model ' . $battery_model);
//error_log('battery 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);
$normalized_size = $this->normalizeName($battery_size);
// save battery manufacturer if not yet in system
if (!isset($this->bmanu_hash[$normalized_manu]))
@ -160,7 +203,7 @@ class ImportCMBBatteryDataCommand extends Command
// save battery size if not yet in system
if (!isset($this->bsize_hash[$normalized_size]))
{
$this->addBatterySize(strtoupper($clean_size));
$this->addBatterySize(strtoupper($battery_size));
}
// save battery if not yet in system

View file

@ -167,24 +167,16 @@ class ImportCMBBatteryModelSizeCommand extends Command
// check if size is empty or if price and tradein prices are N/A
if (!isset($this->bsize_hash[$marathoner_size]))
{
// ignore blank sizes
if ((strlen($marathoner_size) > 0) &&
(strlen($marathoner_price) > 0))
{
{
// non-numeric entries are ignored since these are N/A == they don't sell it
if ((is_numeric($marathoner_price)) &&
(is_numeric($marathoner_tradein_price)))
{
$this->addBatterySize($marathoner_size, $marathoner_price, $marathoner_tradein_price);
}
else
{
$not_added[] = $this->addInvalidEntry('MARATHONER', $marathoner_size, $marathoner_price,
$marathoner_tradein_price, 'Non numeric price/tradein price.');
}
}
else
{
$not_added[] = $this->addInvalidEntry('MARATHONER', $marathoner_size, $marathoner_price,
$marathoner_tradein_price, 'Empty size and price.');
}
}
if (!isset($this->bsize_hash[$classic_size]))
@ -192,21 +184,12 @@ class ImportCMBBatteryModelSizeCommand extends Command
if ((strlen($classic_size) > 0) &&
(strlen($classic_price) > 0))
{
if (($classic_price != 'N/A') ||
($classic_tradein_price != 'N/A'))
// non-numeric entries are ignored since these are N/A == they don't sell it
if ((is_numeric($classic_price)) &&
(is_numeric($classic_tradein_price)))
{
$this->addBatterySize($classic_size, $classic_price, $classic_tradein_price);
}
else
{
$not_added[] = $this->addInvalidEntry('CLASSIC', $classic_size, $classic_price,
$classic_tradein_price, 'Non numeric price/tradein price.');
}
}
else
{
$not_added[] = $this->addInvalidEntry('CLASSIC', $classic_size, $classic_price,
$classic_tradein_price, 'Empty size and price.');
}
}
if (!isset($this->bsize_hash[$excel_size]))
@ -214,21 +197,12 @@ class ImportCMBBatteryModelSizeCommand extends Command
if ((strlen($excel_size) > 0) &&
(strlen($excel_price) > 0))
{
if (($excel_price != 'N/A') ||
($excel_tradein_price != 'N/A'))
// non-numeric entries are ignored since these are N/A == they don't sell it
if ((is_numeric($excel_price)) &&
(is_numeric($excel_tradein_price)))
{
$this->addBatterySize($excel_size, $excel_price, $excel_tradein_price);
}
else
{
$not_added[] = $this->addInvalidEntry('EXCEL', $excel_size, $excel_price,
$excel_tradein_price, 'Non numeric price/tradein price.');
}
}
else
{
$not_added[] = $this->addInvalidEntry('EXCEL', $excel_size, $excel_price,
$excel_tradein_price, 'Empty size and price.');
}
}
@ -237,21 +211,12 @@ class ImportCMBBatteryModelSizeCommand extends Command
if ((strlen($sdfc_size) > 0) &&
(strlen($sdfc_price) > 0))
{
if (($sdfc_price != 'N/A') ||
($sdfc_tradein_price != 'N/A'))
// non-numeric entries are ignored since these are N/A == they don't sell it
if ((is_numeric($sdfc_price)) &&
(is_numeric($sdfc_tradein_price)))
{
$this->addBatterySize($sdfc_size, $sdfc_price, $sdfc_tradein_price);
}
else
{
$not_added[] = $this->addInvalidEntry('SDFC', $sdfc_size, $sdfc_price,
$sdfc_tradein_price, 'Non numeric price/tradein price.');
}
}
else
{
$not_added[] = $this->addInvalidEntry('SDFC', $sdfc_size, $sdfc_price,
$sdfc_tradein_price, 'Empty size and price.');
}
}
@ -306,7 +271,15 @@ class ImportCMBBatteryModelSizeCommand extends Command
protected function addBatterySize($size, $price, $tradein_price)
{
$new_bsize = new BatterySize();
$new_bsize->setName(strtoupper($size));
$clean_size = strtoupper($size);
// check if size is M-42, if so, we need to change it to M42
if (strpos($clean_size, 'M-42') !== false)
{
$clean_size = strtoupper(str_replace('-', '', $size));
}
$new_bsize->setName(strtoupper($clean_size));
$new_bsize->setTIPriceMotolite($tradein_price);
$this->em->persist($new_bsize);