def __create_phase_lines(self, session): """ Create lines for the different phases in the session. Green ones for the start of a phase and red ones for the end. :param session: The session this phase lines should represent. :type session: Session """ config = helper.get_config(session.session_num) if config is None: return # Get all the times of all phases and creates a line for each one. for start, end in config.phase_timestamps.itervalues(): start = helper.csvtime_to_float(session.date, start) - session.start_time end = helper.csvtime_to_float(session.date, end) - session.start_time for time, color in [(start, global_values.COLOR_PHASE_GREEN), (end, global_values.COLOR_PHASE_RED)]: pos_x = (time / self.__duration) * self.__time_slider.width line_node = avg.LineNode(color=color, pos1=(pos_x, 25), pos2=(pos_x, 48), strokewidth=2, opacity=0.8, active=True, parent=self.__time_bar) self.__phase_lines[time] = line_node
def device_entry_from_csv(csv_record, date): timestamp = csvtime_to_float(date, csv_record[0]) uid = int(csv_record[1]) pos_screen = list(eval(csv_record[2])) pos_space = list(eval(csv_record[3])) orientation = list(eval(csv_record[4])) device_entry = plots.DeviceEntry(uid, pos_screen, pos_space, orientation, timestamp) return device_entry
def head_data_from_csv(csv_record, date): timestamp = csvtime_to_float(date, csv_record[0]) userid = eval(csv_record[1]) pos = list(eval(csv_record[2])) # pos is in Meters, origin is lower left corner of the wall. # In the CSV file: # If facing the wall, x points left, y up, z into the wall # In the DB: # If facing the wall, x points right, y up, z away from the wall pos[0] = -pos[0] pos[2] = -pos[2] # Rotation is yaw, pitch, roll, origin is facing wall. rotation = eval(csv_record[3]) head_data = plots.HeadData(userid, pos, rotation, timestamp) return head_data
def import_device_touches(session): print "Importing device touch data:" print " Reading csv" with open(session.data_dir + "/" + session.device_touch_filename) as f: reader = csv.reader(f) csv_data = list(reader) csv_data.pop(0) print " Processing" db_list = [] last_time = 0 for data in csv_data: print data timestamp = csvtime_to_float(session.date, data[0]) userid = int(data[1]) pos = list(eval(data[2])) t_type = data[3] if userid is None: continue touch = [ session.session_num, session.level_num, userid, pos[0], pos[1], timestamp, t_type ] if timestamp > last_time + 0.1: # New touch db_list.append(touch) # prepare for upload else: # Touch continuation touch[6] += timestamp - last_time db_list[-1] = touch last_time = touch[3] print " Writing database" con = sqlite3.connect("db") cur = con.cursor() cur.executemany( "INSERT INTO device_touch (session, level, user, x, y, time, type) VALUES (?,?,?,?,?,?,?);", db_list) con.commit() con.close()
def _read_csv_file(self, csv_path): """ Reads the csv file and saves it in an extra dict with enums. :param csv_path: The path to the csv file for the tasks. :type csv_path: str """ with open(csv_path, 'r') as f: next(f) for line in f: # Split the string in its different columns. line = line.split(", ") # Add the last column back together because it could contain , line[2] = ", ".join(line[2:]) timestamp = csvtime_to_float(line[0], line[1]) if "aid line" in line[2]: created = "created" in line[2] self.__task_data[ timestamp] = TaskTypes.AidLineCreated if created else TaskTypes.AidLineDeleted elif "lens" in line[2] and "Filter" not in line[2]: created = "created" in line[2] self.__task_data[ timestamp] = TaskTypes.LensCreated if created else TaskTypes.LensDeleted elif "Filter" in line[2]: deactivated = "deactivated" in line[2] self.__task_data[ timestamp] = TaskTypes.FilterDeactivated if deactivated else TaskTypes.FilterActivated elif "phase" in line[2]: self.__task_data[timestamp] = TaskTypes.PhaseChanged elif "block" in line[2] and "Started" in line[2]: self.__task_data[timestamp] = TaskTypes.BlockStarted elif "Checked/Unchecked" in line[2]: self.__task_data[timestamp] = TaskTypes.TaskChecked elif "tip was granted" in line[2]: self.__task_data[timestamp] = TaskTypes.TipGranted elif "reset" in line[2]: self.__task_data[timestamp] = TaskTypes.Reseted
def __init__(self, session_num, level_num, data_dir, optitrack_filename, touch_filename, device_touch_filename, device_filename, video_filenames, date, video_start_times, video_time_offset, session_time_offset, num_users, user_pitch_offsets): self.session_num = session_num self.level_num = level_num self.data_dir = data_dir self.optitrack_filename = optitrack_filename self.touch_filename = touch_filename self.device_touch_filename = device_touch_filename self.device_filename = device_filename self.video_filenames = video_filenames self.date = date self.num_users = num_users self.__session_time_offset = session_time_offset # user_pitch_offsets: The recorded pitch data is incorrect by a constant if the subjects didn't wear the # helmet correctly. self.user_pitch_offsets = user_pitch_offsets self.video_start_times = [] for video_start_time in video_start_times: self.video_start_times.append( csvtime_to_float(date, video_start_time) + video_time_offset)
distance_contents.append(content) # Look at each session. for session_id in session_ids: session = create_session(session_id) session.load_from_db() config = get_config(session_id) users = session.users phase_durations = OrderedDict() # Look at each phase. for c, (phase, phase_timestamp) in enumerate(config.phase_timestamps.iteritems()): # Calculate the duration and add it to the dict. start = csvtime_to_float(session.date, phase_timestamp[0]) - session.start_time end = csvtime_to_float(session.date, phase_timestamp[1]) - session.start_time phase_durations[phase] = end - start # Save the user distances for further use. user_session_distances[c][session_id] = OrderedDict([ (uid, [pos[1] for pos in users[uid].getHeadXZPosns(start, end)]) for uid in user_ids ]) # Get all values to calculate the statistics. touches = {uid: users[uid].getTouches(start, end) for uid in user_ids} user_positions = { uid: users[uid].getHeadXZPosns(start, end) for uid in user_ids