Added chart value formatting
This commit is contained in:
@@ -13,20 +13,6 @@ export class BatteryService {
|
||||
batteries = [];
|
||||
last: Date;
|
||||
|
||||
constructor() {
|
||||
this.firestore = firebaseApp.firestore();
|
||||
this.firestore.settings({timestampsInSnapshots: true});
|
||||
this.firestore.collection('Battery').doc('TEMP').onSnapshot(snap => {
|
||||
this.last = new Date();
|
||||
|
||||
let data = snap.data();
|
||||
this.batteries = Object.keys(data).map(key => ({name: key, history: data[key]}));
|
||||
this.average = this.batteries.reduce((acc, battery) => acc + battery.history[0].percentage, 0) / this.batteries.length;
|
||||
this.percentageData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: history.percentage * 100}))}));
|
||||
this.temperatureData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: Math.round(history.temp * 10) / 10}))}));
|
||||
});
|
||||
}
|
||||
|
||||
get icon() {
|
||||
if (!this.batteries.length) return 'battery_alert';
|
||||
if (!this.last) return 'battery_warn';
|
||||
@@ -54,4 +40,18 @@ export class BatteryService {
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.firestore = firebaseApp.firestore();
|
||||
this.firestore.settings({timestampsInSnapshots: true});
|
||||
this.firestore.collection('Battery').doc('TEMP').onSnapshot(snap => {
|
||||
this.last = new Date();
|
||||
|
||||
let data = snap.data();
|
||||
this.batteries = Object.keys(data).map(key => ({name: key, history: data[key]}));
|
||||
this.average = this.batteries.reduce((acc, battery) => acc + battery.history[0].percentage, 0) / this.batteries.length;
|
||||
this.percentageData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: history.percentage * 100}))}));
|
||||
this.temperatureData = this.batteries.map(battery => ({name: battery.name, series: battery.history.map((history, i) => ({name: i, value: Math.round(history.temp * 10) / 10}))}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user