def test_detect_peaks(test_input, expected): df = get_data(test_input) fs = calc_fs(df) rolling_mean = calc_rolling_mean(df, 0.25, fs) num_peaks = len(detect_peaks(df, 60, rolling_mean)) minimum, maximum = expected print("fs is {}".format(fs)) print("num of peaks is {}".format(num_peaks)) assert (minimum <= num_peaks <= maximum)
def test_calc_rrsd(test_input, expected): df = get_data(test_input) fs = calc_fs(df) rolling_mean = calc_rolling_mean(df, 0.25, fs) peaks = detect_peaks(df, 100, rolling_mean) rr_list = calc_rr(df, peaks) rrsd = calc_rrsd(rr_list) minimum, maximum = expected print("rrsd is {}".format(rrsd)) assert (minimum <= rrsd <= maximum)
def test_calc_rr(test_input, expected): df = get_data(test_input) fs = calc_fs(df) rolling_mean = calc_rolling_mean(df, 0.25, fs) peaks = detect_peaks(df, 100, rolling_mean) rr_list = calc_rr(df, peaks) minimum, maximum = expected rr_list_invalid = list( filter(lambda rr: rr <= minimum or rr >= maximum, rr_list)) print("num of peaks is {}".format(len(peaks))) print("num of rr_invalid is {}".format(len(rr_list_invalid))) assert (len(rr_list_invalid) <= 5)
def get_mean_hr_bpm(test_input, expected): raw_input = input('Enter your input:') input_duration = float(raw_input) df = get_data(test_input) duration = get_duration(df) fs = calc_fs(df) rolling_mean = calc_rolling_mean(df, 0.25, fs) peaks = detect_peaks(df, 100, rolling_mean) rr_list = calc_rr(df, peaks) bpm = calc_bpm(rr_list) mean_hr_bpm = get_mean_hr_bpm(duration, bpm, input_duration) minimum, maximum = expected print("mean_hr_bpm is {}".format(mean_hr_bpm)) assert (minimum <= mean_hr_bpm <= maximum)
def test_calc_fs(test_input, expected): df = get_data(test_input) fs = calc_fs(df) assert (fs == expected)