示例#1
0
def inputTimeFrames():
    '''Allows user to choose the time frames over which they compute accelerometer features.'''

    time_frames = []
    print(
        "Accelerometer features can be extracted over different time periods.")
    cont = get_user_input(
        "If you would like to enter a time period over which to compute features, enter 'y', or press enter to compute features over the entire file."
    )
    while cont == 'y' or cont == 'Y':
        start = int(
            get_user_input(
                "Enter the starting hour of the time period (hour 0 is when the file starts):"
            ))
        end = int(
            get_user_input(
                "Enter the ending hour of the time period (hour 0 is when the file starts; use -1 for the end of the file):"
            ))
        start = getIndexFromTimestamp(int(start))
        if end != -1:
            end = getIndexFromTimestamp(int(end))
        time_frames.append([start, end])
        print("Great! Now computing features for the following time periods:" +
              str(time_frames))
        cont = get_user_input(
            "To add another time period, enter 'y'. To finish, press enter.")

    if len(time_frames) == 0:
        time_frames = [[0, -1]]  # the whole file

    return time_frames
def chooseValueOrDefault(str_input, default):
    if str_input == "":
        return default
    else:
        return float(str_input)

if __name__ == "__main__":

    data, filepath_confirm = getInputLoadFile()

    fullOutputPath = getOutputPath()

    print("")
    print("Please choose settings for the peak detection algorithm. For default values press return")
    thresh_str = get_user_input('\tMinimum peak amplitude (default = .02):')
    thresh = chooseValueOrDefault(thresh_str,.02)
    offset_str = get_user_input('\tOffset (default = 1): ')
    offset = chooseValueOrDefault(offset_str,1)
    start_WT_str = get_user_input('\tMax rise time (s) (default = 4): ')
    start_WT = chooseValueOrDefault(start_WT_str,4)
    end_WT_str = get_user_input('\tMax decay time (s) (default = 4): ')
    end_WT = chooseValueOrDefault(end_WT_str,4)

    settings_dict = {'threshold':thresh,
                     'offset':offset,
                     'rise time':start_WT,
                     'decay time':end_WT}

    print("")
    print("Okay, finding peaks in file "+ filepath_confirm + " using the following parameters")
    # Only include x axis label on final subplot
    if secondsPlot:
        plt.xlabel('Time (s)')
    else:
        plt.xlabel('Time (min)')

    # Display the plot
    plt.subplots_adjust(hspace=.3)
    plt.show()
    return


if __name__ == "__main__":
    numClassifiers = int(
        get_user_input(
            'Would you like 1 classifier (Binary or Multiclass) or both (enter 1 or 2): '
        ))

    # Create list of classifiers
    if numClassifiers == 1:
        temp_clf = int(
            get_user_input(
                "Select a classifier:\n1: Binary\n2: Multiclass\n:"))
        while temp_clf != 1 and temp_clf != 2:
            temp_clf = get_user_input(
                "Something went wrong. Enter the number 1 or 2.\n Select a classifier:\n1: Binary\n2: Multiclass):"
            )
        if temp_clf == 1:
            print('Binary Classifier selected')
            classifierList = ['Binary']
        elif temp_clf == 2:
示例#4
0
    print("This script will extract features related to accelerometer data.")

    data, filepath_confirm = getInputLoadFile()

    output_path = getOutputPath()

    time_frames = inputTimeFrames()

    features, steps, motion = computeAllAccelerometerFeatures(
        data, time_frames)

    data["steps"] = steps
    data["motion"] = motion

    saveFeaturesToFile(features, time_frames, output_path)

    print("")
    plot_ans = get_user_input(
        "Do you want to plot the detected steps? (y/n): ")
    if 'y' in plot_ans:
        secs_ans = get_user_input(
            "Would you like the x-axis to be in seconds or minutes? (sec/min): "
        )
        if 'sec' in secs_ans:
            x_seconds = True
        else:
            x_seconds = False
        plotSteps(data, x_seconds)
    else:
        print("\tOkay, script will not produce a plot")