Пример #1
0
def test_dataapi():
	start = 1502153929861
	end = start + 10000
	df = get_necklace('P108', start, end)

	assert ((df.Time >= start).all() and (df.Time <= end).all())

	assert_monotonic(df.Time.as_matrix())
Пример #2
0
N = df_segments.shape[0]

start_time = time.time()

for i in range(N):
    if i % 1000 == 1:
        print("Sample {}, elapsed {}".format(i, time.time() - start_time))
        feature = pd.concat(list_total_feature)
        feature.to_csv('feature_P120.csv', index=None)

    start = datetime_to_epoch(df_segments['start'][i])
    end = datetime_to_epoch(df_segments['end'][i])

    try:
        df = get_necklace('P120', start, end, reliability=0.01)
        f = get_feature(df)

        f['start'] = df_segments['start'][i]
        f['end'] = df_segments['end'][i]
        f['pmin'] = df_segments['pmin'][i]
        f['pmax'] = df_segments['pmax'][i]
        f['eps'] = df_segments['eps'][i]
        f['length'] = df_segments['length'][i]
        f['hour'] = df_segments['start'][i].hour
        f['label'] = df_segments['chewing_gt'][i]
        f['date_exp'] = df_segments['date_exp'][i]

        list_total_feature.append(f)

    except ValueError:
label_bite_path = "{}/{}/visualize/SYNC/{}/labelbites.json".format(
    settings.CLEAN_FOLDER, subj, meal)

label_bite_dict, bite_epoch, bite_chewing_count = read_label_bite(
    label_bite_path)

# create bite ranges (skip the range starting at 'e')
bite_ranges = []
b_previous = None

tmp = list(zip(bite_epoch, bite_epoch[1:]))
for interval, c in zip(tmp, bite_chewing_count):
    if not 'e' in c:
        bite_ranges.append(interval)

df = get_necklace(subj, bite_ranges[0][0], bite_ranges[-1][1])

peaks_index = peak_detection(df['proximity'], min_prominence=2)
peaks_time = df.index[peaks_index]

peaks_epoch = np.array([datetime_to_epoch(p) for p in peaks_time])

# calculating number of prominent peaks per bite
for b1, b2 in bite_ranges:
    print(b1)
    print(b2)
    count = len(np.where((peaks_epoch >= b1) & (peaks_epoch < b2))[0])

    print(count)
chewing_rate_list = []
chewing_rate_std_list = []

for m in valid_meals:

    # get chewing groundtruth
    gt = read_SYNC("{}/{}/visualize/SYNC/{}/labelchewing.json".format(
        settings.CLEAN_FOLDER, subj, m))

    print(gt)

    rate_list = []
    rate_std_list = []
    for i in range(gt.shape[0]):
        df = get_necklace(subj, datetime_to_epoch(gt['start'].iloc[i]),
                          datetime_to_epoch(gt['end'].iloc[i]))

        print(df.shape)

        if df.empty or df.shape[0] < 3:
            print("EMPTY DATAFRAME, DOUBLE CHECK!!!")
            continue

        rate, rate_std = get_chewing_rate(df)

        rate_list.append(rate)
        rate_std_list.append(rate_std)

    chewing_rate_list.append(np.mean(np.array(rate_list)))
    chewing_rate_std_list.append(np.mean(np.array(rate_std_list)))