<commit_before># import random
# import sys
# import os

import math
import numpy
import pandas as pd
# Maybe hr (passed in vector) should be three columns so that I can always pass it in, and just fill as needed


def thresholdhr(hr_rawdata):
    """Will create a threshold array (in mV) on which to return the heart rate
    :param hr_rawdata: raw data input (time first column, voltage second column)
    :return: will return a dataframe of numbers for thresholding whether a heart beat has occured
    """

    # time, voltage
    threshold = 0.7  # %70 percent of max
    time_step = hr_rawdata['time'][2]-hr_rawdata['time'][1]
    data_chunk = int(math.floor(5/time_step))
    number_chunks = int(math.floor((len(hr_rawdata)/data_chunk)))

    # Gives a number of data points per to look at, will miss at worst 100 points
    threshold_hr = [None] * number_chunks

    for j in range(0, number_chunks):
        # minhr_data = min(hr_rawdata[timestamp:timestamp+time_interval])
        maxhr_data = max(hr_rawdata['voltage'][(j * data_chunk):(j * data_chunk) + data_chunk])
        # maxhr_data = max([row[0] for row in hr_rawdata[j*time_interval:(j*time_interval)+time_interval]])
        threshold_hr[j] = threshold * maxhr_data
    threshold_hr = pd.DataFrame(numpy.array(threshold_hr), columns=['Threshold'])
    return [threshold_hr, data_chunk, number_chunks]


def hrdetector(hr_rawdata):
    """Use threshold detection to specify a heart beat (QRS height) and estimate both instanteous and hr over delta_t
    :param hr_rawdata: raw data (after minor I/O filtering)
    """
    # delta_t = input('Enter how long you would like to average your heart rate over (in s): ')
    # Use delta_t, average the HR over that time
    # for i in hr_rawdata[1], find minimum and max locally, threshold on that (using a timing fxn)
    # Calls thresholdhr every so often
    [thresholds, data_chunk, number_chunks] = thresholdhr(hr_rawdata)
    # DataFrame, thresholds, data_chunk (# of points per 5 seconds), number_chunks
    columns = ['HeartRate', 'B/T', 'time']
    # index = [None] * len(thresholds)
    hr = pd.DataFrame(numpy.empty(((len(thresholds)), 3)), columns=columns)
    hr['HeartRate'] = None
    hr['B/T'] = 'Healthy... for now'
    hr['time'] = list(range(0, number_chunks * 5, 5))

    hb_count = [0] * len(thresholds)

    # time_step = hr_rawdata['time'][2]-hr_rawdata['time'][1]  # find time step
    for j in range(0, len(thresholds)):
        for i in range(1, data_chunk):
            if (hr_rawdata['voltage'][i*(j+1)] > thresholds[j]) and \
                    (hr_rawdata['voltage'][(i*(j+1))-1] < thresholds[j]):
                hb_count[j] = hb_count[j] + 1
        hr.at[j, 'HeartRate'] = (hb_count[j]/5)*60
    return hr


def bradydetector(hr, hr_threshold_brady):
    """Detects bradycardia based on threshold input
    :param hr:
    :param hr_threshold_brady:
    :returns: Number of instances of Bradycardia, time stamp for Bradycardia, return HR list with added colomns
    """

    # n = len(hr)
    bradycount = 0
    for x in range(0, len(hr)):
        # timestamp = x * delta_t
        if hr['HeartRate'][x] < hr_threshold_brady:
            bradycount += 1
            if bradycount > 0:
                print("Bradycardia Detected! Either you're an athlete or something's wrong!")
            hr.at[x, 'B/T'] = 'Bradycardia Detected'<commit_msg>Updated, and minorly tested, working code<commit_after># import random
# import sys
# import os

import math
import numpy
import pandas as pd
# Maybe hr (passed in vector) should be three columns so that I can always pass it in, and just fill as needed


def thresholdhr(hr_rawdata):
    """Will create a threshold array (in mV) on which to return the heart rate
    :param hr_rawdata: raw data input (time first column, voltage second column)
    :return: will return a dataframe of numbers for thresholding whether a heart beat has occured
    """

    # time, voltage
    threshold = 0.9  # %90 percent of max
    time_step = hr_rawdata['time'][2]-hr_rawdata['time'][1]
    data_chunk = int(math.floor(5/time_step))
    number_chunks = int(math.floor((len(hr_rawdata)/data_chunk)))

    # Gives a number of data points per to look at, will miss at worst 100 points
    threshold_hr = [None] * number_chunks

    for j in range(0, number_chunks):
        # minhr_data = min(hr_rawdata[timestamp:timestamp+time_interval])
        maxhr_data = max(hr_rawdata['voltage'][(j * data_chunk):(j * data_chunk) + data_chunk])
        # maxhr_data = max([row[0] for row in hr_rawdata[j*time_interval:(j*time_interval)+time_interval]])
        threshold_hr[j] = threshold * maxhr_data
    threshold_hr = pd.DataFrame(numpy.array(threshold_hr), columns=['Threshold'])
    return [threshold_hr, data_chunk, number_chunks]


def hrdetector(hr_rawdata):
    """Use threshold detection to specify a heart beat (QRS height) and estimate both instanteous and hr over delta_t
    :param hr_rawdata: raw data (after minor I/O filtering)
    """
    # delta_t = input('Enter how long you would like to average your heart rate over (in s): ')
    # Use delta_t, average the HR over that time
    # for i in hr_rawdata[1], find minimum and max locally, threshold on that (using a timing fxn)
    # Calls thresholdhr every so often
    [thresholds, data_chunk, number_chunks] = thresholdhr(hr_rawdata)
    # DataFrame, thresholds, data_chunk (# of points per 5 seconds), number_chunks
    columns = ['HeartRate', 'B/T', 'time']
    # index = [None] * len(thresholds)
    hr = pd.DataFrame(numpy.empty(((len(thresholds)), 3)), columns=columns)
    hr['HeartRate'] = None
    hr['B/T'] = 'Healthy... for now'
    hr['time'] = list(range(0, number_chunks * 5, 5))

    hb_count = [0] * len(thresholds)

    # time_step = hr_rawdata['time'][2]-hr_rawdata['time'][1]  # find time step
    for j in range(0, len(thresholds)):
        for i in range(1, data_chunk):
            if (hr_rawdata['voltage'][i*(j+1)] > thresholds['Threshold'][j]) and \
                    (hr_rawdata['voltage'][(i*(j+1))-1] < thresholds['Threshold'][j]):
                hb_count[j] = hb_count[j] + 1
        hr.at[j, 'HeartRate'] = (hb_count[j]/5)*60
    return hr


def bradydetector(hr, hr_threshold_brady):
    """Detects bradycardia based on threshold input
    :param hr:
    :param hr_threshold_brady:
    :returns: Number of instances of Bradycardia, time stamp for Bradycardia, return HR list with added colomns
    """

    # n = len(hr)
    bradycount = 0
    for x in range(0, len(hr)):
        # timestamp = x * delta_t
        if hr['HeartRate'][x] < hr_threshold_brady:
            bradycount += 1
            if bradycount > 0:
                print("Bradycardia Detected! Either you're an athlete or something's wrong!")
            hr.at[x, 'B/T'] = 'Bradycardia Detected'
{'fraction_non_alphanumeric': 0.11800878477306002, 'fraction_numerical': 0.009956076134699853, 'mean_word_length': 3.4127906976744184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1490353', 'n_tokens_mistral': 2289, 'n_tokens_neox': 2166, 'n_words': 686}