Fixed wrong data index

This commit is contained in:
Zakary Timson 2018-12-26 09:59:57 -05:00
parent d31b4ae93b
commit 91321766cc

View File

@ -45,14 +45,17 @@ export class BatteryService {
this.firestore.collection('Battery').doc('170724D').onSnapshot(snap => { this.firestore.collection('Battery').doc('170724D').onSnapshot(snap => {
this.last = new Date(); this.last = new Date();
let data = snap.data(); let data = snap.data();
this.batteries = Object.keys(data.modules).map(key => ({ this.batteries = Object.keys(data.modules).map(key => {
charge: data.modules[key][0].charge, let last = data.modules[key].length - 1;
chargeHistory: data.modules[key].map((val, i) => ({name: i, value: val.charge})), return {
charging: data.modules[key][0] > data.modules[key][1], charge: data.modules[key][last].charge,
name: key, chargeHistory: data.modules[key].map((val, i) => ({name: i, value: val.charge})),
temp: data.modules[key][0].temp, charging: data.modules[key][last] > data.modules[key][last - 1],
tempHistory: data.modules[key].map((val, i) => ({name: i, value: val.temp})) name: key,
})); temp: data.modules[key][last].temp,
tempHistory: data.modules[key].map((val, i) => ({name: i, value: val.temp}))
}
});
this.total = this.batteries.reduce((acc, battery) => acc + battery.charge, 0) / 2; this.total = this.batteries.reduce((acc, battery) => acc + battery.charge, 0) / 2;
console.log(this.batteries) console.log(this.batteries)