In [1]:
%run prelude.ipy
In [21]:
code = data.hansen_2012.program_code("overload", "plusmixed")
aois = aoi.code_to_aois(code, filename="test.py", offset=(10, 10))
aois.to_csv("/home/hansenm/Fall 2013/Research/eyecode/models/mr_bits/programs/overload_plusmixed.txt",
index=False, sep=' ')
aois
Out[21]:
In [20]:
display_html(aois.to_html())
Out[20]:
In []:
pandas.set_printoptions(precision=2)
df = programs.copy()
df.columns = ["Base", "Version", "Code Ch", "Code Ln", "CC", "HE", "HV", "Ouput Ch", "Output Ln"]
df
In []:
s = df.to_latex(index=False)
open("../../../Journal Article/programs_table.tex", "w").write(s)
In [2]:
raw_fixes = data.busjahn_2013.raw_fixations()
#screen = data.busjahn_2013.program_image("rectangle")
screen = data.busjahn_2013.program_image("basketball")
#offset = (-320, -88)
#raw_fixes.fix_x = raw_fixes.fix_x.apply(lambda x: x + offset[0])
#raw_fixes.fix_y = raw_fixes.fix_y.apply(lambda y: y + offset[1])
In []:
fixes = raw_fixes[raw_fixes.trial_id == 8]
plot.fixations.circles(fixes, screen, radius_min=5, radius_max=5)
In []:
from PIL import Image
font_path = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
blank = Image.new("RGB", screen.size, color="#FFFFFF")
lines = open("../../eyecode/data/busjahn_2013/programs/rectangle.java", "r").readlines()
plot.misc.render_code(lines, blank, font_path, 22, 21, offset=(340, 93))
plot.fixations.circles(fixes, blank, radius_min=5, radius_max=5)
In [2]:
img = data.busjahn_2013.program_image("basketball")
aois = data.busjahn_2013.areas_of_interest()
bb_aois = aois[aois.program == "basketball"]
In [3]:
plot.aoi.draw_rectangles(bb_aois[bb_aois.kind == "sub-line"], img)
Out[3]:
In [63]:
df2 = rects.copy()
df2["kind"] = "line"
df2["name"] = "line "
df2.width += df2.x - 300 + 15
df2.x = 300
df2.y -= 8
df2.height += 16
df2.to_csv("../../eyecode/data/busjahn_2013/areas_of_interest.csv")
aoi.draw_rectangles(df2, img)
Out[63]:
In [2]:
raw_fixes = data.busjahn_2013.raw_fixations()
aois = data.busjahn_2013.areas_of_interest()
In [10]:
df = aoi.hit_test(raw_fixes, aois)
df[:25]
Out[10]:
In [9]:
line_fixes = data.busjahn_2013.line_fixations()
t_fixes = line_fixes[line_fixes.trial_id == 8]
fig = plot.fixations.line_timeline_single(t_fixes).figure
fig.tight_layout()
fig
Out[9]:
In [10]:
line_fixes = data.busjahn_2013.line_fixations()
t_fixes = line_fixes[line_fixes.trial_id == 9]
fig = plot.fixations.line_timeline_single(t_fixes).figure
fig.tight_layout()
fig
Out[10]:
In [4]:
aois = data.busjahn_2013.areas_of_interest()
screen = data.busjahn_2013.program_image("rectangle")
plot.aoi.draw_rectangles(aois[aois.kind == "signature"], screen)
Out[4]:
In [43]:
all_fixations = data.busjahn_2013.all_fixations()
all_fixations["aoi_method-call"].unique()
Out[43]:
In [20]:
all_fixations = data.busjahn_2013.all_fixations()
aois = data.busjahn_2013.areas_of_interest()
line_fixations = data.busjahn_2013.line_fixations()
In [3]:
t8_fixes = all_fixations[all_fixations.trial_id == 8]
t9_fixes = all_fixations[all_fixations.trial_id == 9]
In [5]:
aoi.scanpath_from_fixations(t8_fixes, aoi_names={"line":[]}).to_csv("../../../Gaze Workshop/subject1_lines.csv")
In [6]:
aoi.scanpath_from_fixations(t9_fixes, aoi_names={"line":[]}).to_csv("../../../Gaze Workshop/subject2_lines.csv")
In [26]:
plot.fixations.line_timeline(line_fixations, step_size=500).figure
Out[26]:
In [27]:
code_image = Image.open("../../eyecode/data/busjahn_2013/images/rectangle-pygment.png")
In [48]:
plot.fixations.line_code_image(line_fixations, code_image, image_padding=5, bar_height=0.75, bar_mult=1.015, num_lines=23)
Out[48]:
In [50]:
plot.fixations.line_code_image(line_fixations[line_fixations.trial_id == 9], code_image, image_padding=5, bar_height=0.75, bar_mult=1.015, num_lines=23)
Out[50]:
In [32]:
line_order = data.busjahn_2013.lines_execution_order()
In [6]:
all_fixations = data.busjahn_2013.all_fixations()
t8_fixes = all_fixations[all_fixations.trial_id == 8]
sp = aoi.scanpath_from_fixations(t8_fixes, aoi_names={"line":[]}, repeats=False)
In [24]:
from nltk.util import ngrams
from nltk import FreqDist
In [35]:
N = 4
line_grams = set(ngrams(line_order.name, N))
fd = { k: v for k, v in FreqDist(ngrams(sp.values, N)).iteritems() if k in line_grams }
fd
Out[35]:
In [3]:
all_fixations = data.busjahn_2013.all_fixations()
aois = data.busjahn_2013.areas_of_interest()
t9_fixes = all_fixations[all_fixations.trial_id == 9]
main_aoi = aois[(aois.kind == "block") & (aois.name == "main")].iloc[0]
main_bbox = main_aoi[["x", "y", "width", "height"]].values
In [79]:
main_fixes = t9_fixes.iloc[56:72]
density, counts = metrics.fixation_spatial_density(main_fixes, grid_bbox=main_bbox, num_rows=6, num_cols=8)
print density / len(main_fixes)
print counts.T
main_fixes.duration_ms.median()
Out[79]:
In [80]:
flat_counts = counts.flatten()
equal_counts = np.zeros(shape=(1, len(flat_counts))) + (flat_counts.sum() / len(flat_counts))
scipy.spatial.distance.cosine(flat_counts, equal_counts)
Out[80]:
In [36]:
con_aoi = aois[(aois.kind == "block") & (aois.name == "constructor")].iloc[0]
con_fixes = t9_fixes.iloc[73:89]
con_bbox = con_aoi[["x", "y", "width", "height"]].values
In [81]:
density, counts = metrics.fixation_spatial_density(con_fixes, grid_bbox=con_bbox, num_rows=6, num_cols=8)
print density / len(con_fixes)
print counts.T
con_fixes.duration_ms.median()
Out[81]:
In [82]:
flat_counts = counts.flatten()
equal_counts = np.zeros(shape=(1, len(flat_counts))) + (flat_counts.sum() / len(flat_counts))
scipy.spatial.distance.cosine(flat_counts, equal_counts)
Out[82]:
In [69]:
main_fixes = t9_fixes.iloc[90:117]
density, counts = metrics.fixation_spatial_density(main_fixes, grid_bbox=main_bbox, num_rows=6, num_cols=8)
print density / len(main_fixes)
print counts.T
pyplot.imshow(counts.T, interpolation="none").figure
Out[69]:
In [74]:
import scipy.spatial
In [75]:
flat_counts = counts.flatten()
equal_counts = np.zeros(shape=(1, len(flat_counts))) + (flat_counts.sum() / len(flat_counts))
scipy.spatial.distance.cosine(flat_counts, equal_counts)
Out[75]:
In [78]:
main_fixes = t9_fixes.iloc[128:]
density, counts = metrics.fixation_spatial_density(main_fixes, grid_bbox=main_bbox, num_rows=6, num_cols=8)
print density / len(main_fixes)
print counts.T
main_fixes.duration_ms.median()
pyplot.imshow(counts.T, interpolation="none").figure
Out[78]:
In [77]:
flat_counts = counts.flatten()
equal_counts = np.zeros(shape=(1, len(flat_counts))) + (flat_counts.sum() / len(flat_counts))
scipy.spatial.distance.cosine(flat_counts, equal_counts)
Out[77]:
In [2]:
all_fixations = data.busjahn_2013.all_fixations()
aois = data.busjahn_2013.areas_of_interest()
t8_fixes = all_fixations[all_fixations.trial_id == 8]
t9_fixes = all_fixations[all_fixations.trial_id == 9]
code_aoi = aois[aois.name == "code box"].iloc[0]
code_bbox = code_aoi[["x", "y", "width", "height"]].values
In [8]:
fun = lambda fixes: metrics.fixation_spatial_density(fixes, grid_bbox=code_bbox, num_rows=rows, num_cols=cols)[0]
s = util.rolling_func(t8_fixes, fun, 3000)
s.plot(figsize=(20, 8)).figure
In [118]:
s = util.rolling_func(t9_fixes, fun, 3000)
s.plot(figsize=(20, 8)).figure
Out[118]: