def test_file_source_recent_events(): ''' recent_events setup correct or not ''' file_source = File_Source(Empty(), source_path=single_data, timing="external") assert file_source.recent_events == file_source.recent_events_external_timing file_source = File_Source(Empty(), source_path=single_data, timing=None) assert file_source.recent_events == file_source.recent_events_own_timing
def test_file_source_recent_events(): """ recent_events setup correct or not """ file_source = File_Source( SimpleNamespace(), source_path=single_data, timing="external" ) assert file_source.recent_events == file_source.recent_events_external_timing file_source = File_Source(SimpleNamespace(), source_path=single_data, timing=None) assert file_source.recent_events == file_source.recent_events_own_timing
def _copy_info_csv(source_folder, destination_folder): # TODO: The iMotions export still relies on the old-style info.csv, so we have to # generate this here manually. We should clarify with iMotions whether we can update # this to our new recording format. recording = PupilRecording(source_folder) meta = recording.meta_info # NOTE: This is potentially incorrect, since we don't know the timezone. But we are # keeping this format for backwards compatibility with the old-style info.csv. start_datetime = datetime.datetime.fromtimestamp(meta.start_time_system_s) start_date = start_datetime.strftime("%d.%m.%Y") start_time = start_datetime.strftime("%H:%M:%S") duration_full_s = meta.duration_s duration_h = int(duration_full_s // 3600) duration_m = int((duration_full_s % 3600) // 60) duration_s = int(round(duration_full_s % 3600 % 60)) duration_time = f"{duration_h:02}:{duration_m:02}:{duration_s:02}" try: world_video = recording.files().core().world().videos()[0] except IndexError: logger.error( "Error while exporting iMotions data. World video not found!") return cap = File_Source(SimpleNamespace(), world_video) world_frames = cap.get_frame_count() world_resolution = f"{cap.frame_size[0]}x{cap.frame_size[1]}" data = {} data["Recording Name"] = meta.recording_name data["Start Date"] = start_date data["Start Time"] = start_time data["Start Time (System)"] = meta.start_time_system_s data["Start Time (Synced)"] = meta.start_time_synced_s data["Recording UUID"] = str(meta.recording_uuid) data["Duration Time"] = duration_time data["World Camera Frames"] = world_frames data["World Camera Resolution"] = world_resolution data["Capture Software Version"] = meta.recording_software_version data["Data Format Version"] = str(meta.min_player_version) data["System Info"] = meta.system_info info_dest = os.path.join(destination_folder, "iMotions_info.csv") with open(info_dest, "w", newline="", encoding="utf-8") as f: csv_utils.write_key_value_file(f, data)
def generate_frames(g_pool): recording = PupilRecording(g_pool.rec_dir) video_path = recording.files().world().videos()[0] fs = File_Source(g_pool, source_path=video_path, fill_gaps=True) total_frame_count = fs.get_frame_count() while True: try: current_frame = fs.get_frame() except EndofVideoError: break progress = current_frame.index / total_frame_count yield progress, current_frame
def test_file_source_not_source_path(caplog): """ Failed if we don't pass source_path to file_source """ caplog.set_level(logging.INFO) with pytest.raises(AssertionError) as excinfo: _ = File_Source(SimpleNamespace()) assert "Init failed. Source file could not be found at" in caplog.text
def test_file_source_not_source_path(caplog): ''' Failed if we don't pass source_path to file_source ''' caplog.set_level(logging.INFO) with pytest.raises(AssertionError) as excinfo: _ = File_Source(Empty()) assert ("Init failed. Source file could not be found at" in caplog.text)
def _generate_all_lookup_tables(rec_dir: str): recording = PupilRecording(rec_dir) videosets = [ recording.files().core().world().videos(), recording.files().core().eye0().videos(), recording.files().core().eye1().videos(), ] for videos in videosets: if not videos: continue File_Source( SimpleNamespace(), source_path=videos[0], fill_gaps=True, timing=None )
def broken_fill_gaps(): """Returns broken data""" return File_Source(SimpleNamespace(), source_path=broken_data)
def multiple_fill_gaps(): """Returns multiple data""" return File_Source(SimpleNamespace(), source_path=multiple_data, fill_gaps=True)
def single_fill_gaps(): """Returns single data""" return File_Source(SimpleNamespace(), source_path=single_data, fill_gaps=True)
def broken_fill_gaps(): '''Returns broken data''' return File_Source(Empty(), source_path=broken_data)
def multiple_fill_gaps(): '''Returns multiple data''' return File_Source(Empty(), source_path=multiple_data, fill_gaps=True)
def single_fill_gaps(): '''Returns single data''' return File_Source(Empty(), source_path=single_data, fill_gaps=True)