Skip to content

Alheimsins/calculate-cheapest-charging-schedule

Repository files navigation

js-standard-style

calculate-cheapest-charging-schedule

Simple module for calculating the cheapest charging schedule for your EV

Usage

import calculateCheapestChargingSchedule from '@alheimsins/calculate-cheapest-charging-schedule'
import priceArray from './data/pricelist.mjs'
const batteryCapacity = 38
const batteryCurrentLevel = 0.75
const chargingPower = 3.5

console.log(calculateCheapestChargingSchedule({ batteryCapacity, batteryCurrentLevel, chargingPower, priceArray }))

// returns ['2022-04-24T04:00:00.000+02:00', '2022-04-24T13:00:00.000+02:00', '2022-04-24T14:00:00.000+02:00']

priceArray format

The module expects an array of objects with the following properties as priceArray:

[
  {
    "startsAt": "2020-04-24T04:00:00.000+02:00",
    "total": 0.5
  },
  {
    "startsAt": "2020-04-24T13:00:00.000+02:00",
    "total": 0.6
  }
]

if your priceArray is not in this format you can supply a propertyMap

import calculateCheapestChargingSchedule from '@alheimsins/calculate-cheapest-charging-schedule'

const batteryCapacity = 38
const batteryCurrentLevel = 0.75
const chargingPower = 3.5

const priceArray = [
  {
    "starttid": "2020-04-24T04:00:00.000+02:00",
    "pris": 0.5
  },
  {
    "starttid": "2020-04-24T13:00:00.000+02:00",
    "pris": 0.6
  }
]

const propertyMap = {
  startsAt: 'starttid',
  total: 'pris'
}

console.log(calculateCheapestChargingSchedule({ batteryCapacity, batteryCurrentLevel, chargingPower, priceArray, propertyMap }))

// returns ['2022-04-24T04:00:00.000+02:00', '2022-04-24T13:00:00.000+02:00']

Related

License

MIT

About

Created with ❤ for Alheimsins

About

Simple module for calculating the cheapest charging schedule for your EV

Resources

License

Stars

Watchers

Forks

Packages

No packages published