/**
* Any utility functions related to running of a vehicle
* @module
*/
import { isPHEV } from '../classification';
/**
* get user or official mpg based on struct
* @param {struct} skv_config mpg_user, mpg
* @returns {number}
*/
const getMPG = (skv_config) => {
const skv_default = {
mpg: 0,
mpg_user: 0,
};
const skv_local_config = Object.assign(skv_default, skv_config);
if (skv_local_config.mpg_user) {
return skv_local_config.mpg_user;
}
return skv_local_config.mpg;
};
/**
* get user or official battery range miles based on struct
* @param {struct} skv_config battery_range_miles_user, battery_range_miles
* @returns {number} Description
*/
const getBatteryRangeMiles = (skv_config) => {
const skv_default = {
battery_range_miles: 0,
battery_range_miles_user: 0,
};
const skv_local_config = Object.assign(skv_default, skv_config);
if (skv_local_config.battery_range_miles_user) {
return skv_config.battery_range_miles_user;
}
return skv_config.battery_range_miles;
};
/**
* if a journey range is not provided then 16 miles is added to the battery range
* to calculate the journey range as an approximation of how far the vehicle will
* travel on ICE before recharging the battery
* @param {struct} skv_config mpg, battery range, optional journey miles
* @returns {boolean}
*/
const getIsCSMode = (skv_config) => {
if (
isPHEV(skv_config.mpg, skv_config.battery_range_miles)
&& (
!Object.prototype.hasOwnProperty.call(skv_config, 'journey_miles')
|| skv_config.journey_miles === ''
)
) {
return true;
}
return false;
};
export {
getMPG,
getBatteryRangeMiles,
getIsCSMode,
};