UNPKG

gazeplotter

Version:

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

59 lines (58 loc) 2.04 kB
import { AbstractDownloader } from './AbstractDownloader.ts'; import { getNumberOfParticipants, getNumberOfSegments, getParticipant, getSegment } from '../../stores/dataStore.ts'; export class ScanGraphDownloader extends AbstractDownloader { download(stimulusId, fileName) { const content = this.getStimulusScanGraphString(stimulusId); const txtFileContent = URL.createObjectURL(new Blob([content], { type: 'text/plain' })); this.triggerDownload(txtFileContent, fileName, '.txt'); } getStimulusScanGraphString(stimulusId) { let result = ''; const aoiKey = []; const alreadyUsedAoiIds = []; for (let i = 0; i < getNumberOfParticipants(); i++) { result += getParticipant(i).originalName + '\t'; for (let j = 0; j < getNumberOfSegments(stimulusId, i); j++) { const aoi = getSegment(stimulusId, i, j).aoi; result += this.getAoiString(aoi); if (aoi.length === 0) continue; if (alreadyUsedAoiIds.includes(aoi[0].id)) continue; aoiKey.push(this.getAoiKeyPart(aoi)); if (aoi[0] === undefined) continue; alreadyUsedAoiIds.push(aoi[0].id); } result += '\r\n'; } aoiKey.sort(); return this.getHeaderString(aoiKey.join(', ')) + result; } getHeaderString(aoiKey) { return `# # # # Key: # # = no fixation, ${aoiKey} # # The following part is the sequence similarity of the scanpaths # Sequence Similarity\tScanpath string `; } getAoiString(aoi) { if (aoi.length === 0) return '#'; return this.getAoiLetter(aoi[0].id); } getAoiLetter(aoi) { return String.fromCharCode(65 + aoi); } getAoiKeyPart(aoi) { if (aoi.length === 0) return ''; const name = aoi[0].displayedName; return `${this.getAoiLetter(aoi[0].id)} = ${name}`; } }