-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgeneral.js
More file actions
34 lines (33 loc) · 1.45 KB
/
general.js
File metadata and controls
34 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cars from '../utils/cars';
import MomentJS from 'moment';
export default {
/**
* Calculates chargetime left and finishtime while charging
* @param {String} car the cartype to get the chargetime to
* @param {String} socDisplay the state of charge from display
* @param {String} socBMS the state of charge from BMS
* @param {String} batteryPower the charging speed
* @param {String} typeOfTime the result timeType that gets returned
* @returns {*} the defined and calculated timeType
*/
chargeTime(car, socDisplay, socBMS, batteryPower, typeOfTime) {
const duration = MomentJS.duration(parseFloat(this.chargeDecimalTime(car, socDisplay, socBMS, batteryPower))).asMilliseconds();
const now = new Date().getTime();
if(typeOfTime == "timeleft") {
return MomentJS().startOf('day').add(duration, 'minutes').format('m:ss');
} else if (typeOfTime == "finishtime") {
return MomentJS(now).add(duration, 'hours').format('HH:mm');
} else {
return false;
}
},
chargeDecimalTime(car, socDisplay, socBMS, batteryPower) {
const capacity = cars[car].CAPACITY;
const soc = socDisplay || socBMS;
const amountToCharge = capacity * (1 - (soc / 100)) || 0;
const decimalTime = parseFloat(
amountToCharge / (Math.abs(batteryPower) || cars[car].FAST_SPEED)
).toFixed(2);
return decimalTime;
}
}