<commit_before>from bokeh.io import output_notebook
from bokeh.plotting import figure, show, gridplot
import numpy as np
import os
import csv


def download_trajectory_data(file):
    """
    Converts a .csv file dataset to a numpy array.  If the file
    is not a .csv file or the file does not exist, returns an error message.

    Inputs: .csv file.
    Outputs: numpy array
    """

    # Define unit test variables
    file_csv = True
    file_exists = True

    # Check if file is a .csv file
    if file[-4:] == '.csv':

        # Check if file exists and downloads it.\
        try:
            name = np.genfromtxt(file, delimiter=",")
            name = np.delete(name, 0, 0)
        except:
            print('File does not exist')
            file_exists = False
            return (file_csv, file_exists)
        else:
            return name

    else:

        file_csv = False
        print('File is not a .csv file')
        return (file_csv, file_exists)


def csv_writer():
    """
    Creates a sample dataset for unit tests called output.csv
    """
    if os.path.exists('output.csv'):
        print('output.csv', 'already exists')

    else:

        data = ["first_name,last_name,city".split(","),
                "Tyrese,Hirthe,Strackeport".split(","),
                "Jules,Dicki,<NAME>".split(","),
                "Dedric,Medhurst,Stiedemannberg".split(",")
                ]
        path = "output.csv"
        with open(path, "w") as csv_file:
            writer = csv.writer(csv_file, delimiter=',')
            for line in data:
                writer.writerow(line)


def define_xydata(dataset, sets):
    """
    Takes a large numpy array (presumably trajectory data with frames, x
    coordinates, y coordinates) of n columns and splits into (n-1)/3 numpy
    arrays of x-y data plus a separate array of time data.

    The first column in array is time column.  Afterwards, every set of three
    columns becomes an entry in dictionary (Run i).

    Example: trajectory data over 10-second interval with three particles, each
    with three types of data: frame, x coordinate, y coordinate.  define_xydata
    would output a times array (1 column) plus 3 3-column arrays of trajectory
    data with names Run['Run1'], Run['Run2'], Run['Run3'].  These can be used
    to define variable with desired names later.

    Input: Large numpy array (n columns), number of sets to define from array
    Output: time array (1 column)
            trajectory arrays ((n-1)/3 columns)
    """

    splitsuccess = True
    wholenumber = True
    justrightsets = True
    correctformat = True

    # Check that dataset is of the correct format.
    if (dataset.shape[1] - 1) % 3 == 0:

        # Check that the desire number of sets matches the given dataset.
        if sets < (dataset.shape[1] - 1)/3:

            # Check that the desired number of sets is a whole number.
            if float(sets).is_integer():

                # Define the times column.
                times = dataset[:, 0]
                Run = dict()

                # Build individual trajectory datasets.
                for num in range(1, sets + 1):
                    Run["Run" + str(num)] = dataset[:, 3 * num - 2: 3 * num + 1]

                return times, Run

            else:
                print("The variable 'sets' must be a whole number.")
                wholenumber = False
                splitsuccess = False
                return (splitsuccess, wholenumber, justrightsets, correctformat)

        else:
            print("Desired number of sets is too high for this dataset.")
            justrightsets = False
            splitsuccess = False
            return (splitsuccess, wholenumber, justrightsets, correctformat)<commit_msg>Reviewed comments from group members and made selected changes.  Some comments reflected discussion that we already resolved together, and others reflected future iterations.  Made a few minor changes involving commenting within my code.<commit_after>from bokeh.io import output_notebook
from bokeh.plotting import figure, show, gridplot
import numpy as np
import os
import csv


def download_trajectory_data(file):
    """
    Converts a .csv file dataset to a numpy array.  If the file
    is not a .csv file or the file does not exist, returns an error message.

    Inputs: .csv file.
    Outputs: numpy array
    """

    # Define unit test variables
    file_csv = True
    file_exists = True

    # Check if file is a .csv file
    if file[-4:] == '.csv':

        # Check if file exists and downloads it.\
        try:
            name = np.genfromtxt(file, delimiter=",")
            name = np.delete(name, 0, 0)
        except:
            print('File does not exist')
            file_exists = False
            return (file_csv, file_exists)
        else:
            return name

    else:

        file_csv = False
        print('File is not a .csv file')
        return (file_csv, file_exists)


def csv_writer():
    """
    Creates a sample dataset for unit tests called output.csv
    """
    if os.path.exists('output.csv'):
        print('output.csv', 'already exists')

    else:

        data = ["first_name,last_name,city".split(","),
                "Tyrese,Hirthe,Strackeport".split(","),
                "<NAME>".split(","),
                "Dedric,Medhurst,Stiedemannberg".split(",")
                ]
        path = "output.csv"
        with open(path, "w") as csv_file:
            writer = csv.writer(csv_file, delimiter=',')
            for line in data:
                writer.writerow(line)


def define_xydata(dataset, sets):
    """
    Takes a large numpy array (presumably trajectory data with frames, x
    coordinates, y coordinates) of n columns and splits into (n-1)/3 numpy
    arrays of x-y data plus a separate array of time data.

    The first column in array is time column.  Afterwards, every set of three
    columns becomes an entry in dictionary (Run i).

    Example: trajectory data over 10-second interval with three particles, each
    with three types of data: frame, x coordinate, y coordinate.  define_xydata
    would output a times array (1 column) plus 3 3-column arrays of trajectory
    data with names Run['Run1'], Run['Run2'], Run['Run3'].  These can be used
    to define variable with desired names later.

    Input: Large numpy array (n columns), number of sets to define from array
    Output: time array (1 column)
            trajectory arrays ((n-1)/3 columns)
    """

    splitsuccess = True
    wholenumber = True
    justrightsets = True
    correctformat = True

    if (dataset.shape[1] - 1) % 3 == 0:

        if sets < (dataset.shape[1] - 1)/3:

            if float(sets).is_integer():

                times = dataset[:, 0]
                Run = dict()

                for num in range(1, sets + 1):
                    Run["Run" + str(num)] = dataset[:, 3 * num - 2: 3 * num + 1]

                return times, Run

            else:
                print("The variable 'sets' must be a whole number.")
                wholenumber = False
                splitsuccess = False
                return (splitsuccess, wholenumber, justrightsets, correctformat)

        else:
            print("Desired number of sets is too high for this dataset.")
            justrightsets = False
            splitsuccess = False
            return (splitsuccess, wholenumber, justrightsets, correctformat)
{'fraction_non_alphanumeric': 0.09016283138204817, 'fraction_numerical': 0.008074283407347598, 'mean_word_length': 2.0812603648424544, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6708740', 'n_tokens_mistral': 2116, 'n_tokens_neox': 1983, 'n_words': 785}