fix
parent
e1d21d0a19
commit
1df7612b8d
|
|
@ -125,6 +125,6 @@ export class DemographicsFeedbackComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.metricsService.fullCleanup();
|
||||
this.metricsService.resetMetrics();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import '../../../../../assets/scripts/model-viewer';
|
|||
styleUrls: ['./spatial-position-assessment.component.css'],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
export class SpatialPositionAssessmentComponent implements AfterViewInit {
|
||||
export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDestroy {
|
||||
|
||||
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
|
||||
@Output() testComplete = new EventEmitter<void>();
|
||||
|
|
@ -39,6 +39,9 @@ export class SpatialPositionAssessmentComponent implements AfterViewInit {
|
|||
constructor(private cdr: ChangeDetectorRef) {
|
||||
this.logInteraction = this.logInteraction.bind(this);
|
||||
}
|
||||
ngOnDestroy() {
|
||||
this.metricsService.stopTracking();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
const mv = this.modelViewerRef.nativeElement;
|
||||
|
|
|
|||
|
|
@ -166,5 +166,6 @@ export class SpatialStabilityAssessmentComponent implements AfterViewInit, OnDes
|
|||
if (this.countdownInterval) {
|
||||
clearInterval(this.countdownInterval);
|
||||
}
|
||||
this.metricsService.stopTracking();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import '../../../../../assets/scripts/model-viewer';
|
|||
styleUrls: ['./text-legibility-assessment.component.css'],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
export class TextLegibilityAssessmentComponent implements AfterViewInit {
|
||||
export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestroy {
|
||||
@ViewChild('modelViewer') modelViewerRef!: ElementRef<any>;
|
||||
@Output() testComplete = new EventEmitter<void>();
|
||||
@Output() redoTest = new EventEmitter<number>();
|
||||
|
|
@ -127,4 +127,10 @@ export class TextLegibilityAssessmentComponent implements AfterViewInit {
|
|||
this.testComplete.emit();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
||||
this.metricsService.stopTracking();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,11 +103,16 @@ export class MetricsTrackerService {
|
|||
console.warn("logInteraction called with an unknown event type:", event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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(() => {
|
||||
if (!modelViewerElement.arActive) {
|
||||
return;
|
||||
|
|
@ -128,6 +133,7 @@ export class MetricsTrackerService {
|
|||
};
|
||||
this.metricsLog.arData.push(arData);
|
||||
|
||||
// Capture Device Orientation
|
||||
if (this.lastDeviceOrientation) {
|
||||
const orientation: DeviceOrientation = {
|
||||
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) {
|
||||
const payload = {
|
||||
testName,
|
||||
|
|
@ -148,7 +162,7 @@ export class MetricsTrackerService {
|
|||
...(formData && { formData })
|
||||
};
|
||||
console.log("Sending final payload:", payload);
|
||||
this.stopTracking();
|
||||
this.stopTracking();
|
||||
return this.http.post(this.serverUrl, payload).pipe(
|
||||
tap({
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue