improve tracking logic
parent
9446e3b2de
commit
95d92cc4d9
|
|
@ -59,8 +59,6 @@ export class DemographicsFeedbackComponent implements OnInit, OnDestroy {
|
|||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
// Start device orientation tracking for this component
|
||||
this.metricsService.startDeviceOrientationTracking();
|
||||
}
|
||||
|
||||
logInteraction(event: Event) {
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ export class SpatialPositionAssessmentComponent implements AfterViewInit, OnDest
|
|||
|
||||
ngAfterViewInit() {
|
||||
const mv = this.modelViewerRef.nativeElement;
|
||||
this.metricsService.startDeviceOrientationTracking();
|
||||
this.metricsService.startArTracking(mv);
|
||||
this.metricsService.startTracking(mv);
|
||||
mv.addEventListener('ar-status', (e: any) => {
|
||||
if (e.detail.status === 'session-started') {
|
||||
setTimeout(() => this.captureAnchor(), 500);
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ export class SpatialStabilityAssessmentComponent implements AfterViewInit, OnDes
|
|||
ngAfterViewInit() {
|
||||
const modelViewer = this.modelViewerRef.nativeElement;
|
||||
|
||||
this.metricsService.startDeviceOrientationTracking();
|
||||
this.metricsService.startArTracking(modelViewer);
|
||||
this.metricsService.startTracking(modelViewer);
|
||||
|
||||
modelViewer.addEventListener('ar-status', (event: any) => {
|
||||
if (event.detail.status === 'session-started' && !this.isModelPlaced) {
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ export class TextLegibilityAssessmentComponent implements AfterViewInit, OnDestr
|
|||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.metricsService.startDeviceOrientationTracking();
|
||||
this.metricsService.startArTracking(this.modelViewerRef.nativeElement);
|
||||
const mv = this.modelViewerRef.nativeElement;
|
||||
this.metricsService.startTracking(mv);
|
||||
}
|
||||
|
||||
public logInteraction(event: Event) {
|
||||
|
|
|
|||
|
|
@ -52,18 +52,12 @@ export class MetricsTrackerService {
|
|||
arData: []
|
||||
};
|
||||
|
||||
private deviceOrientationSubscription: Subscription | null = null;
|
||||
private arTrackingSubscription: Subscription | null = null;
|
||||
private trackingSubscription: Subscription | null = null;
|
||||
private lastDeviceOrientation: DeviceOrientationEvent | null = null;
|
||||
|
||||
constructor() {
|
||||
this.handleDeviceOrientation = this.handleDeviceOrientation.bind(this);
|
||||
}
|
||||
|
||||
private handleDeviceOrientation(event: DeviceOrientationEvent): void {
|
||||
this.lastDeviceOrientation = event;
|
||||
}
|
||||
|
||||
// --- Public API ---
|
||||
public logInteraction(event: Event): void {
|
||||
if (event.target) {
|
||||
|
|
@ -92,15 +86,36 @@ export class MetricsTrackerService {
|
|||
}
|
||||
|
||||
|
||||
public startDeviceOrientationTracking(): void {
|
||||
if (this.deviceOrientationSubscription || typeof window === 'undefined') return;
|
||||
public startTracking(modelViewerElement: any): void {
|
||||
if (this.trackingSubscription || !modelViewerElement) return;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('deviceorientation', this.handleDeviceOrientation);
|
||||
}
|
||||
|
||||
this.deviceOrientationSubscription = interval(500).subscribe(() => {
|
||||
this.trackingSubscription = interval(500).subscribe(() => {
|
||||
if (!modelViewerElement.arActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
const timestamp = Date.now();
|
||||
|
||||
const anchor = modelViewerElement.getAnchor ? modelViewerElement.getAnchor() : 'getAnchor not available';
|
||||
const orbit = modelViewerElement.getCameraOrbit ? modelViewerElement.getCameraOrbit() : null;
|
||||
const target = modelViewerElement.getCameraTarget ? modelViewerElement.getCameraTarget() : null;
|
||||
|
||||
const arData: ArTrackingData = {
|
||||
timestamp: timestamp,
|
||||
anchor: anchor.includes('not placed') ? null : anchor,
|
||||
cameraOrbit: orbit ? { theta: orbit.theta, phi: orbit.phi, radius: orbit.radius } : null,
|
||||
cameraTarget: target ? { x: target.x, y: target.y, z: target.z } : null,
|
||||
};
|
||||
this.metricsLog.arData.push(arData);
|
||||
|
||||
let orientation: DeviceOrientation | null = null;
|
||||
if (this.lastDeviceOrientation) {
|
||||
const orientation: DeviceOrientation = {
|
||||
timestamp: this.lastDeviceOrientation.timeStamp,
|
||||
orientation = {
|
||||
timestamp: timestamp,
|
||||
alpha: this.lastDeviceOrientation.alpha,
|
||||
beta: this.lastDeviceOrientation.beta,
|
||||
gamma: this.lastDeviceOrientation.gamma
|
||||
|
|
@ -110,30 +125,6 @@ export class MetricsTrackerService {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
public startArTracking(modelViewerElement: any): void {
|
||||
if (this.arTrackingSubscription || !modelViewerElement) return;
|
||||
|
||||
this.arTrackingSubscription = interval(500).subscribe(() => {
|
||||
if (!modelViewerElement.arActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
const anchor = modelViewerElement.getAnchor ? modelViewerElement.getAnchor() : 'getAnchor not available';
|
||||
const orbit = modelViewerElement.getCameraOrbit();
|
||||
const target = modelViewerElement.getCameraTarget();
|
||||
|
||||
const arData: ArTrackingData = {
|
||||
timestamp: Date.now(),
|
||||
anchor: anchor.includes('not placed') ? null : anchor,
|
||||
cameraOrbit: orbit ? { theta: orbit.theta, phi: orbit.phi, radius: orbit.radius } : null,
|
||||
cameraTarget: target ? { x: target.x, y: target.y, z: target.z } : null,
|
||||
};
|
||||
|
||||
this.metricsLog.arData.push(arData);
|
||||
});
|
||||
}
|
||||
|
||||
public sendMetricsToServer(testName: string, formData?: any) {
|
||||
const payload = {
|
||||
testName,
|
||||
|
|
@ -156,10 +147,8 @@ export class MetricsTrackerService {
|
|||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('deviceorientation', this.handleDeviceOrientation);
|
||||
}
|
||||
this.deviceOrientationSubscription?.unsubscribe();
|
||||
this.arTrackingSubscription?.unsubscribe();
|
||||
this.deviceOrientationSubscription = null;
|
||||
this.arTrackingSubscription = null;
|
||||
this.trackingSubscription?.unsubscribe();
|
||||
this.trackingSubscription = null;
|
||||
}
|
||||
|
||||
public resetMetrics(): void {
|
||||
|
|
|
|||
Loading…
Reference in New Issue