Exemple #1
0
def test_pickImportData():
    from pickImportData import PickImportData
    import pandas as pd
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    assert type(testClass.outPutArray) == pd.core.frame.DataFrame
def test_max_min_volts_time_dur():
    from pickImportData import PickImportData
    from max_min_volts_time_dur import MaxMinVoltsTimeDur
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    testClassMaxMin = MaxMinVoltsTimeDur(testClass.outPutArray)
    assert testClassMaxMin.tuple_min_max_volts == (1.05, -0.68)
    assert testClassMaxMin.max_time_strip == 27.775
Exemple #3
0
def test_correctExcp():
    from pickImportData import PickImportData
    import pytest
    with pytest.raises(ImportError, message="Expecting ImportError"):
        import randomFunc
    with pytest.raises(ValueError, message="Expecting ValueError"):
        testClass2 = PickImportData()
        testClass2.FilePath = "requirements.txt"
        testClass2.ImportFile()
def test_correctExcp():
    from pickImportData import PickImportData
    from max_min_volts_time_dur import MaxMinVoltsTimeDur
    from cleanData import cleanData
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    testClassMaxMin2 = MaxMinVoltsTimeDur(testClass.outPutArray)
    import pytest
    with pytest.raises(ImportError, message="Expecting ImportError"):
        import randomFunc
    with pytest.raises(AttributeError, message="Expecting AttributeError"):
        voltageList, timeList = cleanData(2)
def test_json_output():
    from pickImportData import PickImportData
    from max_min_volts_time_dur import MaxMinVoltsTimeDur
    from meanBPM import MeanBPM
    from json_output import Json_Output
    import os
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    testClassBPM = MeanBPM(testClass.outPutArray)
    testClassBPM.get_mean_bpm()
    testClassBPM.convert_beat_times_list_to_np_array()
    testClassmm = MaxMinVoltsTimeDur(testClass.outPutArray)
    testJSONclass = Json_Output(testClass.FilePath, max(testClassBPM.timeList),
                                testClassBPM.timeUnit, testClassBPM.meanBPM,
                                testClassBPM.num_beat_times,
                                testClassBPM.beatTimes,
                                testClassmm.tuple_min_max_volts,
                                testClassmm.max_time_strip)
    test_data = {
        "time_range":
        27.775,
        "max_time":
        27.775,
        "times_of_beats": [
            0.6809999999999999, 1.492, 2.281, 3.072, 3.861, 4.678, 5.331,
            6.327999999999999, 7.169, 7.978, 8.769, 9.542, 10.380999999999998,
            11.235999999999999, 12.058, 12.886, 13.708, 14.503, 15.3, 16.092,
            16.914, 17.783, 18.605999999999998, 19.392, 20.183,
            20.958000000000002, 21.744, 22.555999999999997, 23.372, 24.2,
            25.044, 25.85, 26.625
        ],
        "max_min_volt": (1.05, -0.68),
        "mean_BPM":
        74.006,
        "time_unit":
        "s",
        "number_of_beats":
        33
    }
    assert testJSONclass.data["time_range"] == test_data["time_range"]
    assert testJSONclass.data["max_time"] == test_data["max_time"]
    assert testJSONclass.data["times_of_beats"] == test_data["times_of_beats"]
    assert testJSONclass.data["max_min_volt"] == test_data["max_min_volt"]
    assert testJSONclass.data["mean_BPM"] == test_data["mean_BPM"]
    assert testJSONclass.data["time_unit"] == test_data["time_unit"]
    string1 = "number_of_beats"
    assert testJSONclass.data["number_of_beats"] == test_data[string1]
    new_filename = str(testClass.FilePath).replace(".csv", "") + ".json"
    cf = os.path.isfile(new_filename)
    assert cf is True
Exemple #6
0
def test_meanBPM():
    from pickImportData import PickImportData
    from meanBPM import MeanBPM
    import numpy as np
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    testClassBPM = MeanBPM(testClass.outPutArray)
    testClassBPM.get_mean_bpm()
    testClassBPM.convert_beat_times_list_to_np_array()
    assert testClassBPM.meanBPM == 74.006
    x = [
        0.6809999999999999, 1.492, 2.281, 3.072, 3.861, 4.678, 5.331,
        6.327999999999999, 7.169, 7.978, 8.769, 9.542, 10.380999999999998,
        11.235999999999999, 12.058, 12.886, 13.708, 14.503, 15.3, 16.092,
        16.914, 17.783, 18.605999999999998, 19.392, 20.183, 20.958000000000002,
        21.744, 22.555999999999997, 23.372, 24.2, 25.044, 25.85, 26.625
    ]
    assert testClassBPM.beatTimes == x
    xn = np.array(x)
    assert np.array_equal(testClassBPM.np_beat_times, xn) is True
    testClassAb = PickImportData()
    testClassAb.FilePath = "test_data1.csv"
    testClassAb.ImportFile()
    testClassBPMAb = MeanBPM(testClass.outPutArray, 20, "ms")
    testClassBPMAb.get_mean_bpm()
    testClassBPMAb.convert_beat_times_list_to_np_array()
    assert testClassBPMAb.meanBPM == 73753.407
Exemple #7
0
def test_cleanData():
    import pandas as pd
    from cleanData import cleanData
    import math as mt
    from pickImportData import PickImportData
    testClass = PickImportData()
    testClass.FilePath = "test_data30.csv"
    testClass.ImportFile()
    voltage, time = cleanData(testClass.outPutArray)
    for i in range(len(voltage)):
        assert isinstance(voltage[i], float) is True
        assert isinstance(time[i], float) is True
        assert mt.isnan(voltage[i]) is False
        assert mt.isnan(time[i]) is False
    for i in range(1, len(time)):
        assert time[i] != 0
    assert len(voltage) == 10000
Exemple #8
0
def main():
    """"function that combines all of the previous classes (PickImportData,
    MultiPickAndImportData, MeanBPM, MaxMinVoltsTimeDur, Json_Output) to
    convert a csv raw ECG data file to a json file with variables
    1. Mean BPM over time range.
    2. Tuple for maximum voltage and minimum voltage in ECG strip.
    3. Number of beat events detected.
    4. List of times of each beat event (also converted to numpy array
    if needed).
    5. Maximum Time on ECG strip.
    6. User input time range for analysis.
    7. User input time units (eg. seconds or minutes).
    8. Name of the csv file.

    :param x: corresponds to time range over which the analysis is done
    :param y:  corresponds to the time unit of the ECG test
    :param z: corresponds to the type of test to run. Multi file or single
              pick
    :returns: json file with the same name as the ECG csv file
    """
    args = parse_cli()
    x = args.x
    y = args.y
    z = args.z

    if z != "m":
        from pickImportData import PickImportData
        from meanBPM import MeanBPM
        from max_min_volts_time_dur import MaxMinVoltsTimeDur
        from json_output import Json_Output
        runSingleClass = PickImportData()
        runSingleClass.PickFile()
        runSingleClass.ImportFile()
        runSingleClassBPM = MeanBPM(runSingleClass.outPutArray, x, y)
        runSingleClassBPM.get_mean_bpm()
        runSingleClassBPM.convert_beat_times_list_to_np_array()
        runSingleClassBPM.detect_abnormal_heart_rate()
        runSingleClassMM = MaxMinVoltsTimeDur(runSingleClass.outPutArray)
        runSingleClassJSON = Json_Output(runSingleClass.FilePath,
                                         runSingleClassBPM.timeRange, y,
                                         runSingleClassBPM.meanBPM,
                                         runSingleClassBPM.num_beat_times,
                                         runSingleClassBPM.beatTimes,
                                         runSingleClassMM.tuple_min_max_volts,
                                         runSingleClassMM.max_time_strip)
    else:
        from multiPickAndImportData import MultiPickAndImportData
        from meanBPM import MeanBPM
        from max_min_volts_time_dur import MaxMinVoltsTimeDur
        from json_output import Json_Output
        runMultiClass = MultiPickAndImportData()
        for i in range(len(runMultiClass.dfList)):
            print(runMultiClass.superList[i])
            df = runMultiClass.dfList[i]
            runMultiClassBPM = MeanBPM(df, x, y)
            runMultiClassBPM.get_mean_bpm()
            runMultiClassBPM.convert_beat_times_list_to_np_array()
            runMultiClassBPM.detect_abnormal_heart_rate()
            runMultClassMM = MaxMinVoltsTimeDur(df)
            runMultiClassJSON = Json_Output(runMultiClass.superList[i],
                                            runMultiClassBPM.timeRange, y,
                                            runMultiClassBPM.meanBPM,
                                            runMultiClassBPM.num_beat_times,
                                            runMultiClassBPM.beatTimes,
                                            runMultClassMM.tuple_min_max_volts,
                                            runMultClassMM.max_time_strip)
Exemple #9
0
def test_correctExcp():
    from pickImportData import PickImportData
    from meanBPM import MeanBPM
    import numpy as np
    import pandas as pd
    from cleanData import cleanData
    testClass = PickImportData()
    testClass.FilePath = "test_data1.csv"
    testClass.ImportFile()
    testClassBPM = MeanBPM(testClass.outPutArray)
    testClassBPM.get_mean_bpm()
    testClassBPM.convert_beat_times_list_to_np_array()
    import pytest
    with pytest.raises(ImportError, message="Expecting ImportError"):
        import randomFunc
    with pytest.raises(FileNotFoundError,
                       message="Expecting \
                       FileNotFoundError"):
        standFilePath = "standardPatter.csv"
        sdf = pd.read_csv(standFilePath, header=None)
    with pytest.raises(AttributeError, message="Expecting AttributeError"):
        voltageList, timeList = cleanData(2)
    with pytest.raises(IndexError, message="Expecting IndexError"):
        testClass2 = PickImportData()
        testClass2.FilePath = "test_data1.csv"
        testClass2.ImportFile()
        testClassBPM2 = MeanBPM(testClass.outPutArray, 200)
    with pytest.raises(ValueError, message="Expecting ValueError"):
        testClass3 = PickImportData()
        testClass3.FilePath = "test_data1.csv"
        testClass3.ImportFile()
        testClassBPM3 = MeanBPM(testClass.outPutArray, -8)
    with pytest.raises(IndexError,
                       message="Expecting IndexError. \
                       Too many heartbeats found over interval."):
        testClass4 = PickImportData()
        testClass4.FilePath = "test_data1.csv"
        testClass4.ImportFile()
        testClassBPM4 = MeanBPM(testClass4.outPutArray, 0.5)