Beispiel #1
0
def test_peak_detection(file_name, expected_num_peaks):
    test_data = importdata(file_name)
    data_valid = is_data_number(test_data)
    source = filter_data(data_valid)
    peaks = detect_peak(source)
    num_peaks = len(peaks)
    assert num_peaks <= expected_num_peaks
 def find_peaks(cls, data):
     """
     this function to detect the prak of QRS complex in the
     .. ecg data
     :param data: ecg data with time and voltage
     :return: index of peak in the ecg data
     """
     peaks = detect_peak(data)
     return peaks
def test_mean_bpm_no_user_specified(data, expected_bpm):
    peaks = detect_peak(data)
    bpm = calculate_mean_hr_bpm(data, peaks)
    assert abs(expected_bpm - bpm) <= 5
def test_mean_bpm_user_specified(data, expected_bpm, user_input):
    peaks = detect_peak(data)
    print('peaks:', peaks)
    bpm = calculate_mean_hr_bpm(data, peaks, user_input)
    assert abs(expected_bpm - bpm) <= 5
r_r_interval1 = [1.0, 1.0, 2.0, 1.5, 1.0, 1.5, 2.0, 1.5, 1.5, 2.0]
r_r_interval2 = [2.0, 2.0, 2.0, 2.0, 1.0, 2.5, 2.5, 1.0]
fs = 8000
ecg = signal.wavelets.daub(10)
signal1 = numpy.concatenate(
    [signal.resample(ecg, int(r * fs)) for r in r_r_interval1])
signal2 = numpy.concatenate(
    [signal.resample(ecg, int(r * fs)) for r in r_r_interval2])
t1 = numpy.arange(len(signal1)) / fs
t2 = numpy.arange(len(signal2)) / fs
d1 = {'time': t1, 'voltage': signal1}
df1 = pd.DataFrame(data=d1)
d2 = {'time': t2, 'voltage': signal2}
df2 = pd.DataFrame(data=d2)
peaks1 = detect_peak(df1)
peaks2 = detect_peak(df2)
num_beats1 = len(peaks1)
num_beats2 = len(peaks2)
expected_beats1 = [df1['time'].iloc[peaks1[0]], df1['time'].iloc[peaks1[-1]]]
expected_beats2 = [df2['time'].iloc[peaks2[0]], df2['time'].iloc[peaks2[-1]]]


@pytest.mark.parametrize("data, peaks, expected_num_beats, expected_beats", [
    (df1, peaks1, num_beats1, expected_beats1),
    (df2, peaks2, num_beats2, expected_beats2)

])
def test_peak_detection(data, peaks, expected_num_beats, expected_beats):
    num_beats, beats = calculate_number_beats_and_bests(data, peaks)
    print(beats)