Beispiel #1
0
def get_brushing_features_and_labels_for_pid_daywise(pid, sid, mbrushing_segmentList, sBrushing_segmentList=None):
    cur_dir = sensor_data_dir + pid + '/' + sid + '/'

    left_ori, right_ori, is_new_device = get_orientations_and_device_info(pid, sid)

    X_brush, Y_brush = [], []

    AGMO_r = get_accel_gyro_mag_orientation(cur_dir, RIGHT_WRIST, right_ori, is_new_device=is_new_device)
    if len(AGMO_r) > 0:
        cand_r = generate_candidates(AGMO_r)
        cand_r = filter_for_brushing(cand_r, AGMO_r)
        if len(cand_r) > 0:
            Xs = generate_all_window_and_compute_brushing_features(pid, sid, AGMO_r, cand_r, wrist=RIGHT_WRIST)
            Ys = get_manual_brushing_labels(list(Xs), mbrushing_segmentList, sBrushing_segmentList, wrist=RIGHT_WRIST)
            X_brush.extend(Xs)
            Y_brush.extend(Ys)
    else:
        print('---------DATA MISSING----', pid, sid, '#right', len(AGMO_r))
    AGMO_l = get_accel_gyro_mag_orientation(cur_dir, LEFT_WRIST, left_ori, is_new_device=is_new_device)
    if len(AGMO_l) > 0:
        cand_l = generate_candidates(AGMO_l)
        cand_l = filter_for_brushing(cand_l, AGMO_l)
        if len(cand_l) > 0:
            Xs = generate_all_window_and_compute_brushing_features(pid, sid, AGMO_l, cand_l, wrist=LEFT_WRIST)
            Ys = get_manual_brushing_labels(list(Xs), mbrushing_segmentList, sBrushing_segmentList, wrist=LEFT_WRIST)
            X_brush.extend(Xs)
            Y_brush.extend(Ys)
    else:
        print('---------DATA MISSING----', pid, sid, '#left', len(AGMO_l))
    print('Done for', pid, sid, 'Orientations:', left_ori, right_ori, is_new_device, '#pos:',
          len([v for v in Y_brush if v == 1]), 'total', len(Y_brush))
    return X_brush, Y_brush
Beispiel #2
0
def get_brushing_features_for_pid_day(pid, sid):
    cur_dir = sensor_data_dir + pid + '/' + sid + '/'

    left_ori, right_ori, is_new_device = get_orientations_and_device_info(pid, sid)

    X_brush = [], []

    AGMO_r = get_accel_gyro_mag_orientation(cur_dir, RIGHT_WRIST, right_ori, is_new_device=is_new_device)
    if len(AGMO_r) > 0:
        cand_r = generate_candidates(AGMO_r)
        cand_r = filter_for_brushing(cand_r, AGMO_r)
        if len(cand_r) > 0:
            Xs = generate_all_window_and_compute_brushing_features(pid, sid, AGMO_r, cand_r, wrist=RIGHT_WRIST)
            X_brush.extend(Xs)
    else:
        print('---------DATA MISSING----', pid, sid, '#right', len(AGMO_r))
    AGMO_l = get_accel_gyro_mag_orientation(cur_dir, LEFT_WRIST, left_ori, is_new_device=is_new_device)
    if len(AGMO_l) > 0:
        cand_l = generate_candidates(AGMO_l)
        cand_l = filter_for_brushing(cand_l, AGMO_l)
        if len(cand_l) > 0:
            Xs = generate_all_window_and_compute_brushing_features(pid, sid, AGMO_l, cand_l, wrist=LEFT_WRIST)
            X_brush.extend(Xs)
    else:
        print('---------DATA MISSING----', pid, sid, '#left', len(AGMO_l))
    print('Done for', pid, sid, 'total', len(X_brush))
    return X_brush
def process_pid_sid_negative_classes(pid, sid, mbrushing_segmentList,
                                     stringFlossing_segmentList):
    cur_dir = data_dir + pid + '/' + sid + '/'

    left_ori, right_ori, is_new_device = get_orientations_and_device_info(
        pid, sid)

    AGMO_r = get_accel_gyro_mag_orientation(cur_dir,
                                            RIGHT_WRIST,
                                            right_ori,
                                            is_new_device=is_new_device)
    AGMO_l = get_accel_gyro_mag_orientation(cur_dir,
                                            LEFT_WRIST,
                                            left_ori,
                                            is_new_device=is_new_device)

    if len(AGMO_l) == 0 or len(AGMO_r) == 0:
        print('---------DATA MISSING----', pid, sid, '#left', len(AGMO_l),
              '#right', len(AGMO_r))
        return [], [], [], []

    AGMO_l = aline_datastream(AGMO_l, [v[0] for v in AGMO_r])
    cand_l = generate_candidates(AGMO_l)
    cand_r = generate_candidates(AGMO_r)

    cand_l = filter_for_brushing(cand_l, AGMO_l)
    cand_r = filter_for_brushing(cand_r, AGMO_r)

    cands = combine_left_right(cand_l, cand_r)

    # if len(cand_l) > 0:
    #     X_left = generate_all_window_and_compute_brushing_features(pid, sid, AGMO_l, cand_l)
    #     X_df_left = pd.DataFrame(np.array(X_left), columns=featurenames)
    if len(cand_r) > 0:
        X_brush = generate_all_window_and_compute_brushing_features(
            pid, sid, AGMO_r, cand_r)
        Y_brush = get_manual_brushing_labels(list(X_brush),
                                             mbrushing_segmentList)
    else:
        X_brush, Y_brush = [], []

    if len(cands) > 0:
        X_floss = generate_all_window_and_compute_flossing_features(
            pid, sid, AGMO_l, AGMO_r, cands)
        Y_floss = get_flossing_labels(list(X_floss),
                                      stringFlossing_segmentList)
    else:
        X_floss, Y_floss = [], []

    return list(X_brush), list(Y_brush), list(X_floss), list(Y_floss)
def do_proccess_plot_candidates_for_positive_brushing_event(pids):
    duration_outputs = []

    M_brush_with, M_floss_with, M_ori_left, M_ori_right, M_wrist, M_is_new_device = get_event_configurations(
    )
    # pids = ['9a6b']
    for pid in pids:

        print('start')
        event_keys = [
            d for d in os.listdir(pos_event_input_data_dir)
            if os.path.isdir(os.path.join(pos_event_input_data_dir, d))
            and d.startswith(pid)
        ]
        event_keys.sort()
        # print(pids)
        for event_key in event_keys:
            if 'plots' in event_key or event_key.endswith('20181202_084726'):
                continue
            if len(event_key) > 20:
                continue
            # if event_key in ['024_20181202_084726']:
            #     continue

            # basedir = pos_event_input_data_dir + event_key + '/'
            basedir = new_pos_event_input_data_dir + event_key + '/'
            # print('-----', basedir)
            if M_brush_with[event_key] != MANUAL_BRUSHING:
                continue

            annotation_filename = event_key + '.csv'
            AD = get_label_annotations(annotation_filename)
            if AD is None:
                print('---------ANNOTATION MISSING----', event_key)
                continue
            right_ori = M_ori_right[event_key]
            AGMO_r = get_accel_gyro_mag_orientation(
                basedir,
                RIGHT_WRIST,
                right_ori,
                is_new_device=M_is_new_device[event_key])

            if len(AGMO_r) == 0:
                print('---------DATA MISSING----', event_key, '#right',
                      len(AGMO_r))
                continue
            # print('>>>>', AD['start_timestamp'][0], AGMO_r[0][0])

            cand_r = generate_candidates(AGMO_r)
            # do_plotting(AGMO_r, AD, event_key, cand_r)
            cand_r = filter_for_brushing(cand_r, AGMO_r)
            # cand_r = get_only_brushing_candidates(AGMO_r, cand_r, event_key)

            do_plotting(AGMO_r, AD, event_key, cand_r, output_dir=basedir)
def do_proccess_positive_brushing_event_data_and_generate_featutes(pids):
    featurenames_brushing = create_featurenames_for_brushing()

    duration_outputs = []

    M_brush_with, M_floss_with, M_ori_left, M_ori_right, M_wrist, M_is_new_device = get_event_configurations(
    )
    # pids = ['9a6b']
    for pid in pids:

        print('start')
        mbrushing_segmentList, sBrushing_segmentList, stringFlossing_segmentList = get_brushing_flossing_segments(
            pid)

        event_keys = [
            d for d in os.listdir(pos_event_input_data_dir)
            if os.path.isdir(os.path.join(pos_event_input_data_dir, d))
            and d.startswith(pid)
        ]
        event_keys.sort()
        # print(pids)
        XX = []
        YY = []
        for event_key in event_keys:
            if 'plots' in event_key or event_key.endswith('20181202_084726'):
                continue
            if len(event_key) > 20:
                continue
            # if event_key in ['024_20181202_084726']:
            #     continue

            basedir = pos_event_input_data_dir + event_key + '/'
            # print('-----', basedir)
            if M_brush_with[event_key] != MANUAL_BRUSHING:
                continue

            annotation_filename = event_key + '.csv'
            AD = get_label_annotations(annotation_filename)
            if AD is None:
                print('---------ANNOTATION MISSING----', event_key)
                continue
            right_ori = M_ori_right[event_key]
            AGMO_r = get_accel_gyro_mag_orientation(
                basedir,
                RIGHT_WRIST,
                right_ori,
                is_new_device=M_is_new_device[event_key])

            if len(AGMO_r) == 0:
                print('---------DATA MISSING----', event_key, '#right',
                      len(AGMO_r))
                continue
            # print('>>>>', AD['start_timestamp'][0], AGMO_r[0][0])

            cand_r = generate_candidates(AGMO_r)
            # do_plotting(AGMO_r, AD, event_key, cand_r)
            cand_r = filter_for_brushing(cand_r, AGMO_r)
            # cand_r = get_only_brushing_candidates(AGMO_r, cand_r, event_key)

            do_plotting(AGMO_r, AD, event_key, cand_r)
            X_brush = generate_all_window_and_compute_brushing_features(
                pid, event_key, AGMO_r, cand_r)
            Y_brush = get_manual_brushing_labels(list(X_brush),
                                                 mbrushing_segmentList)

            X_brush1 = [x for i, x in enumerate(X_brush) if Y_brush[i] == 1]
            Y_brush1 = [y for y in Y_brush if y == 1]

            output_filename = event_key + '_XY1.csv'
            if len(Y_brush1) > 0:
                duration_outputs.extend([[pid, event_key, x[4]]
                                         for x in X_brush1])
                print(event_key, '#ofPos', len(Y_brush1), len(Y_brush))
                XX.extend(X_brush1)
                YY.extend(Y_brush1)
                save_as_csv(X_brush1,
                            Y_brush1,
                            featurenames_brushing,
                            output_brushing_feature_dir,
                            output_filename=output_filename)
            # do_plotting(AGMO_r, AGMO_l, AD, event_key, cand_l, cand_r, cands)
            else:
                print('--------------------NO candidate generated for ',
                      event_key, len(Y_brush1), len(Y_brush))

        print('PID TOTAL ----->', pid, '#of windows', len(list(XX)),
              '#of only brushing', len([v for v in YY if v == 1]))
        if len(YY) > 0:
            save_as_csv(XX,
                        YY,
                        featurenames_brushing,
                        output_brushing_feature_dir,
                        output_filename=pid + '_XY1.csv')

    data = np.array(duration_outputs)
    pd_data = pd.DataFrame(data=data,
                           columns=['pid', 'event_key', 'dur_brushing'])

    pd_data.to_csv(sensor_data_dir + 'brushing_candidate_durations.csv',
                   encoding='utf-8',
                   index=False)