-
Notifications
You must be signed in to change notification settings - Fork 1
/
gaze_processor.py
89 lines (69 loc) · 2.65 KB
/
gaze_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
# external
import pandas
# custom
from pygazeanalyser.gazeplotter import draw_fixations, draw_heatmap, \
draw_scanpath, draw_raw
def process_files(filename, gaze_data):
for trialnr in range(len(gaze_data)):
# Load saccades and fixations
# [starttime, endtime, duration, startx, starty, endx, endy]
saccades = gaze_data[trialnr]['events']['Esac']
# [starttime, endtime, duration, endx, endy]
fixations = gaze_data[trialnr]['events']['Efix']
return trialnr, fixations, saccades
def generate_csv(ENGINEEREDDATADIR, filename, fixations, saccades):
panda_fix = pandas.DataFrame(fixations)
panda_fix.columns = ['Sfix', 'Efix', 'Durfix', 'endxfix', 'endyfix']
panda_sac = pandas.DataFrame(saccades)
panda_sac.columns = ['Ssac', 'Esac', 'Dursac', 'startxsac', 'startysac', 'endxsac', 'endysac']
if int(filename[4:5]) == 1:
panda_fix['load'] = 1
else:
panda_fix['load'] = 2
with open(ENGINEEREDDATADIR + '/%s_fix.csv' % (filename[:3]), 'a+') as f:
panda_fix.to_csv(f, sep='\t', index=False)
if int(filename[4:5]) == 1:
panda_sac['load'] = 1
else:
panda_sac['load'] = 2
with open(ENGINEEREDDATADIR + '/%s_sac.csv' % (filename[:3]), 'a+') as f:
panda_sac.to_csv(f, sep='\t', index=False)
return panda_fix, panda_sac
def generate_plots(IMGDIR, PLOTDIR, filename, fixations, saccades, data, DISPSIZE, trialnr):
# cognitive load
if int(filename[4:5]) == 1:
cognitive_load = "LOW"
else:
cognitive_load = "HIGH"
#imgname = "screenshot.jpg"
#imagefile = os.path.join(IMGDIR,imgname)
# paths
rawplotfile = os.path.join(
PLOTDIR,
"raw_data_%s_%s" % (filename[:3], cognitive_load))
scatterfile = os.path.join(
PLOTDIR,
"fixations_%s_%s" % (filename[:3], cognitive_load))
scanpathfile = os.path.join(
PLOTDIR,
"scanpath_%s_%s" % (filename[:3], cognitive_load))
heatmapfile = os.path.join(
PLOTDIR,
"heatmap_%s_%s" % (filename[:3], cognitive_load))
# raw data points
draw_raw(
data[trialnr]['x'], data[trialnr]['y'],
DISPSIZE, imagefile=None, savefilename=rawplotfile)
# fixations
draw_fixations(
fixations, DISPSIZE, imagefile=None, durationsize=True,
durationcolour=False, alpha=0.5, savefilename=scatterfile)
# scanpath
draw_scanpath(
fixations, saccades, DISPSIZE, imagefile=None,
alpha=0.5, savefilename=scanpathfile)
# heatmap
draw_heatmap(
fixations, DISPSIZE, imagefile=None,
durationweight=True, alpha=0.5, savefilename=heatmapfile)