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() {
this.metricsService.cleanup();
this.metricsService.fullCleanup();
}
}

View File

@ -23,8 +23,8 @@ import '../../../../../assets/scripts/model-viewer';
styleUrls: ['./spatial-position-assessment.component.css'],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDestroy {
export class SpatialPositionAssessmentComponent implements AfterViewInit {
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
@Output() testComplete = new EventEmitter<void>();
@Output() redoTest = new EventEmitter<number>();
@ -105,7 +105,4 @@ export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDest
this.redoTest.emit(1);
}
ngOnDestroy() {
this.metricsService.cleanup();
}
}

View File

@ -166,6 +166,5 @@ export class SpatialStabilityAssessmentComponent implements AfterViewInit, OnDes
if (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'],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestroy {
export class TextLegibilityAssessmentComponent implements AfterViewInit {
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
@Output() testComplete = new EventEmitter<void>();
@Output() redoTest = new EventEmitter<number>();
@ -127,8 +127,4 @@ export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestr
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 { v4 as uuidv4 } from 'uuid';
// --- Data Interfaces ---
// --- Data Interfaces (Unchanged) ---
export interface InteractionEvent {
timestamp: number;
type: string;
@ -70,13 +70,16 @@ export class MetricsTrackerService {
localStorage.setItem('device-uuid', 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 {
this.lastDeviceOrientation = event;
}
public logInteraction(event: Event): void {
if (event.target) {
const target = event.target as HTMLElement;
@ -100,14 +103,11 @@ export class MetricsTrackerService {
console.warn("logInteraction called with an unknown event type:", event);
}
}
public startTracking(modelViewerElement: any): void {
if (this.trackingSubscription || !modelViewerElement) return;
if (typeof window !== 'undefined') {
window.addEventListener('deviceorientation', this.handleDeviceOrientation);
}
console.log("Starting periodic metrics tracking...");
this.trackingSubscription = interval(500).subscribe(() => {
if (!modelViewerElement.arActive) {
return;
@ -115,6 +115,7 @@ export class MetricsTrackerService {
const timestamp = Date.now();
// Capture AR Data
const anchor = modelViewerElement.getAnchor ? modelViewerElement.getAnchor() : 'getAnchor not available';
const orbit = modelViewerElement.getCameraOrbit ? modelViewerElement.getCameraOrbit() : null;
const target = modelViewerElement.getCameraTarget ? modelViewerElement.getCameraTarget() : null;
@ -147,6 +148,7 @@ export class MetricsTrackerService {
...(formData && { formData })
};
console.log("Sending final payload:", payload);
this.stopTracking();
return this.http.post(this.serverUrl, payload).pipe(
tap({
next: (response) => {
@ -158,16 +160,22 @@ export class MetricsTrackerService {
);
}
public cleanup(): void {
if (typeof window !== 'undefined') {
window.removeEventListener('deviceorientation', this.handleDeviceOrientation);
}
public stopTracking(): void {
console.log("Stopping periodic metrics tracking.");
this.trackingSubscription?.unsubscribe();
this.trackingSubscription = null;
this.lastDeviceOrientation = null;
}
public resetMetrics(): void {
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;
}
}