def read_event_data(self, event_file): all_event = [] with open(event_file, 'r') as f: for i in xrange(params.EVENTS_FIRST_DATA_LINE - 1): if i is (params.USER_EVENT_HEADER_LINE - 1): # read the row of the table header for user events fixation_headers = next(f).strip().split(',') else: next(f) reader = csv.DictReader(f, fieldnames=fixation_headers) for row in reader: if row["Event Type"] != "UserEvent": continue data = {"timestamp": utils.cast_int(row["Start"]), "description": row["Description"]} descriptions = row["Description"].split(" ") event_type = descriptions[2] if event_type == "UE-mouseclick": if descriptions[3] == "left": data.update({"event": "LeftMouseClick"}) else: data.update({"event": "RightMouseClick"}) data.update({"x_coord": utils.cast_int(descriptions[4].split("=")[1]), "y_coord": utils.cast_int(descriptions[5].split("=")[1])}) elif event_type == "UE-keypress": data.update({"event": "KeyPress", "key_name": descriptions[3]}) all_event.append(Event(data, self.media_offset)) return all_event
def read_all_data(self, all_file): """Returns a list of "Datapoint"s read from an "All-Data" file. Args: all_file:A string containing the name of the 'All-Data.tsv' file output by the Tobii software. Returns: a list of "Datapoint"s """ all_data = [] with open(all_file, 'r') as f: reader = csv.DictReader(f, delimiter="\t") for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if not row["ValidityLeft"] or not row["ValidityRight"]: #ignore data point with no validity information continue pupil_left = utils.cast_float(row["PupilLeft"], -1) pupil_right = utils.cast_float(row["PupilRight"], -1) distance_left = utils.cast_float(row["DistanceLeft"], -1) distance_right = utils.cast_float(row["DistanceRight"], -1) data = {"timestamp": utils.cast_int(row["RecordingTimestamp"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": Recording.get_distance(distance_left, distance_right), "is_valid": utils.cast_int(row["ValidityRight"]) < 2 or utils.cast_int(row["ValidityLeft"]) < 2, "stimuliname": row["MediaName"], "fixationindex": utils.cast_int(row["FixationIndex"]), "gazepointxleft": utils.cast_float(row["GazePointLeftX (ADCSpx)"])} all_data.append(Datapoint(data)) return all_data
def read_event_data(self, event_file): """Returns a list of "Event"s read from an "Event-Data" file. Args: event_file: A string containing the name of the 'Event-Data.tsv' file output by the Tobii software. Returns: a list of "Event"s """ all_event = [] with open(event_file, 'r') as f: reader = csv.DictReader(f, delimiter='\t') for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if row["MouseEventIndex"]: #mouse event data = { "timestamp": utils.cast_int(row["RecordingTimestamp"]), "event": row["MouseEvent"] + "MouseClick", "x_coord": utils.cast_int(row["MouseEventX (MCSpx)"]), "y_coord": utils.cast_int(row["MouseEventY (MCSpx)"]) } all_event.append(Event(data, self.media_offset)) elif row["KeyPressEventIndex"]: #keyboard event data = { "timestamp": utils.cast_int(row["RecordingTimestamp"]), "event": "KeyPress", "key_name": row["KeyPressEvent"] } all_event.append(Event(data, self.media_offset)) return all_event
def read_event_data(self, event_file): """Returns a list of "Event"s read from an "Event-Data" file. Args: event_file: A string containing the name of the 'Event-Data.tsv' file output by the Tobii software. Returns: a list of "Event"s """ all_event = [] with open(event_file, 'r') as f: for _ in xrange(params.EVENTSHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter='\t') for row in reader: data = {"timestamp": utils.cast_int(row["Timestamp"]), "event": row["Event"], "event_key": utils.cast_int(row["EventKey"])} if data["event"] == "LeftMouseClick" or data["event"] == "RightMouseClick": data.update({"x_coord": utils.cast_int(row["Data1"]), "y_coord": utils.cast_int(row["Data2"])}) elif data["event"] == "KeyPress": data.update({"key_code": utils.cast_int(row["Data1"]), "key_name": row["Descriptor"]}) elif data["event"] == "LogData": data.update({"description": row["Data1"]}) all_event.append(Event(data, self.media_offset)) return all_event
def read_event_data(self, event_file): """Returns a list of "Event"s read from an "Event-Data" file. Args: event_file: A string containing the name of the 'Event-Data.tsv' file output by the Tobii software. Returns: a list of "Event"s """ all_event = [] with open(event_file, 'r') as f: reader = csv.DictReader(f, delimiter='\t') for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if row["MouseEventIndex"] : #mouse event data = {"timestamp": utils.cast_int(row["RecordingTimestamp"]), "event": row["MouseEvent"]+"MouseClick", "x_coord": utils.cast_int(row["MouseEventX (MCSpx)"]), "y_coord": utils.cast_int(row["MouseEventY (MCSpx)"]) } all_event.append(Event(data, self.media_offset)) elif row["KeyPressEventIndex"] : #keyboard event data = {"timestamp": utils.cast_int(row["RecordingTimestamp"]), "event": "KeyPress", "key_name": row["KeyPressEvent"] } all_event.append(Event(data, self.media_offset)) return all_event
def read_fixation_data(self, fixation_file): """Returns a list of "Fixation"s read from an "Fixation-Data" file. Args: fixation_file: A string containing the name of the 'Fixation-Data.tsv' file output by the Tobii software. Returns: a list of "Fixation"s """ all_fixation = [] with open(fixation_file, 'r') as f: currentfix = 0 reader = csv.DictReader(f, delimiter='\t') for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if not row["ValidityLeft"] or not row["ValidityRight"]: #ignore data point with no validity information continue if row["GazeEventType"] != "Fixation" or currentfix == row["FixationIndex"]: #if not a fixation or the current fixation continue data = {"fixationindex": utils.cast_int(row["FixationIndex"]), "timestamp": utils.cast_int(row["RecordingTimestamp"]), "fixationduration": utils.cast_int(row["GazeEventDuration"]), "fixationpointx": utils.cast_int(row["FixationPointX (MCSpx)"]), "fixationpointy": utils.cast_int(row["FixationPointY (MCSpx)"])} all_fixation.append(Fixation(data, self.media_offset)) currentfix = row["FixationIndex"] return all_fixation
def read_fixation_data(self, fixation_file): """Returns a list of "Fixation"s read from an "Fixation-Data" file. Args: fixation_file: A string containing the name of the 'Fixation-Data.tsv' file output by the Tobii software. Returns: a list of "Fixation"s """ all_fixation = [] with open(fixation_file, 'r') as f: for _ in xrange(params.FIXATIONHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter='\t') for row in reader: data = { "fixationindex": utils.cast_int(row["FixationIndex"]), "timestamp": utils.cast_int(row["Timestamp"]), "fixationduration": utils.cast_int(row["FixationDuration"]), "fixationpointx": utils.cast_int(row["MappedFixationPointX"]), "fixationpointy": utils.cast_int(row["MappedFixationPointY"]) } all_fixation.append(Fixation(data, self.media_offset)) return all_fixation
def read_all_data(self, all_file): """Returns a list of "Datapoint"s read from an "All-Data" file. Args: all_file:A string containing the name of the 'All-Data.tsv' file output by the Tobii software. Returns: a list of "Datapoint"s """ all_data = [] with open(all_file, 'r') as f: for _ in xrange(params.ALLDATAHEADERLINES + params.NUMBEROFEXTRAHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter="\t") for row in reader: if not row["Number"]: # ignore invalid data point continue pupil_left = utils.cast_float(row["PupilLeft"], -1) pupil_right = utils.cast_float(row["PupilRight"], -1) distance_left = utils.cast_float(row["DistanceLeft"], -1) distance_right = utils.cast_float(row["DistanceRight"], -1) data = {"timestamp": utils.cast_int(row["Timestamp"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": Recording.get_distance(distance_left, distance_right), "is_valid": utils.cast_int(row["ValidityRight"]) < 2 or utils.cast_int(row["ValidityLeft"]) < 2, "stimuliname": row["StimuliName"], "fixationindex": utils.cast_int(row["FixationIndex"]), "gazepointxleft": utils.cast_float(row["GazePointXLeft"])} all_data.append(Datapoint(data)) return all_data
def contestants_to_list(self): l = [] for _, c in self.contestants.items(): l.append([self.year, c.country.code, c.country.name, c.performer, c.song, cast_int(c.place_contest), cast_int(c.sf_num), cast_int(c.running_final), cast_int(c.running_sf), cast_int(c.place_final), cast_int(c.points_final), cast_int(c.place_sf), cast_int(c.points_sf), cast_int(c.points_tele_final), cast_int(c.points_jury_final), cast_int(c.points_tele_sf), cast_int(c.points_jury_sf), ';'.join(c.composers), ';'.join(c.lyricists), c.lyrics, c.youtube_url]) return l
def read_all_data(self, all_file): all_data = [] with open(all_file, 'r') as f: reader = csv.DictReader(f) for row in reader: if row["L Event Info"] != "Fixation": # ignore data points other than fixations (gaze points) continue pupil_left = utils.cast_float(row["L Pupil Diameter [mm]"]) pupil_right = utils.cast_float(row["R Pupil Diameter [mm]"]) data = {"timestamp": utils.cast_int(row["Time"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": 0, # temporarily set to 0 "is_valid": True, # temporarily set to true for all "stimuliname": "Screen", # temporarily set to the same stimuli "fixationindex": utils.cast_int(row["Time"]), "gazepointxleft": utils.cast_float(row["L POR X [px]"])} all_data.append(Datapoint(data)) return all_data
def read_all_data(self, all_file): """Returns a list of "Datapoint"s read from an "All-Data" file. Args: all_file:A string containing the name of the 'All-Data.tsv' file output by the Tobii software. Returns: a list of "Datapoint"s """ all_data = [] with open(all_file, 'r') as f: for _ in xrange(params.ALLDATAHEADERLINES + params.NUMBEROFEXTRAHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter="\t") for row in reader: if not row["Number"]: # ignore invalid data point continue pupil_left = utils.cast_float(row["PupilLeft"], -1) pupil_right = utils.cast_float(row["PupilRight"], -1) distance_left = utils.cast_float(row["DistanceLeft"], -1) distance_right = utils.cast_float(row["DistanceRight"], -1) data = { "timestamp": utils.cast_int(row["Timestamp"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": Recording.get_distance(distance_left, distance_right), "is_valid": utils.cast_int(row["ValidityRight"]) < 2 or utils.cast_int(row["ValidityLeft"]) < 2, "stimuliname": row["StimuliName"], "fixationindex": utils.cast_int(row["FixationIndex"]), "gazepointxleft": utils.cast_float(row["GazePointXLeft"]) } all_data.append(Datapoint(data)) return all_data
def read_all_data(self, all_file): """Returns a list of "Datapoint"s read from an "All-Data" file. Args: all_file:A string containing the name of the 'All-Data.tsv' file output by the Tobii software. Returns: a list of "Datapoint"s """ all_data = [] with open(all_file, 'r') as f: reader = csv.DictReader(f, delimiter="\t") for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if not row["ValidityLeft"] or not row[ "ValidityRight"]: #ignore data point with no validity information continue pupil_left = utils.cast_float(row["PupilLeft"], -1) pupil_right = utils.cast_float(row["PupilRight"], -1) distance_left = utils.cast_float(row["DistanceLeft"], -1) distance_right = utils.cast_float(row["DistanceRight"], -1) data = { "timestamp": utils.cast_int(row["RecordingTimestamp"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": Recording.get_distance(distance_left, distance_right), "is_valid": utils.cast_int(row["ValidityRight"]) < 2 or utils.cast_int(row["ValidityLeft"]) < 2, "stimuliname": row["MediaName"], "fixationindex": utils.cast_int(row["FixationIndex"]), "gazepointxleft": utils.cast_float(row["GazePointLeftX (ADCSpx)"]) } all_data.append(Datapoint(data)) return all_data
def read_fixation_data(self, fixation_file): all_fixation = [] with open(fixation_file, 'r') as f: for i in xrange(params.EVENTS_FIRST_DATA_LINE - 1): if i is (params.FIXATION_HEADER_LINE - 1): # read the row of the table header for fixations fixation_headers = next(f).strip().split(',') else: next(f) reader = csv.DictReader(f, fieldnames=fixation_headers) for row in reader: if not row["Event Type"].startswith("Fixation L"): continue data = {"fixationindex": utils.cast_int(row["Number"]), "timestamp": utils.cast_int(row["Start"]), "fixationduration": utils.cast_int(row["Duration"]), "fixationpointx": utils.cast_float(row["Location X"]), "fixationpointy": utils.cast_float(row["Location Y"])} all_fixation.append(Fixation(data, self.media_offset)) return all_fixation
def read_event_data(self, event_file): all_event = [] with open(event_file, 'r') as f: for i in xrange(params.EVENTS_FIRST_DATA_LINE - 1): if i is (params.USER_EVENT_HEADER_LINE - 1 ): # read the row of the table header for user events fixation_headers = next(f).strip().split(',') else: next(f) reader = csv.DictReader(f, fieldnames=fixation_headers) for row in reader: if row["Event Type"] != "UserEvent": continue data = { "timestamp": utils.cast_int(row["Start"]), "description": row["Description"] } descriptions = row["Description"].split(" ") event_type = descriptions[2] if event_type == "UE-mouseclick": if descriptions[3] == "left": data.update({"event": "LeftMouseClick"}) else: data.update({"event": "RightMouseClick"}) data.update({ "x_coord": utils.cast_int(descriptions[4].split("=")[1]), "y_coord": utils.cast_int(descriptions[5].split("=")[1]) }) elif event_type == "UE-keypress": data.update({ "event": "KeyPress", "key_name": descriptions[3] }) all_event.append(Event(data, self.media_offset)) return all_event
def read_fixation_data(self, fixation_file): all_fixation = [] with open(fixation_file, 'r') as f: for i in xrange(params.EVENTS_FIRST_DATA_LINE - 1): if i is (params.FIXATION_HEADER_LINE - 1): # read the row of the table header for fixations fixation_headers = next(f).strip().split(',') else: next(f) reader = csv.DictReader(f, fieldnames=fixation_headers) for row in reader: if not row["Event Type"].startswith("Fixation L"): continue data = { "fixationindex": utils.cast_int(row["Number"]), "timestamp": utils.cast_int(row["Start"]), "fixationduration": utils.cast_int(row["Duration"]), "fixationpointx": utils.cast_float(row["Location X"]), "fixationpointy": utils.cast_float(row["Location Y"]) } all_fixation.append(Fixation(data, self.media_offset)) return all_fixation
def read_all_data(self, all_file): all_data = [] with open(all_file, 'r') as f: reader = csv.DictReader(f) for row in reader: if row["L Event Info"] != "Fixation": # ignore data points other than fixations (gaze points) continue pupil_left = utils.cast_float(row["L Pupil Diameter [mm]"]) pupil_right = utils.cast_float(row["R Pupil Diameter [mm]"]) data = { "timestamp": utils.cast_int(row["Time"]), "pupilsize": Recording.get_pupil_size(pupil_left, pupil_right), "distance": 0, # temporarily set to 0 "is_valid": True, # temporarily set to true for all "stimuliname": "Screen", # temporarily set to the same stimuli "fixationindex": utils.cast_int(row["Time"]), "gazepointxleft": utils.cast_float(row["L POR X [px]"]) } all_data.append(Datapoint(data)) return all_data
def read_fixation_data(self, fixation_file): """Returns a list of "Fixation"s read from an "Fixation-Data" file. Args: fixation_file: A string containing the name of the 'Fixation-Data.tsv' file output by the Tobii software. Returns: a list of "Fixation"s """ all_fixation = [] with open(fixation_file, 'r') as f: currentfix = 0 reader = csv.DictReader(f, delimiter='\t') for row in reader: if row["MediaName"] != 'ScreenRec': # ignore non-recording data point continue if not row["ValidityLeft"] or not row[ "ValidityRight"]: #ignore data point with no validity information continue if row["GazeEventType"] != "Fixation" or currentfix == row[ "FixationIndex"]: #if not a fixation or the current fixation continue data = { "fixationindex": utils.cast_int(row["FixationIndex"]), "timestamp": utils.cast_int(row["RecordingTimestamp"]), "fixationduration": utils.cast_int(row["GazeEventDuration"]), "fixationpointx": utils.cast_int(row["FixationPointX (MCSpx)"]), "fixationpointy": utils.cast_int(row["FixationPointY (MCSpx)"]) } all_fixation.append(Fixation(data, self.media_offset)) currentfix = row["FixationIndex"] return all_fixation
def read_event_data(self, event_file): """Returns a list of "Event"s read from an "Event-Data" file. Args: event_file: A string containing the name of the 'Event-Data.tsv' file output by the Tobii software. Returns: a list of "Event"s """ all_event = [] with open(event_file, 'r') as f: for _ in xrange(params.EVENTSHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter='\t') for row in reader: data = { "timestamp": utils.cast_int(row["Timestamp"]), "event": row["Event"], "event_key": utils.cast_int(row["EventKey"]) } if data["event"] == "LeftMouseClick" or data[ "event"] == "RightMouseClick": data.update({ "x_coord": utils.cast_int(row["Data1"]), "y_coord": utils.cast_int(row["Data2"]) }) elif data["event"] == "KeyPress": data.update({ "key_code": utils.cast_int(row["Data1"]), "key_name": row["Descriptor"] }) elif data["event"] == "LogData": data.update({"description": row["Data1"]}) all_event.append(Event(data, self.media_offset)) return all_event
def read_fixation_data(self, fixation_file): """Returns a list of "Fixation"s read from an "Fixation-Data" file. Args: fixation_file: A string containing the name of the 'Fixation-Data.tsv' file output by the Tobii software. Returns: a list of "Fixation"s """ all_fixation = [] with open(fixation_file, 'r') as f: for _ in xrange(params.FIXATIONHEADERLINES - 1): next(f) reader = csv.DictReader(f, delimiter='\t') for row in reader: data = {"fixationindex": utils.cast_int(row["FixationIndex"]), "timestamp": utils.cast_int(row["Timestamp"]), "fixationduration": utils.cast_int(row["FixationDuration"]), "fixationpointx": utils.cast_int(row["MappedFixationPointX"]), "fixationpointy": utils.cast_int(row["MappedFixationPointY"])} all_fixation.append(Fixation(data, self.media_offset)) return all_fixation