master
MrPlatnum 2025-09-14 19:25:25 +02:00
parent e1d21d0a19
commit 1df7612b8d
5 changed files with 31 additions and 22 deletions

View File

@ -125,6 +125,6 @@ export class DemographicsFeedbackComponent implements OnInit, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
this.metricsService.fullCleanup(); this.metricsService.resetMetrics();
} }
} }

View File

@ -23,7 +23,7 @@ import '../../../../../assets/scripts/model-viewer';
styleUrls: ['./spatial-position-assessment.component.css'], styleUrls: ['./spatial-position-assessment.component.css'],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}) })
export class SpatialPositionAssessmentComponent implements AfterViewInit { export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDestroy {
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>; @ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
@Output() testComplete = new EventEmitter<void>(); @Output() testComplete = new EventEmitter<void>();
@ -39,6 +39,9 @@ export class SpatialPositionAssessmentComponent implements AfterViewInit {
constructor(private cdr: ChangeDetectorRef) { constructor(private cdr: ChangeDetectorRef) {
this.logInteraction = this.logInteraction.bind(this); this.logInteraction = this.logInteraction.bind(this);
} }
ngOnDestroy() {
this.metricsService.stopTracking();
}
ngAfterViewInit() { ngAfterViewInit() {
const mv = this.modelViewerRef.nativeElement; const mv = this.modelViewerRef.nativeElement;

View File

@ -166,5 +166,6 @@ export class SpatialStabilityAssessmentComponent implements AfterViewInit, OnDes
if (this.countdownInterval) { if (this.countdownInterval) {
clearInterval(this.countdownInterval); clearInterval(this.countdownInterval);
} }
this.metricsService.stopTracking();
} }
} }

View File

@ -23,7 +23,7 @@ import '../../../../../assets/scripts/model-viewer';
styleUrls: ['./text-legibility-assessment.component.css'], styleUrls: ['./text-legibility-assessment.component.css'],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}) })
export class TextLegibilityAssessmentComponent implements AfterViewInit { export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestroy {
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>; @ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
@Output() testComplete = new EventEmitter<void>(); @Output() testComplete = new EventEmitter<void>();
@Output() redoTest = new EventEmitter<number>(); @Output() redoTest = new EventEmitter<number>();
@ -127,4 +127,10 @@ export class TextLegibilityAssessmentComponent implements AfterViewInit {
this.testComplete.emit(); this.testComplete.emit();
} }
ngOnDestroy() {
this.metricsService.stopTracking();
}
} }

View File

@ -103,11 +103,16 @@ export class MetricsTrackerService {
console.warn("logInteraction called with an unknown event type:", event); console.warn("logInteraction called with an unknown event type:", event);
} }
} }
public startTracking(modelViewerElement: any): void { public startTracking(modelViewerElement: any): void {
if (this.trackingSubscription || !modelViewerElement) return; this.stopTracking();
console.log("Starting periodic metrics tracking..."); if (!modelViewerElement) {
console.error("startTracking called with no modelViewerElement.");
return;
}
console.log("Starting a new periodic metrics tracking subscription.");
this.trackingSubscription = interval(500).subscribe(() => { this.trackingSubscription = interval(500).subscribe(() => {
if (!modelViewerElement.arActive) { if (!modelViewerElement.arActive) {
return; return;
@ -128,6 +133,7 @@ export class MetricsTrackerService {
}; };
this.metricsLog.arData.push(arData); this.metricsLog.arData.push(arData);
// Capture Device Orientation
if (this.lastDeviceOrientation) { if (this.lastDeviceOrientation) {
const orientation: DeviceOrientation = { const orientation: DeviceOrientation = {
timestamp: timestamp, timestamp: timestamp,
@ -140,6 +146,14 @@ export class MetricsTrackerService {
}); });
} }
public stopTracking(): void {
if (this.trackingSubscription) {
console.log("Stopping existing tracking subscription.");
this.trackingSubscription.unsubscribe();
this.trackingSubscription = null;
}
}
public sendMetricsToServer(testName: string, formData?: any) { public sendMetricsToServer(testName: string, formData?: any) {
const payload = { const payload = {
testName, testName,
@ -148,7 +162,7 @@ export class MetricsTrackerService {
...(formData && { formData }) ...(formData && { formData })
}; };
console.log("Sending final payload:", payload); console.log("Sending final payload:", payload);
this.stopTracking(); this.stopTracking();
return this.http.post(this.serverUrl, payload).pipe( return this.http.post(this.serverUrl, payload).pipe(
tap({ tap({
next: (response) => { next: (response) => {
@ -160,22 +174,7 @@ export class MetricsTrackerService {
); );
} }
public stopTracking(): void {
console.log("Stopping periodic metrics tracking.");
this.trackingSubscription?.unsubscribe();
this.trackingSubscription = null;
}
public resetMetrics(): void { public resetMetrics(): void {
this.metricsLog = { interactions: [], deviceOrientations: [], arData: [] }; this.metricsLog = { interactions: [], deviceOrientations: [], arData: [] };
} }
public fullCleanup(): void {
console.log("Performing full cleanup of MetricsTrackerService.");
this.stopTracking();
if (typeof window !== 'undefined') {
window.removeEventListener('deviceorientation', this.handleDeviceOrientation, true);
}
this.lastDeviceOrientation = null;
}
} }