diff --git a/frontend/src/app/main-page/main-page.component.ts b/frontend/src/app/main-page/main-page.component.ts
index 6f85d48..36d6939 100644
--- a/frontend/src/app/main-page/main-page.component.ts
+++ b/frontend/src/app/main-page/main-page.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { V1Device } from '../api/pax';
import { SampleService } from '../sample.service';
+import { Subscription, interval } from 'rxjs';
@Component({
selector: 'app-main-page',
@@ -11,13 +12,20 @@ export class MainPageComponent implements OnInit {
activeDevices: V1Device[] = [];
activeDevice?: V1Device;
+ autoPlayEnabled: boolean = false;
+ activeStep: number = 0;
+ autoPlayer?: Subscription;
constructor(
protected samples: SampleService,
) {
+ let list: V1Device[] = [];
this.samples.activeDevices().subscribe({
next: (d: V1Device) => {
- this.activeDevices.push(d);
+ list.push(d);
+ },
+ complete: () => {
+ this.activeDevices = list;
},
})
}
@@ -28,4 +36,33 @@ export class MainPageComponent implements OnInit {
setActiveDevice(device?: V1Device): void {
this.activeDevice = device;
}
+
+ autoPlay(enable: boolean) {
+ if (!enable) {
+ this.autoPlayEnabled = false;
+ this.autoPlayer?.unsubscribe();
+ return;
+ }
+ this.activeStep = -1;
+ this.activeDevice = undefined;
+ this.autoPlayEnabled = true;
+ this.autoPlayer = interval(15000).subscribe((val) => this.autoStep());
+ }
+
+ autoStep(): void {
+ if (!this.autoPlayEnabled) {
+ return;
+ }
+ this.activeStep++;
+ if (this.activeStep >= this.activeDevices.length) {
+ this.activeStep = -1;
+ }
+ if (this.activeStep == -1) {
+ this.activeDevice = undefined;
+ return;
+ }
+ this.activeDevice = this.activeDevices[this.activeStep];
+ }
+
+
}
diff --git a/frontend/src/app/sample.service.ts b/frontend/src/app/sample.service.ts
index 1cea14c..af52b44 100644
--- a/frontend/src/app/sample.service.ts
+++ b/frontend/src/app/sample.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { PaxServiceService, V1Data, V1Device, V1ListDataResponse, V1ListDevicesResponse, V1Sample } from './api/pax';
-import { Observable, ReplaySubject, combineLatest, interval } from 'rxjs';
+import { Observable, ReplaySubject, interval } from 'rxjs';
import { HttpErrorResponse } from '@angular/common/http';
// Also a custom sample setup
@@ -19,14 +19,12 @@ export class SampleService {
public errorMessage: string = "";
- public lastPoll: Date = new Date();
+ public lastDataUpdate: Date = new Date();
+ private lastPoll: Date = new Date();
// Subject for initial data load
private dataSubject = new ReplaySubject();
- // Subjects for individual device load
- private deviceSubjects: Map> = new Map>();
-
// Subject for updates
private updateSubject = new ReplaySubject();
@@ -41,7 +39,7 @@ export class SampleService {
return this.activeDeviceSubject;
}
- //dataUpdater = interval(60000).subscribe((val) => console.debug('Called update', val));
+ dataUpdater = interval(60000).subscribe((val) => this.pollForChanges());
constructor(
protected paxService: PaxServiceService,
@@ -53,6 +51,8 @@ export class SampleService {
let chartIntervalHours = 24;
let dayAgo: string = "" + (new Date().getTime() - (chartIntervalHours * 3600 * 1000));
let now: string = "" + (new Date().getTime());
+ this.lastDataUpdate = new Date();
+ this.lastPoll = new Date();
this.paxService.paxServiceListData(dayAgo, now).subscribe({
next: (value: V1ListDataResponse) => {
if (value.data) {
@@ -88,36 +88,55 @@ export class SampleService {
this.dataSubject.complete();
},
complete: () => {
- this.lastPoll = new Date();
-
- // FIXME: Postpone the complete call when we start polling?
this.activeDeviceSubject.complete();
this.dataSubject.complete();
},
});
}
- public hasError(): boolean {
- return this.errorMessage != "";
+ private pollForChanges(): void {
+ let lastCheck: string = "" + this.lastPoll.getTime();
+ this.lastPoll = new Date();
+ this.paxService.paxServiceListData(lastCheck).subscribe({
+ next: (value: V1ListDataResponse) => {
+ if (value.data) {
+ value.data.forEach((data) => this.addDataToSamples(data));
+ }
+ },
+ error: (e: HttpErrorResponse) => {
+ this.errorMessage = e.message;
+ this.updateSubject.error(e);
+ },
+ complete: () => {
+ },
+ });
}
- public dataForDevice(id: string): DeviceSample[] {
- let ret = this.allSamples.find((v: V1Data) => v.deviceId == id);
- if (ret && ret.samples) {
- return ret.samples.map(d => {
- return {
- id: "",
- name: "",
- time: new Date(parseInt(d.timestamp!)),
- ble: d.bluetoothCount || 0,
- wifi: d.wifiCount || 0,
- };
- });
+ // Add samples to the existing data set
+ private addDataToSamples(data: V1Data): void {
+ var exists: boolean = false;
+ this.allSamples.forEach((set, index) => {
+ if (set.deviceId == data.deviceId) {
+ exists = true;
+ set.samples?.forEach((sample) => {
+ this.allSamples[index].samples?.push(sample);
+ });
+ console.debug("Added " + (set.samples?.length || 0) + " samples to data for " + set.deviceId)
+ }
+ });
+ if (!exists) {
+ console.debug("New device; adding new sample set: ", data);
+ this.allSamples.push(data);
}
- return [];
+ }
+
+ public hasError(): boolean {
+ return this.errorMessage != "";
}
public allData(): Observable {
+ // TODO: If the data is more than N minutes old return a new sample set
return this.dataSubject;
}
+
}