master
MrPlatnum 2025-09-14 19:11:03 +02:00
parent ddd487e72a
commit e1d21d0a19
5 changed files with 24 additions and 24 deletions

View File

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

View File

@ -23,8 +23,8 @@ 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, OnDestroy { export class SpatialPositionAssessmentComponent implements AfterViewInit {
@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>();
@ -105,7 +105,4 @@ export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDest
this.redoTest.emit(1); this.redoTest.emit(1);
} }
ngOnDestroy() {
this.metricsService.cleanup();
}
} }

View File

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

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, OnDestroy { export class TextLegibilityAssessmentComponent implements AfterViewInit {
@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,8 +127,4 @@ export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestr
this.testComplete.emit(); this.testComplete.emit();
} }
ngOnDestroy() {
this.metricsService.cleanup();
}
} }

View File

@ -3,7 +3,7 @@ import { inject, Injectable } from '@angular/core';
import { interval, Subscription, tap } from 'rxjs'; import { interval, Subscription, tap } from 'rxjs';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
// --- Data Interfaces --- // --- Data Interfaces (Unchanged) ---
export interface InteractionEvent { export interface InteractionEvent {
timestamp: number; timestamp: number;
type: string; type: string;
@ -70,13 +70,16 @@ export class MetricsTrackerService {
localStorage.setItem('device-uuid', this.deviceId); localStorage.setItem('device-uuid', this.deviceId);
} }
console.log('Device ID for this session:', this.deviceId); console.log('Device ID for this session:', this.deviceId);
if (typeof window !== 'undefined') {
window.addEventListener('deviceorientation', this.handleDeviceOrientation, true);
}
} }
private handleDeviceOrientation(event: DeviceOrientationEvent): void { private handleDeviceOrientation(event: DeviceOrientationEvent): void {
this.lastDeviceOrientation = event; this.lastDeviceOrientation = event;
} }
public logInteraction(event: Event): void { public logInteraction(event: Event): void {
if (event.target) { if (event.target) {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
@ -100,14 +103,11 @@ 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; if (this.trackingSubscription || !modelViewerElement) return;
if (typeof window !== 'undefined') { console.log("Starting periodic metrics tracking...");
window.addEventListener('deviceorientation', this.handleDeviceOrientation);
}
this.trackingSubscription = interval(500).subscribe(() => { this.trackingSubscription = interval(500).subscribe(() => {
if (!modelViewerElement.arActive) { if (!modelViewerElement.arActive) {
return; return;
@ -115,6 +115,7 @@ export class MetricsTrackerService {
const timestamp = Date.now(); const timestamp = Date.now();
// Capture AR Data
const anchor = modelViewerElement.getAnchor ? modelViewerElement.getAnchor() : 'getAnchor not available'; const anchor = modelViewerElement.getAnchor ? modelViewerElement.getAnchor() : 'getAnchor not available';
const orbit = modelViewerElement.getCameraOrbit ? modelViewerElement.getCameraOrbit() : null; const orbit = modelViewerElement.getCameraOrbit ? modelViewerElement.getCameraOrbit() : null;
const target = modelViewerElement.getCameraTarget ? modelViewerElement.getCameraTarget() : null; const target = modelViewerElement.getCameraTarget ? modelViewerElement.getCameraTarget() : null;
@ -147,6 +148,7 @@ export class MetricsTrackerService {
...(formData && { formData }) ...(formData && { formData })
}; };
console.log("Sending final payload:", payload); console.log("Sending final payload:", payload);
this.stopTracking();
return this.http.post(this.serverUrl, payload).pipe( return this.http.post(this.serverUrl, payload).pipe(
tap({ tap({
next: (response) => { next: (response) => {
@ -158,16 +160,22 @@ export class MetricsTrackerService {
); );
} }
public cleanup(): void { public stopTracking(): void {
if (typeof window !== 'undefined') { console.log("Stopping periodic metrics tracking.");
window.removeEventListener('deviceorientation', this.handleDeviceOrientation);
}
this.trackingSubscription?.unsubscribe(); this.trackingSubscription?.unsubscribe();
this.trackingSubscription = null; this.trackingSubscription = null;
this.lastDeviceOrientation = 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;
}
} }