示例#1
0
def main():
    """
    This is the main function

    Returns:
        None
    """
    import hbAnalysis as hb  # Assuming we named the file 'heartbeat.py'
    import filehander
    import json
    from jsonEncoder import NumpyAwareJSONEncoder

    # get data
    filename = filehander.open_file_dialog()
    df = hb.get_data(filename)

    # Todo: clean the data

    # signal processing
    # calc interested info using the chosen data, and store in metrics
    hb.process(df, metrics)

    # plot the interested value
    plotter(df, "test_data1")

    # store the interested value into file
    j = json.dumps(metrics, cls=NumpyAwareJSONEncoder)
    f = open("data.json", "w")
    f.write(j)
    f.close()
示例#2
0
def get_num_beats(test_input, expected):
    df = get_data(test_input)
    peaks, _ = fit_peaks(df)
    beats = get_beats(df, peaks)
    num_beats = get_num_beats(beats)
    minimum, maximum = expected
    print("num of beats is {}".format(num_beats))
    assert (minimum <= num_beats <= maximum)
示例#3
0
def test_fit_peaks(test_input, expected):
    df = get_data(test_input)
    peaks, w_best = fit_peaks(df)
    num_peaks = len(peaks)
    minimum, maximum = expected
    print("num of peaks is {}".format(num_peaks))
    print("best weight is {}".format(w_best))
    assert (minimum <= num_peaks <= maximum)
示例#4
0
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)
示例#5
0
def test_calc_rolling_mean(test_input, expected):
    df = get_data(test_input)
    hrw = 1
    fs = 2
    rolling_mean = calc_rolling_mean(df, hrw, fs)
    print("rolling_mean is :{}".format(rolling_mean))
    is_close = np.std(np.array(rolling_mean) - np.array(expected))
    print("isClose is :{}".format(is_close))
    assert (is_close <= 0.001)
示例#6
0
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)
示例#7
0
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)
示例#8
0
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)
示例#9
0
def test_calc_fs(test_input, expected):
    df = get_data(test_input)
    fs = calc_fs(df)
    assert (fs == expected)
示例#10
0
def test_get_voltage_extremes(test_input, expected):
    df = get_data(test_input)
    extremes = get_voltage_extremes(df)
    assert (extremes == expected)
示例#11
0
def test_get_duration(test_input, expected):
    df = get_data(test_input)
    duration = get_duration(df)
    assert (duration == expected)
示例#12
0
def test_get_data(test_input, expected):
    df = get_data(test_input)
    assert (list(df.time) == expected)