UNPKG

gazeplotter

Version:

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

60 lines (59 loc) 2.19 kB
import { AbstractEyeDeserializer } from './AbstractEyeDeserializer.ts'; // BEWARE! If only one timestamp for whole segment, start and end are the same! export class CsvEyeDeserializer extends AbstractEyeDeserializer { cTime; cParticipant; cStimulus; cAoi; mTimeStart = ''; mTimeLast = ''; mTimeBase = null; mAoi = null; mParticipant = 'CsvParticipant'; mStimulus = 'CsvFile'; constructor(header) { super(); this.cTime = this.getIndex(header, 'Time'); this.cAoi = this.getIndex(header, 'AOI'); this.cParticipant = this.getIndex(header, 'Participant'); this.cStimulus = this.getIndex(header, 'Stimulus'); } deserialize(row) { const time = row[this.cTime]; const aoi = row[this.cAoi]; const participant = row[this.cParticipant]; const stimulus = row[this.cStimulus]; const isNewSegment = (aoi !== this.mAoi) || (participant !== this.mParticipant) || (stimulus !== this.mStimulus); const isNewTimebase = (this.mTimeBase === null) || (participant !== this.mParticipant) || (stimulus !== this.mStimulus); let output = null; if (this.mTimeBase === null) this.mTimeBase = Number(time); if (isNewSegment) { output = this.finalize(); this.mTimeStart = time; // if a new segment starts, set the start time this.mAoi = aoi; this.mParticipant = participant; this.mStimulus = stimulus; } if (isNewTimebase) this.mTimeBase = Number(time); this.mTimeLast = time; return output; } finalize() { const baseTime = this.mTimeBase; if (baseTime === null) throw new Error('Base time is null'); const aoi = this.mAoi; if (aoi === null) return null; return { aoi: aoi === '' ? null : [aoi], category: 'Fixation', start: String(Number(this.mTimeStart) - baseTime), end: String(Number(this.mTimeLast) - baseTime), participant: this.mParticipant, stimulus: this.mStimulus }; } }