New dashboard widgets
- Custom time range can now be picked - Map now shows accuracy of latest beat - Presets removed
This commit is contained in:
@@ -10,6 +10,9 @@ import { APIService, IBeat } from '../api.service';
|
||||
})
|
||||
export class DashboardComponent implements AfterViewInit {
|
||||
|
||||
totalDistance = '0';
|
||||
devices = 0;
|
||||
|
||||
// Array of different segments in chart
|
||||
lineChartData: ChartDataSets[] = [
|
||||
{ data: [], label: 'Battery' }
|
||||
@@ -38,7 +41,11 @@ export class DashboardComponent implements AfterViewInit {
|
||||
}
|
||||
};
|
||||
|
||||
constructor(private api: APIService) {
|
||||
constructor(public api: APIService) {
|
||||
this.api.phoneEvent.subscribe(phones => {
|
||||
this.devices = phones.length;
|
||||
});
|
||||
|
||||
this.api.beatsEvent.subscribe(beats => {
|
||||
this.lineChartData[0].data = [];
|
||||
this.lineChartLabels = [];
|
||||
@@ -58,11 +65,22 @@ export class DashboardComponent implements AfterViewInit {
|
||||
this.lineChartData[0].data.push(beat.battery);
|
||||
this.lineChartLabels.push(this.formatDateTime(new Date(beat.createdAt)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async fetchData(): Promise<void> {
|
||||
await this.api.getBeats();
|
||||
let tDistance = 0;
|
||||
|
||||
// Calculate distance
|
||||
for (let i = 0; i < beats.length; i++) {
|
||||
if (i >= beats.length || (i + 1) >= beats.length) { break; }
|
||||
|
||||
const dist1 = beats[i].coordinate;
|
||||
const dist2 = beats[i + 1].coordinate;
|
||||
tDistance += this.api.distanceInKmBetweenEarthCoordinates(dist1[0], dist1[1], dist2[0], dist2[1]);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
this.totalDistance = tDistance.toFixed(2);
|
||||
});
|
||||
}
|
||||
|
||||
private formatDateTime(date: Date): string {
|
||||
@@ -70,7 +88,6 @@ export class DashboardComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user