Source code for eyecode.data.hansen_2012
"""Complete dataset from the eyeCode experiment (http://arxiv.org/abs/1304.5257)"""
import pandas, os, gzip
from glob import glob
DATA_DIR = os.path.abspath(os.path.dirname(__file__))
XML_DIR = os.path.join(DATA_DIR, "xml")
def __read_csv(file_name):
return pandas.read_csv(gzip.open(os.path.join(DATA_DIR, "{0}.csv.gz".format(file_name))))
[docs]def programs():
"""Code metrics for all programs"""
return __read_csv("programs")
def line_categories():
"""Automatically assigned categories for program lines"""
return __read_csv("line_categories")
[docs]def experiments():
"""Experiment/participant information"""
return __read_csv("experiments")
[docs]def trials():
"""Individual trial information"""
return __read_csv("trials")
def trial_responses():
"""Timestamped text responses for all trials"""
return __read_csv("trial_responses")
[docs]def all_fixations():
"""Hit-tested fixations for all trials"""
return __read_csv("all_fixations")
def line_fixations():
"""Hit-tested fixations with numeric line column for all trials"""
return __read_csv("line_fixations")
def raw_fixations():
"""Fixations without offset correction and hit testing"""
return __read_csv("raw_fixations")
[docs]def areas_of_interest():
"""AOI rectangles for all trials"""
return __read_csv("aois")
def youtube_videos():
"""URLs for uploaded eye-tracking videos"""
return __read_csv("youtube")
def trial_screen_path(trial_id):
"""Path to screenshot image for the given eye-tracking trial"""
return os.path.join(DATA_DIR, "screens", "{0}.png".format(trial_id))
[docs]def trial_screen(trial_id):
"""Screenshot image for the given eye-tracking trial"""
from PIL import Image
return Image.open(trial_screen_path(trial_id))
[docs]def program_code(base, version):
"""Lines of code for the given program base and version"""
return open(os.path.join(DATA_DIR, "programs", "{0}_{1}.py".format(base, version)), "r").readlines()
[docs]def program_output(base, version):
"""Lines of correct text output for the given program base and version"""
return open(os.path.join(DATA_DIR, "programs", "output", "{0}_{1}.py.txt".format(base, version)), "r").readlines()
def program_lines_with_code(base, version):
"""List of non-blank lines for the given program base and version (1-based)"""
lines = program_code(base, version)
return [i+1 for i, line in enumerate(lines) if len(line.strip()) > 0]
def program_image(base, version):
"""Image with syntax-highlighted, line-numbered code for the given program base and version"""
from PIL import Image
return Image.open(os.path.join(DATA_DIR, "images", "programs", "{0}_{1}.py.png".format(base, version)))
def xml_trial_ids():
return [int(os.path.split(p)[1][:-len(".xml.gz")])
for p in glob(os.path.join(XML_DIR, "*.xml.gz"))]
def xml_trial_path(trial_id):
return os.path.join(XML_DIR, "{0:02d}.xml.gz".format(trial_id))
def xml_trial(trial_id):
from lxml import etree
return etree.parse(xml_trial_path(trial_id))