Refactoring of local car
ADD
src/assets/cars/car-catalogs-definition.json
+[
+ {
+ "id": 100000,
+ "vehicleMake": "GOUPIL",
+ "vehicleModel": "G5 benne",
+ "vehicleModelVersion": "",
+ "availabilityStatus": null,
+ "availabilityDateFrom": null,
+ "availabilityDateTo": null,
+ "priceFromDE": 0,
+ "priceFromDEEstimate": null,
+ "priceFromNL": 0,
+ "priceFromNLEstimate": null,
+ "priceFromUK": 0,
+ "priceGrantPICGUK": 0,
+ "priceFromUKEstimate": null,
+ "drivetrainType": null,
+ "drivetrainFuel": null,
+ "drivetrainPropulsion": null,
+ "drivetrainPower": 0,
+ "drivetrainPowerHP": 21,
+ "drivetrainTorque": 37,
+ "performanceAcceleration": 0,
+ "performanceTopspeed": 50,
+ "rangeWLTP": 0,
+ "rangeWLTPEstimate": null,
+ "rangeNEDC": 0,
+ "rangeNEDCEstimate": null,
+ "rangeReal": 40,
+ "rangeRealMode": null,
+ "rangeRealWHwy": null,
+ "rangeRealWCmb": null,
+ "rangeRealWCty": null,
+ "rangeRealBHwy": null,
+ "rangeRealBCmb": null,
+ "rangeRealBCty": null,
+ "efficiencyWLTP": 0,
+ "efficiencyWLTPFuelEq": 0,
+ "efficiencyWLTPV": 0,
+ "efficiencyWLTPFuelEqV": 0,
+ "efficiencyWLTPCO2": 0,
+ "efficiencyNEDC": 0,
+ "efficiencyNEDCFuelEq": 0,
+ "efficiencyNEDCV": 0,
+ "efficiencyNEDCFuelEqV": 0,
+ "efficiencyNEDCCO2": 0,
+ "efficiencyReal": 0,
+ "efficiencyRealFuelEqV": 0,
+ "efficiencyRealCO2": 0,
+ "efficiencyRealWHwy": 0,
+ "efficiencyRealWCmb": 0,
+ "efficiencyRealWCty": 0,
+ "efficiencyRealBHwy": 0,
+ "efficiencyRealBCmb": 0,
+ "efficiencyRealBCty": 0,
+ "chargePlug": null,
+ "chargePlugEstimate": null,
+ "chargePlugLocation": null,
+ "chargeStandardPower": 13,
+ "chargeStandardPhase": 1,
+ "chargeStandardPhaseAmp": 16,
+ "chargeStandardChargeTime": 0,
+ "chargeStandardChargeSpeed": 0,
+ "chargeStandardEstimate": null,
+ "chargeStandardTables": [
+ {
+ "type": "230V16A1X",
+ "evsePhaseVolt": 72,
+ "evsePhaseAmp": 16,
+ "evsePhase": 4,
+ "evsePhaseVoltCalculated": 72,
+ "chargePhaseVolt": 230,
+ "chargePhaseAmp": 16,
+ "chargePhase": 1,
+ "chargePower": 4,
+ "chargeTime": 106,
+ "chargeSpeed": 7
+ }
+ ],
+ "chargeAlternativePower": 0,
+ "chargeAlternativePhase": 0,
+ "chargeAlternativePhaseAmp": 0,
+ "chargeAlternativeChargeTime": 0,
+ "chargeAlternativeChargeSpeed": 0,
+ "chargeAlternativeTables": [],
+ "chargeOptionPower": 0,
+ "chargeOptionPhase": 0,
+ "chargeOptionPhaseAmp": 0,
+ "chargeOptionChargeTime": 0,
+ "chargeOptionChargeSpeed": 0,
+ "chargeOptionTables": [],
+ "fastChargePlug": null,
+ "fastChargePlugEstimate": null,
+ "fastChargePlugLocation": null,
+ "fastChargePowerMax": 0,
+ "fastChargePowerAvg": 0,
+ "fastChargeTime": 0,
+ "fastChargeSpeed": 0,
+ "fastChargeOptional": null,
+ "fastChargeEstimate": null,
+ "batteryCapacityUseable": 0,
+ "batteryCapacityFull": 8.6,
+ "batteryCapacityEstimate": null,
+ "dimsLength": 0,
+ "dimsWidth": 0,
+ "dimsHeight": 0,
+ "dimsWheelbase": null,
+ "dimsWeight": 0,
+ "dimsBootspace": 0,
+ "dimsBootspaceMax": 0,
+ "dimsTowWeightUnbraked": 0,
+ "dimsTowWeightBraked": 0,
+ "dimsRoofLoadMax": 0,
+ "miscBody": null,
+ "miscSegment": null,
+ "miscSeats": 0,
+ "miscRoofrails": null,
+ "miscIsofix": null,
+ "miscIsofixSeats": null,
+ "miscTurningCircle": null,
+ "euroNCAPRating": 0,
+ "euroNCAPYear": null,
+ "euroNCAPAdult": 0,
+ "euroNCAPChild": 0,
+ "euroNCAPVRU": 0,
+ "euroNCAPSA": 0,
+ "relatedVehicleIDSuccessor": 0,
+ "eVDBDetailURL": null,
+ "videos": null,
+ "hash": null,
+ "imageURLs": [
+ "100000-goupil-g5-benne-1.jpg",
+ "100000-goupil-g5-benne-2.jpg"
+ ],
+ "lastChangedOn": "2021-12-06"
+ },
+ {
+ "id": 100001,
+ "vehicleMake": "Renault",
+ "vehicleModel": "Twizy",
+ "vehicleModelVersion": "Life",
+ "availabilityStatus": null,
+ "availabilityDateFrom": null,
+ "availabilityDateTo": null,
+ "priceFromDE": 0,
+ "priceFromDEEstimate": null,
+ "priceFromNL": 0,
+ "priceFromNLEstimate": null,
+ "priceFromUK": 0,
+ "priceGrantPICGUK": 0,
+ "priceFromUKEstimate": null,
+ "drivetrainType": null,
+ "drivetrainFuel": null,
+ "drivetrainPropulsion": null,
+ "drivetrainPower": 0,
+ "drivetrainPowerHP": 17,
+ "drivetrainTorque": 57,
+ "performanceAcceleration": 0,
+ "performanceTopspeed": 80,
+ "rangeWLTP": 0,
+ "rangeWLTPEstimate": null,
+ "rangeNEDC": 0,
+ "rangeNEDCEstimate": null,
+ "rangeReal": 80,
+ "rangeRealMode": null,
+ "rangeRealWHwy": null,
+ "rangeRealWCmb": null,
+ "rangeRealWCty": null,
+ "rangeRealBHwy": null,
+ "rangeRealBCmb": null,
+ "rangeRealBCty": null,
+ "efficiencyWLTP": 0,
+ "efficiencyWLTPFuelEq": 0,
+ "efficiencyWLTPV": 0,
+ "efficiencyWLTPFuelEqV": 0,
+ "efficiencyWLTPCO2": 0,
+ "efficiencyNEDC": 0,
+ "efficiencyNEDCFuelEq": 0,
+ "efficiencyNEDCV": 0,
+ "efficiencyNEDCFuelEqV": 0,
+ "efficiencyNEDCCO2": 0,
+ "efficiencyReal": 0,
+ "efficiencyRealFuelEqV": 0,
+ "efficiencyRealCO2": 0,
+ "efficiencyRealWHwy": 0,
+ "efficiencyRealWCmb": 0,
+ "efficiencyRealWCty": 0,
+ "efficiencyRealBHwy": 0,
+ "efficiencyRealBCmb": 0,
+ "efficiencyRealBCty": 0,
+ "chargePlug": null,
+ "chargePlugEstimate": null,
+ "chargePlugLocation": null,
+ "chargeStandardPower": 13,
+ "chargeStandardPhase": 1,
+ "chargeStandardPhaseAmp": 16,
+ "chargeStandardChargeTime": 0,
+ "chargeStandardChargeSpeed": 0,
+ "chargeStandardEstimate": null,
+ "chargeStandardTables": [
+ {
+ "type": "230V16A1X",
+ "evsePhaseVolt": 230,
+ "evsePhaseAmp": 16,
+ "evsePhase": 4,
+ "evsePhaseVoltCalculated": 230,
+ "chargePhaseVolt": 230,
+ "chargePhaseAmp": 16,
+ "chargePhase": 1,
+ "chargePower": 4,
+ "chargeTime": 106,
+ "chargeSpeed": 7
+ }
+ ],
+ "chargeAlternativePower": 0,
+ "chargeAlternativePhase": 0,
+ "chargeAlternativePhaseAmp": 0,
+ "chargeAlternativeChargeTime": 0,
+ "chargeAlternativeChargeSpeed": 0,
+ "chargeAlternativeTables": [],
+ "chargeOptionPower": 0,
+ "chargeOptionPhase": 0,
+ "chargeOptionPhaseAmp": 0,
+ "chargeOptionChargeTime": 0,
+ "chargeOptionChargeSpeed": 0,
+ "chargeOptionTables": [],
+ "fastChargePlug": null,
+ "fastChargePlugEstimate": null,
+ "fastChargePlugLocation": null,
+ "fastChargePowerMax": 0,
+ "fastChargePowerAvg": 0,
+ "fastChargeTime": 0,
+ "fastChargeSpeed": 0,
+ "fastChargeOptional": null,
+ "fastChargeEstimate": null,
+ "batteryCapacityUseable": 0,
+ "batteryCapacityFull": 6.1,
+ "batteryCapacityEstimate": null,
+ "dimsLength": 0,
+ "dimsWidth": 0,
+ "dimsHeight": 0,
+ "dimsWheelbase": null,
+ "dimsWeight": 0,
+ "dimsBootspace": 0,
+ "dimsBootspaceMax": 0,
+ "dimsTowWeightUnbraked": 0,
+ "dimsTowWeightBraked": 0,
+ "dimsRoofLoadMax": 0,
+ "miscBody": null,
+ "miscSegment": null,
+ "miscSeats": 0,
+ "miscRoofrails": null,
+ "miscIsofix": null,
+ "miscIsofixSeats": null,
+ "miscTurningCircle": null,
+ "euroNCAPRating": 0,
+ "euroNCAPYear": null,
+ "euroNCAPAdult": 0,
+ "euroNCAPChild": 0,
+ "euroNCAPVRU": 0,
+ "euroNCAPSA": 0,
+ "relatedVehicleIDSuccessor": 0,
+ "eVDBDetailURL": null,
+ "videos": null,
+ "imageURLs": [
+ "100001-renault-twizy-1.jpg",
+ "100001-renault-twizy-2.jpg",
+ "100001-renault-twizy-3.jpg",
+ "100001-renault-twizy-4.jpg",
+ "100001-renault-twizy-5.jpg"
+ ],
+ "lastChangedOn": "2021-12-06"
+ },
+ {
+ "id": 100002,
+ "vehicleMake": "TATA Motors",
+ "vehicleModel": "Nexon",
+ "vehicleModelVersion": "EV",
+ "availabilityStatus": null,
+ "availabilityDateFrom": null,
+ "availabilityDateTo": null,
+ "priceFromDE": 0,
+ "priceFromDEEstimate": null,
+ "priceFromNL": 0,
+ "priceFromNLEstimate": null,
+ "priceFromUK": 0,
+ "priceGrantPICGUK": 0,
+ "priceFromUKEstimate": null,
+ "drivetrainType": null,
+ "drivetrainFuel": null,
+ "drivetrainPropulsion": null,
+ "drivetrainPower": 0,
+ "drivetrainPowerHP": 21,
+ "drivetrainTorque": 37,
+ "performanceAcceleration": 0,
+ "performanceTopspeed": 50,
+ "rangeWLTP": 0,
+ "rangeWLTPEstimate": null,
+ "rangeNEDC": 0,
+ "rangeNEDCEstimate": null,
+ "rangeReal": 40,
+ "rangeRealMode": null,
+ "rangeRealWHwy": null,
+ "rangeRealWCmb": null,
+ "rangeRealWCty": null,
+ "rangeRealBHwy": null,
+ "rangeRealBCmb": null,
+ "rangeRealBCty": null,
+ "efficiencyWLTP": 0,
+ "efficiencyWLTPFuelEq": 0,
+ "efficiencyWLTPV": 0,
+ "efficiencyWLTPFuelEqV": 0,
+ "efficiencyWLTPCO2": 0,
+ "efficiencyNEDC": 0,
+ "efficiencyNEDCFuelEq": 0,
+ "efficiencyNEDCV": 0,
+ "efficiencyNEDCFuelEqV": 0,
+ "efficiencyNEDCCO2": 0,
+ "efficiencyReal": 0,
+ "efficiencyRealFuelEqV": 0,
+ "efficiencyRealCO2": 0,
+ "efficiencyRealWHwy": 0,
+ "efficiencyRealWCmb": 0,
+ "efficiencyRealWCty": 0,
+ "efficiencyRealBHwy": 0,
+ "efficiencyRealBCmb": 0,
+ "efficiencyRealBCty": 0,
+ "chargePlug": null,
+ "chargePlugEstimate": null,
+ "chargePlugLocation": null,
+ "chargeStandardPower": 13,
+ "chargeStandardPhase": 1,
+ "chargeStandardPhaseAmp": 16,
+ "chargeStandardChargeTime": 0,
+ "chargeStandardChargeSpeed": 0,
+ "chargeStandardEstimate": null,
+ "chargeStandardTables": [
+ {
+ "type": "230V16A1X",
+ "evsePhaseVolt": 72,
+ "evsePhaseAmp": 16,
+ "evsePhase": 4,
+ "evsePhaseVoltCalculated": 72,
+ "chargePhaseVolt": 230,
+ "chargePhaseAmp": 16,
+ "chargePhase": 1,
+ "chargePower": 4,
+ "chargeTime": 106,
+ "chargeSpeed": 7
+ }
+ ],
+ "chargeAlternativePower": 0,
+ "chargeAlternativePhase": 0,
+ "chargeAlternativePhaseAmp": 0,
+ "chargeAlternativeChargeTime": 0,
+ "chargeAlternativeChargeSpeed": 0,
+ "chargeAlternativeTables": [],
+ "chargeOptionPower": 0,
+ "chargeOptionPhase": 0,
+ "chargeOptionPhaseAmp": 0,
+ "chargeOptionChargeTime": 0,
+ "chargeOptionChargeSpeed": 0,
+ "chargeOptionTables": [],
+ "fastChargePlug": null,
+ "fastChargePlugEstimate": null,
+ "fastChargePlugLocation": null,
+ "fastChargePowerMax": 0,
+ "fastChargePowerAvg": 0,
+ "fastChargeTime": 0,
+ "fastChargeSpeed": 0,
+ "fastChargeOptional": null,
+ "fastChargeEstimate": null,
+ "batteryCapacityUseable": 0,
+ "batteryCapacityFull": 8.6,
+ "batteryCapacityEstimate": null,
+ "dimsLength": 0,
+ "dimsWidth": 0,
+ "dimsHeight": 0,
+ "dimsWheelbase": null,
+ "dimsWeight": 0,
+ "dimsBootspace": 0,
+ "dimsBootspaceMax": 0,
+ "dimsTowWeightUnbraked": 0,
+ "dimsTowWeightBraked": 0,
+ "dimsRoofLoadMax": 0,
+ "miscBody": null,
+ "miscSegment": null,
+ "miscSeats": 0,
+ "miscRoofrails": null,
+ "miscIsofix": null,
+ "miscIsofixSeats": null,
+ "miscTurningCircle": null,
+ "euroNCAPRating": 0,
+ "euroNCAPYear": null,
+ "euroNCAPAdult": 0,
+ "euroNCAPChild": 0,
+ "euroNCAPVRU": 0,
+ "euroNCAPSA": 0,
+ "relatedVehicleIDSuccessor": 0,
+ "eVDBDetailURL": null,
+ "videos": null,
+ "imageURLs": [
+ "100002-tata-nexon-1.jpg",
+ "100002-tata-nexon-2.jpg"
+ ],
+ "lastChangedOn": "2021-12-06"
+ }
+]
\ No newline at end of file

DELETE
src/assets/cars/cars-definition.json
-[
- {
- "Vehicle_ID": 100000,
- "Vehicle_Make": "GOUPIL",
- "Vehicle_Model": "G5 benne",
- "Vehicle_Model_Version": "",
- "Images": [
- "100000-goupil-g5-benne-1.jpg",
- "100000-goupil-g5-benne-2.jpg"
- ],
- "Charge_Standard_Table": {
- "230V16A1X": {
- "EVSE_PhaseVolt": 72,
- "EVSE_Phase": 4,
- "EVSE_PhaseAmp": 16,
- "Charge_PhaseVolt": 230,
- "Charge_PhaseAmp": 16,
- "Charge_Phase": 1,
- "Charge_Power": 4,
- "Charge_Time": 106,
- "Charge_Speed": 7
- }
- },
- "Drivetrain_Power_HP": 21,
- "Charge_Standard_Power": 13,
- "Range_Real": 40,
- "Battery_Capacity_Full": 8.6,
- "Charge_Standard_PhaseAmp": 16,
- "Charge_Standard_Phase": 1,
- "Performance_Topspeed": 50,
- "Drivetrain_Torque": 37
- },
- {
- "Vehicle_ID": 100001,
- "Vehicle_Make": "Renault",
- "Vehicle_Model": "Twizy",
- "Vehicle_Model_Version": "Life",
- "Images": [
- "100001-renault-twizy-1.jpg",
- "100001-renault-twizy-2.jpg",
- "100001-renault-twizy-3.jpg",
- "100001-renault-twizy-4.jpg",
- "100001-renault-twizy-5.jpg"
- ],
- "Charge_Standard_Table": {
- "230V16A1X": {
- "EVSE_PhaseVolt": 230,
- "EVSE_Phase": 4,
- "EVSE_PhaseAmp": 16,
- "Charge_PhaseVolt": 230,
- "Charge_PhaseAmp": 16,
- "Charge_Phase": 1,
- "Charge_Power": 4,
- "Charge_Time": 106,
- "Charge_Speed": 7
- }
- },
- "Drivetrain_Power_HP": 17,
- "Charge_Standard_Power": 13,
- "Range_Real": 80,
- "Battery_Capacity_Full": 6.1,
- "Charge_Standard_PhaseAmp": 16,
- "Charge_Standard_Phase": 1,
- "Performance_Topspeed": 80,
- "Drivetrain_Torque": 57
- },
- {
- "Vehicle_ID": 100002,
- "Vehicle_Make": "TATA Motors",
- "Vehicle_Model": "Nexon",
- "Vehicle_Model_Version": "EV",
- "Images": [
- "2021-tata-nexon-ev-suv.jpg",
- "tata-nexon-ev-featured-5.jpg"
- ],
- "Charge_Standard_Table": {
- "230V16A1X": {
- "EVSE_PhaseVolt": 72,
- "EVSE_Phase": 4,
- "EVSE_PhaseAmp": 16,
- "Charge_PhaseVolt": 230,
- "Charge_PhaseAmp": 16,
- "Charge_Phase": 1,
- "Charge_Power": 4,
- "Charge_Time": 106,
- "Charge_Speed": 7
- }
- },
- "Drivetrain_Power_HP": 21,
- "Charge_Standard_Power": 13,
- "Range_Real": 40,
- "Battery_Capacity_Full": 8.6,
- "Charge_Standard_PhaseAmp": 16,
- "Charge_Standard_Phase": 1,
- "Performance_Topspeed": 50,
- "Drivetrain_Torque": 37
- }
-]

MODIFY
src/assets/cars/img/100001-renault-twizy-1.jpg
src/assets/cars/img/100001-renault-twizy-1.jpg
Binary files a/src/assets/cars/img/100001-renault-twizy-1.jpg and b/src/assets/cars/img/100001-renault-twizy-1.jpg differ

MODIFY
src/assets/cars/img/100001-renault-twizy-2.jpg
src/assets/cars/img/100001-renault-twizy-2.jpg
Binary files a/src/assets/cars/img/100001-renault-twizy-2.jpg and b/src/assets/cars/img/100001-renault-twizy-2.jpg differ

MODIFY
src/assets/cars/img/100001-renault-twizy-3.jpg
src/assets/cars/img/100001-renault-twizy-3.jpg
Binary files a/src/assets/cars/img/100001-renault-twizy-3.jpg and b/src/assets/cars/img/100001-renault-twizy-3.jpg differ

MODIFY
src/assets/cars/img/100001-renault-twizy-4.jpg
src/assets/cars/img/100001-renault-twizy-4.jpg
Binary files a/src/assets/cars/img/100001-renault-twizy-4.jpg and b/src/assets/cars/img/100001-renault-twizy-4.jpg differ

MODIFY
src/assets/cars/img/100001-renault-twizy-5.jpg
src/assets/cars/img/100001-renault-twizy-5.jpg
Binary files a/src/assets/cars/img/100001-renault-twizy-5.jpg and b/src/assets/cars/img/100001-renault-twizy-5.jpg differ

ADD
src/assets/cars/img/100002-tata-nexon-1.jpg
src/assets/cars/img/100002-tata-nexon-1.jpg
Binary files /dev/null and b/src/assets/cars/img/100002-tata-nexon-1.jpg differ

ADD
src/assets/cars/img/100002-tata-nexon-2.jpg
src/assets/cars/img/100002-tata-nexon-2.jpg
Binary files /dev/null and b/src/assets/cars/img/100002-tata-nexon-2.jpg differ

DELETE
src/assets/cars/img/2021-tata-nexon-ev-suv.jpg
src/assets/cars/img/2021-tata-nexon-ev-suv.jpg
Binary files a/src/assets/cars/img/2021-tata-nexon-ev-suv.jpg and /dev/null differ

DELETE
src/assets/cars/img/tata-nexon-ev-featured-5.jpg
src/assets/cars/img/tata-nexon-ev-featured-5.jpg
Binary files a/src/assets/cars/img/tata-nexon-ev-featured-5.jpg and /dev/null differ

MODIFY
src/bootstrap/LocalCarCatalogBootstrap.ts
src/bootstrap/LocalCarCatalogBootstrap.ts
-import { CarCatalog, CarCatalogChargeAlternativeTable, CarCatalogChargeOptionTable, CarCatalogConverter } from '../types/Car';
-
+import { CarCatalog } from '../types/Car';
import CarStorage from '../storage/mongodb/CarStorage';
import Constants from '../utils/Constants';
import Jimp from 'jimp';
import Logging from '../utils/Logging';
import { ServerAction } from '../types/Server';
import Utils from '../utils/Utils';
-import { Voltage } from '../types/ChargingStation';
import fs from 'fs';
import global from '../types/GlobalType';
@@ -16,190 +14,34 @@ export default class LocalCarCatalogBootstrap {
public static async uploadLocalCarCatalogsFromFile() : Promise<void> {
let created = 0;
try {
- const cars = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/cars/cars-definition.json`, 'utf8'));
- if (!Utils.isEmptyArray(cars)) {
- for (const car of cars) {
+ const carCatalogs = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/cars/car-catalogs-definition.json`, 'utf8')) as CarCatalog[];
+ if (!Utils.isEmptyArray(carCatalogs)) {
+ for (const carCatalog of carCatalogs) {
try {
- const chargeStandardTables: CarCatalogConverter[] = [];
- const chargeAlternativeTables: CarCatalogChargeAlternativeTable[] = [];
- const chargeOptionTables: CarCatalogChargeOptionTable[] = [];
- for (const chargeStandard of Object.keys(car.Charge_Standard_Table)) {
- const chargeStandardTable: CarCatalogConverter = {
- type: chargeStandard,
- evsePhaseVolt: car.Charge_Standard_Table[chargeStandard].EVSE_PhaseVolt,
- evsePhaseAmp: car.Charge_Standard_Table[chargeStandard].EVSE_PhaseAmp,
- evsePhase: car.Charge_Standard_Table[chargeStandard].EVSE_Phase,
- evsePhaseVoltCalculated: car.Charge_Standard_Table[chargeStandard].EVSE_Phase === 3 ?
- Voltage.VOLTAGE_400 : car.Charge_Standard_Table[chargeStandard].EVSE_PhaseVolt,
- chargePhaseVolt: car.Charge_Standard_Table[chargeStandard].Charge_PhaseVolt,
- chargePhaseAmp: car.Charge_Standard_Table[chargeStandard].Charge_PhaseAmp,
- chargePhase: car.Charge_Standard_Table[chargeStandard].Charge_Phase,
- chargePower: car.Charge_Standard_Table[chargeStandard].Charge_Power,
- chargeTime: car.Charge_Standard_Table[chargeStandard].Charge_Time,
- chargeSpeed: car.Charge_Standard_Table[chargeStandard].Charge_Speed,
- };
- chargeStandardTables.push(chargeStandardTable);
- }
- if (car.Charge_Alternative_Table) {
- for (const chargeAlternative of Object.keys(car.Charge_Alternative_Table)) {
- const chargeAlternativeTable: CarCatalogChargeAlternativeTable = {
- type: chargeAlternative,
- evsePhaseVolt: car.Charge_Standard_Table[chargeAlternative].EVSE_PhaseVolt,
- evsePhaseAmp: car.Charge_Standard_Table[chargeAlternative].EVSE_PhaseAmp,
- evsePhase: car.Charge_Standard_Table[chargeAlternative].EVSE_Phase,
- chargePhaseVolt: car.Charge_Standard_Table[chargeAlternative].Charge_PhaseVolt,
- chargePhaseAmp: car.Charge_Standard_Table[chargeAlternative].Charge_PhaseAmp,
- chargePhase: car.Charge_Standard_Table[chargeAlternative].Charge_Phase,
- chargePower: car.Charge_Standard_Table[chargeAlternative].Charge_Power,
- chargeTime: car.Charge_Standard_Table[chargeAlternative].Charge_Time,
- chargeSpeed: car.Charge_Standard_Table[chargeAlternative].Charge_Speed,
- };
- chargeAlternativeTables.push(chargeAlternativeTable);
- }
- }
- if (car.Charge_Option_Table) {
- for (const chargeOption of Object.keys(car.Charge_Option_Table)) {
- const chargeAlternativeTable: CarCatalogChargeOptionTable = {
- type: chargeOption,
- evsePhaseVolt: car.Charge_Standard_Table[chargeOption].EVSE_PhaseVolt,
- evsePhaseAmp: car.Charge_Standard_Table[chargeOption].EVSE_PhaseAmp,
- evsePhase: car.Charge_Standard_Table[chargeOption].EVSE_Phase,
- chargePhaseVolt: car.Charge_Standard_Table[chargeOption].Charge_PhaseVolt,
- chargePhaseAmp: car.Charge_Standard_Table[chargeOption].Charge_PhaseAmp,
- chargePhase: car.Charge_Standard_Table[chargeOption].Charge_Phase,
- chargePower: car.Charge_Standard_Table[chargeOption].Charge_Power,
- chargeTime: car.Charge_Standard_Table[chargeOption].Charge_Time,
- chargeSpeed: car.Charge_Standard_Table[chargeOption].Charge_Speed,
- };
- chargeOptionTables.push(chargeAlternativeTable);
- }
+ // Build the hash code
+ carCatalog.hash = Utils.hash(JSON.stringify(carCatalog));
+ // Check if the existing car has changed
+ const existingCarCatalog = await CarStorage.getCarCatalog(carCatalog.id);
+ // Ignore
+ if (existingCarCatalog?.hash === carCatalog.hash) {
+ continue;
}
- const carCatalog: CarCatalog = {
- id: car.Vehicle_ID,
- vehicleMake: car.Vehicle_Make,
- vehicleModel: car.Vehicle_Model,
- vehicleModelVersion: car.Vehicle_Model_Version,
- availabilityStatus: car.Availability_Status,
- availabilityDateFrom: car.Availability_Date_From,
- availabilityDateTo: car.Availability_Date_To,
- priceFromDE: car.Price_From_DE,
- priceFromDEEstimate: car.Price_From_DE_Estimate,
- priceFromNL: car.Price_From_NL,
- priceFromNLEstimate: car.Price_From_NL_Estimate,
- priceFromUK: car.Price_From_UK,
- priceGrantPICGUK: car.Price_Grant_PICG_UK,
- priceFromUKEstimate: car.Price_From_UK_Estimate,
- drivetrainType: car.Drivetrain_Type,
- drivetrainFuel: car.Drivetrain_Fuel,
- drivetrainPropulsion: car.Drivetrain_Propulsion,
- drivetrainPower: car.Drivetrain_Power,
- drivetrainPowerHP: car.Drivetrain_Power_HP,
- drivetrainTorque: car.Drivetrain_Torque,
- performanceAcceleration: car.Performance_Acceleration,
- performanceTopspeed: car.Performance_Topspeed,
- rangeWLTP: car.Range_WLTP,
- rangeWLTPEstimate: car.Range_WLTP_Estimate,
- rangeNEDC: car.Range_NEDC,
- rangeNEDCEstimate: car.Range_NEDC_Estimate,
- rangeReal: car.Range_Real,
- rangeRealMode: car.Range_Real_Mode,
- rangeRealWHwy: car.Range_Real_WHwy,
- rangeRealWCmb: car.Range_Real_WCmb,
- rangeRealWCty: car.Range_Real_WCty,
- rangeRealBHwy: car.Range_Real_BHwy,
- rangeRealBCmb: car.Range_Real_BCmb,
- rangeRealBCty: car.Range_Real_BCty,
- efficiencyWLTP: car.Efficiency_WLTP,
- efficiencyWLTPFuelEq: car.Efficiency_WLTP_FuelEq,
- efficiencyWLTPV: car.Efficiency_WLTP_V,
- efficiencyWLTPFuelEqV: car.Efficiency_WLTP_FuelEq_V,
- efficiencyWLTPCO2: car.Efficiency_WLTP_CO2,
- efficiencyNEDC: car.Efficiency_NEDC,
- efficiencyNEDCFuelEq: car.Efficiency_NEDC_FuelEq,
- efficiencyNEDCV: car.Efficiency_NEDC_V,
- efficiencyNEDCFuelEqV: car.Efficiency_NEDC_FuelEq_V,
- efficiencyNEDCCO2: car.Efficiency_NEDC_CO2,
- efficiencyReal: car.Efficiency_Real,
- efficiencyRealFuelEqV: car.Efficiency_Real_FuelEq_V,
- efficiencyRealCO2: car.Efficiency_Real_CO2,
- efficiencyRealWHwy: car.Efficiency_Real_WHwy,
- efficiencyRealWCmb: car.Efficiency_Real_WCmb,
- efficiencyRealWCty: car.Efficiency_Real_WCty,
- efficiencyRealBHwy: car.Efficiency_Real_BHwy,
- efficiencyRealBCmb: car.Efficiency_Real_BCmb,
- efficiencyRealBCty: car.Efficiency_Real_BCty,
- chargePlug: car.Charge_Plug,
- chargePlugEstimate: car.Charge_Plug_Estimate,
- chargePlugLocation: car.Charge_Plug_Location,
- chargeStandardPower: car.Charge_Standard_Power,
- chargeStandardPhase: car.Charge_Standard_Phase,
- chargeStandardPhaseAmp: car.Charge_Standard_PhaseAmp,
- chargeStandardChargeTime: car.Charge_Standard_ChargeTime,
- chargeStandardChargeSpeed: car.Charge_Standard_ChargeSpeed,
- chargeStandardEstimate: car.Charge_Standard_Estimate,
- chargeStandardTables: chargeStandardTables,
- chargeAlternativePower: car.Charge_Alternative_Power,
- chargeAlternativePhase: car.Charge_Alternative_Phase,
- chargeAlternativePhaseAmp: car.Charge_Alternative_PhaseAmp,
- chargeAlternativeChargeTime: car.Charge_Alternative_ChargeTime,
- chargeAlternativeChargeSpeed: car.Charge_Alternative_ChargeSpeed,
- chargeAlternativeTables: chargeAlternativeTables,
- chargeOptionPower: car.Charge_Option_Power,
- chargeOptionPhase: car.Charge_Option_Phase,
- chargeOptionPhaseAmp: car.Charge_Option_PhaseAmp,
- chargeOptionChargeTime: car.Charge_Option_ChargeTime,
- chargeOptionChargeSpeed: car.Charge_Option_ChargeSpeed,
- chargeOptionTables: chargeOptionTables,
- fastChargePlug: car.Fastcharge_Plug,
- fastChargePlugEstimate: car.Fastcharge_Plug_Estimate,
- fastChargePlugLocation: car.Fastcharge_Plug_Location,
- fastChargePowerMax: car.Fastcharge_Power_Max,
- fastChargePowerAvg: car.Fastcharge_Power_Avg,
- fastChargeTime: car.Fastcharge_ChargeTime,
- fastChargeSpeed: car.Fastcharge_ChargeSpeed,
- fastChargeOptional: car.Fastcharge_Optional,
- fastChargeEstimate: car.Fastcharge_Estimate,
- batteryCapacityUseable: car.Battery_Capacity_Useable,
- batteryCapacityFull: car.Battery_Capacity_Full,
- batteryCapacityEstimate: car.Battery_Capacity_Estimate,
- dimsLength: car.Dims_Length,
- dimsWidth: car.Dims_Width,
- dimsHeight: car.Dims_Height,
- dimsWheelbase: car.Dims_Wheelbase,
- dimsWeight: car.Dims_Weight,
- dimsBootspace: car.Dims_Bootspace,
- dimsBootspaceMax: car.Dims_Bootspace_Max,
- dimsTowWeightUnbraked: car.Dims_TowWeight_Braked,
- dimsRoofLoadMax: car.Dims_RoofLoad_Max,
- miscBody: car.Misc_Body,
- miscSegment: car.Misc_Segment,
- miscSeats: car.Misc_Seats,
- miscRoofrails: car.Misc_Roofrails,
- miscIsofix: car.Misc_Isofix,
- miscIsofixSeats: car.Misc_Isofix_Seats,
- miscTurningCircle: car.Misc_TurningCircle,
- euroNCAPRating: car.EuroNCAP_Rating,
- euroNCAPYear: car.EuroNCAP_Year,
- euroNCAPAdult: car.EuroNCAP_Adult,
- euroNCAPChild: car.EuroNCAP_Child,
- euroNCAPVRU: car.EuroNCAP_VRU,
- euroNCAPSA: car.EuroNCAP_SA,
- relatedVehicleIDSuccessor: car.Related_Vehicle_ID_Successor,
- eVDBDetailURL: car.EVDB_Detail_URL,
- imageURLs: car.Images ? (!Utils.isEmptyArray(car.Images) ? car.Images : [car.Images]) : [],
- images: [],
- videos: car.Videos,
- };
- let imageURLPath = `${global.appRoot}/assets/cars/img/${carCatalog.imageURLs[0]}`;
- const thumbImage = (await Jimp.read(imageURLPath)).resize(200, 150);
- const thumbImageMIME = thumbImage.getMIME();
- const base64ThumbImage = await thumbImage.getBase64Async(thumbImageMIME);
- carCatalog.image = base64ThumbImage;
// Delete Car Catalog
await CarStorage.deleteCarCatalog(carCatalog.id);
await CarStorage.deleteCarCatalogImages(carCatalog.id);
+ // Save Car Catalog
carCatalog.createdOn = new Date();
carCatalog.lastChangedOn = carCatalog.createdOn;
+ await CarStorage.saveCarCatalog(carCatalog);
+ // Create images
+ if (!Utils.isEmptyArray(carCatalog.imageURLs)) {
+ // Create thumb image
+ let imageURLPath = `${global.appRoot}/assets/cars/img/${carCatalog.imageURLs[0]}`;
+ const thumbImage = (await Jimp.read(imageURLPath)).resize(200, 150);
+ const thumbImageMIME = thumbImage.getMIME();
+ const base64ThumbImage = await thumbImage.getBase64Async(thumbImageMIME);
+ carCatalog.image = base64ThumbImage;
+ // Create image
for (const imageURL of carCatalog.imageURLs) {
imageURLPath = `${global.appRoot}/assets/cars/img/${imageURL}`;
const image = await Jimp.read(imageURLPath);
@@ -208,11 +50,10 @@ export default class LocalCarCatalogBootstrap {
// Save car catalog images
await CarStorage.saveCarCatalogImage(carCatalog.id, base64Image);
}
- // Save
- await CarStorage.saveCarCatalog(carCatalog);
+ }
created++;
} catch (error) {
- const message = `Error while importing the local Car ID '${car.Vehicle_ID as string}': ${error.message as string}`;
+ const message = `Error while importing the local Car ID '${carCatalog.id}': ${error.message as string}`;
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS,

Refactoring of local car