def load_sensor_data_and_labels_by_name(record_dir, type_name='accel', inference=False): print(f'\nProcessing record dir: {record_dir}') if type_name == 'accel': suffix = ACC_SUFFIX elif type_name == 'gyro': suffix = GYRO_SUFFIX elif type_name == 'magnet': suffix = MAGNET_SUFFIX else: raise ValueError(f'Unsupport type name: {type_name}') # Load data and split ts out data_file = record_dir / f'{record_dir.name}-{suffix}' if not data_file.exists(): Log.e(f'Record has no {type_name} data, do nothing') return None, None, None data_all = pd.read_csv(data_file) data_all = data_all[:-1] # Remove the last line, maybe one broken line data_ts, data = split_ts_and_data(data_all) # Fitler outliner print(f'Origing raw data shape: {data.shape}') exception_point_process(data.T[0], inplace=True) exception_point_process(data.T[1], inplace=True) exception_point_process(data.T[2], inplace=True) # Low pass data_lp = signal.filtfilt(FILTER_B, FILTER_A, data, axis=0) data = np.hstack((data, data_lp)) # To get the data labels label_file = record_dir / f'{record_dir.name}-{LABEL_SUFFIX}' if label_file.exists(): labels_ts = load_label_result(label_file) labels = label_convert_ts2index(labels_ts, data_ts) else: if inference: Log.i('Label file not exists, Using activity type name Infer.') activity_type_name = get_activity_type_name_by_file_name( record_dir.name) is_daily = activity_type_name in LABEL_DAILY is_other_sports = activity_type_name in LABEL_OTHER_SPORTS if is_daily or is_other_sports: if is_daily: activity_type_name_as = 'DailyActivity' else: activity_type_name_as = 'OtherSports' activity_type = LABEL_ITEMS_INDEX_DICT.get( activity_type_name_as) print( f'Treat {activity_type_name} as {activity_type_name_as}: {activity_type}' ) labels = [(activity_type, 0, data.shape[0])] else: labels = None else: Log.w( 'Label file not exists, Inference by activity type name disabled. Skipped!' ) labels = None return data_ts, data, labels