def hrmonitor(filepath, output_name): """ :param filepath: ECG data location :param output_name : Output file name :return: .txt file all calculated outputs """ # Importing csv data data = opencsv(filepath) # Update path or add file to root folder time = data['time'] voltage = data['voltage'] # Instantaneous heart rate that updates every 5s maxpeaks = find_max_peaks(voltage, time, update_time=5) instantaneoushr = inst_hr(maxpeaks, update_time=5) # Average heart rate # mins = float(input('Please specify a time (in min) for averaging.')) newhrset = new_hr_set(mins, instantaneoushr, update_time=5) avghr = avg_hr(newhrset[0]) # Brady/Tachycardia condition = bradtach(avghr, mins) message = condition[1] # Output Information in .txt File HRinfo = open('{}_HR_Information.txt'.format(output_name), 'w') HRinfo.write("Estimated Instantaneous HR is {} beats per minute.".format( instantaneoushr)) HRinfo.write( "/nEstimated Average HR is {} beats per minute in minutes/n".format( avghr, mins)) HRinfo.write("/n{}/n".format(message))
def test_groupnum_equaltodata(): """ Tests when user inputs a time equal to data set """ mins = 0.5 rawbunches = [60, 70, 65, 68, 71, 68] update_time = 5 testinputequal = new_hr_set(mins, rawbunches, update_time) assert testinputequal[0] == rawbunches
def test_longmin(): """ Checking a larger user input, as well as a user input of type 'int' """ minlong = 132 rawbunches = [80, 79, 85, 90, 77, 73] update_time = 5 testgrouplong = new_hr_set(minlong, rawbunches, update_time) assert testgrouplong[1] == 1584
def test_new_hr_set_equal(): """ Checks for when user input exists in set for half a minute (300 sec) """ mins = 0.5 rawbunches = [80, 79, 85, 90, 77, 73] update_time = 5 testgroup = new_hr_set(mins, rawbunches, update_time) assert testgroup[1] == 6
def test_groupnum_greaterthan_data(): """ This tests when user inputs a time greater than the data set allows """ mins = 5 # User input 5 minutes # Data set only has bunches for 50 sec rawbunches = [65, 70, 68, 77, 74, 68, 64, 65, 64, 78] update_time = 5 testinputgreater = new_hr_set(mins, rawbunches, update_time) assert testinputgreater[0] == rawbunches
def test_new_hr_set_between(): """ Checks for when user input is not divisible by predetermined window (e.g. 0.67 min) """ min2 = 0.67 rawbunches = [80, 79, 85, 90, 77, 73] update_time = 5 testgroup2 = new_hr_set(min2, rawbunches, update_time) assert testgroup2[1] == 9
def test_groupnum_lessthandata(): """ Tests when input is less than data set """ mins = 0.5 # 30 sec input # Minute worth of data rawbunches = [60, 70, 65, 68, 71, 68, 66, 65, 73, 69, 66, 62] update_time = 5 testinputless = new_hr_set(mins, rawbunches, update_time) # Output should be half a min assert testinputless[0] == [60, 70, 65, 68, 71, 68]