Skip to content

Instantly share code, notes, and snippets.

@andytwoods
Last active April 9, 2019 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andytwoods/ac995d0f76f8bbb7941fba7a202abc25 to your computer and use it in GitHub Desktop.
Save andytwoods/ac995d0f76f8bbb7941fba7a202abc25 to your computer and use it in GitHub Desktop.
tobii_vr_custom_json_analytics
# MIT License
#
# Copyright (c) 2019 Andy Thomas Woods
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import json
loc = 'C:\\Users\\Andy\\Desktop\\Mondrian2019v1'
filenames = ['JO', 'polly', 'TIMH', 'CALLUM', 'TimStokes', 'tony']
times = {
'polly': [9, 36, 37, 54],
'TIMH': [4, 34, 39, 59],
'CALLUM': [3, 31, 42, 71],
'JO': [0, 32, 45, 62],
'TimStokes': [3, 33, 40, 59],
'tony': [2, 32, 39, 54]
}
def crunch(json, _times):
start1 = _times[0]
stop1 = _times[1]
start2= _times[2]
stop2 = _times[3]
items = {'free': [], 'task': []}
time = 0
delta = 1.0/90
prev_item = None
current_item = None
duration = 0
fixations = 50
min_duration = 60 / 1000
for frame in (json['frameData']['TobiiProVRAnalytics.Metrics.TrackedObjectFrameData, TobiiProVRAnalytics, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null']['$values']):
try:
current_item = frame['objectId']
if current_item == prev_item:
duration += delta
else:
if prev_item:
if duration > min_duration:
if time > start1 and time < stop1:
if len(items['free']) < fixations:
items['free'].append(str(duration))
elif time > start2 and time < stop2:
if len(items['task']) < fixations:
items['task'].append(str(duration))
prev_item = current_item
duration = 0
time += delta
except TypeError:
pass
return items
data = {}
sav = ''
for filename in filenames:
filenamecombined = loc + '\\' + filename + '.json'
with open(filenamecombined) as json_file:
j = json.loads(json_file.read())
data = crunch(j, times[filename])
sav += filename + ',free,' + ','.join(data['free']) + '\n'
sav += filename + ',task,' + ','.join(data['task']) + '\n'
with open(loc + '\\' + 'results.txt', 'w') as file:
file.write(sav)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment