Commits

Alexander Konovalov  committed db73224

A small script to calculate timestep distribution.

  • Participants
  • Parent commits 807ee5f

Comments (0)

Files changed (1)

File timestep_distribution.py

+#!/usr/bin/env python
+
+from __future__ import division
+from util import *
+import os, os.path, errno
+
+def read_data(path):
+    data = {}
+
+    with open(path, "rt") as f:
+        for line in f:
+            time, gaze_x, gaze_y, mouse_x, mouse_y, click, user, query = \
+                tuple(line.strip().split(' '))
+
+            if user not in data:
+                data[user] = {}
+            if query not in data[user]:
+                data[user][query] = Entry()
+
+            entry = data[user][query]
+
+            entry.time.append(int(time))
+            entry.gaze[0].append(int(gaze_x))
+            entry.gaze[1].append(int(gaze_y))
+            entry.mouse[0].append(int(mouse_x))
+            entry.mouse[1].append(int(mouse_y))
+            entry.click.append(int(click))
+
+    for queries in data.itervalues():
+        for query, entry in queries.iteritems():
+            entry.time = numpy.array(entry.time)
+            entry.gaze = numpy.array(entry.gaze).T
+            entry.mouse = numpy.array(entry.mouse).T
+            entry.click = numpy.array(entry.click)
+
+    return data
+
+if __name__ == "__main__":
+    data = read_data("data/DATA")
+
+    total = 0
+    distribution = {}
+
+    for user, queries in data.iteritems():
+        for query, entry in queries.iteritems():
+            dt = entry.time[1:] - entry.time[:-1]
+            for v in dt:
+                if v not in distribution:
+                    distribution[v] = 0
+                distribution[v] += 1
+
+                total += 1
+
+    for k in distribution.iterkeys():
+        distribution[v] /= total
+
+    for k in sorted(list(distribution.iterkeys())):
+        print "%s\t%s" % (k, distribution[k])