Skip to content

Commit

Permalink
Move metrics to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
stalehd committed Apr 9, 2023
1 parent be35a04 commit bfe7652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
1 change: 0 additions & 1 deletion frontend/src/app/device-view/device-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
<div class="location">
<app-device-map-view [device]="device"></app-device-map-view>
</div>

</div>
61 changes: 32 additions & 29 deletions frontend/src/app/device-view/device-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,7 @@ export class DeviceViewComponent implements OnInit, AfterViewInit, OnChanges {
this.errorMessage = e.message;
},
complete: () => {
let maxBle: number = d3.max(this.data, d => d.ble) || 0;
let maxWifi: number = d3.max(this.data, d => d.wifi) || 0;
let busyIndicator: string = "Rolig";
let i = this.data.length - 1;
let current = this.data[i].ble + this.data[i].wifi;
let percent: number = Math.round(current * 100 / (maxBle + maxWifi));

if (percent >= 80) {
busyIndicator = "Svært høy"
}
if (percent >= 60 && percent < 80) {
busyIndicator = "Høy";
}
if (percent >= 40 && percent < 60) {
busyIndicator = "Normal";
}
if (percent >= 25 && percent < 40) {
busyIndicator = "Lav";
}
if (percent < 25) {
busyIndicator = "Svært Lav";
}
this.metrics = [
{ bigText: String(maxBle), smallText: "Maks antall BLE" },
{ bigText: String(maxWifi), smallText: "Maks antall WiFi" },
{ bigText: String(this.data.length), smallText: "Målinger i perioden" },
{ bigText: busyIndicator, smallText: "Folketetthet (" + percent + "% av maks)" }
];

this.buildMetrics();
this.lastPoll = new Date();
this.showChart();
},
Expand All @@ -110,6 +82,7 @@ export class DeviceViewComponent implements OnInit, AfterViewInit, OnChanges {

showChart(): void {
if (this.chart) {
// Remove the old one if it already exists
this.renderer.removeChild(this.chartRef?.nativeElement, this.chart, false);
}
let width = this.chartRef?.nativeElement.offsetWidth;
Expand Down Expand Up @@ -191,4 +164,34 @@ export class DeviceViewComponent implements OnInit, AfterViewInit, OnChanges {
this.renderer.appendChild(this.chartRef?.nativeElement, this.chart)
}

buildMetrics(): void {
let maxBle: number = d3.max(this.data, d => d.ble) || 0;
let maxWifi: number = d3.max(this.data, d => d.wifi) || 0;
let busyIndicator: string = "Rolig";
let i = this.data.length - 1;
let current = this.data[i].ble + this.data[i].wifi;
let percent: number = Math.round(current * 100 / (maxBle + maxWifi));

if (percent >= 80) {
busyIndicator = "Svært høy"
}
if (percent >= 60 && percent < 80) {
busyIndicator = "Høy";
}
if (percent >= 40 && percent < 60) {
busyIndicator = "Normal";
}
if (percent >= 25 && percent < 40) {
busyIndicator = "Lav";
}
if (percent < 25) {
busyIndicator = "Svært Lav";
}
this.metrics = [
{ bigText: String(maxBle), smallText: "Maks antall BLE" },
{ bigText: String(maxWifi), smallText: "Maks antall WiFi" },
{ bigText: String(this.data.length), smallText: "Målinger i perioden" },
{ bigText: busyIndicator, smallText: "Folketetthet (" + percent + "% av maks)" }
];
}
}

0 comments on commit bfe7652

Please sign in to comment.