UNPKG

gazeplotter

Version:

Gazeplotter is a Svelte application for visualizing eye-tracking data.

53 lines (52 loc) 2.06 kB
import { AbstractEyeDeserializer } from './AbstractEyeDeserializer.ts'; export class VarjoEyeDeserializer extends AbstractEyeDeserializer { cTime; cActorLabel; // ActorLabel stands for AOI mTimeStart = ''; mTimeLast = ''; mTimeBase = null; mActorLabel = null; mParticipant; constructor(header, fileName) { super(); this.cTime = this.getIndex(header, 'Time'); this.cActorLabel = this.getIndex(header, 'Actor Label'); this.mParticipant = fileName.split('.')[0]; } deserialize(row) { const time = row[this.cTime]; const actorLabel = row[this.cActorLabel]; const isNewSegment = actorLabel !== this.mActorLabel; let output = null; if (this.mTimeBase === null) this.mTimeBase = this.convertStringTime(time); // at the beginning of the file, set the base time if (isNewSegment) { output = this.finalize(); this.mTimeStart = time; // if a new segment starts, set the start time this.mActorLabel = actorLabel; } this.mTimeLast = time; return output; } finalize() { const baseTime = this.mTimeBase; if (baseTime === null) throw new Error('Base time is null'); const actorLabel = this.mActorLabel; if (actorLabel === null) return null; return { aoi: actorLabel === '' ? null : [actorLabel], category: 'Fixation', start: String(this.convertStringTime(this.mTimeStart) - baseTime), end: String(this.convertStringTime(this.mTimeLast) - baseTime), participant: this.mParticipant, stimulus: 'VarjoScene' }; } convertStringTime(time) { // From format "2022:11:11:15:50:18:30" const timeArray = time.split(':'); return new Date(Number(timeArray[0]), Number(timeArray[1]), Number(timeArray[2]), Number(timeArray[3]), Number(timeArray[4]), Number(timeArray[5]), Number(timeArray[6])).getTime(); } }