Ejemplo n.º 1
0
    def __run_test(self, filename, output_directory):
        """
        Handles running of data through algorithm not live, parses the file and puts data line by line
        through the algorithm, algorithm will react to it as if the data is being collected real time. Used in testing
        mode as can be run at home to see how algorithm reacts.
        Args:
            filename: name of recorded data to run through, defaults to latest file
            output_directory: relative path to output_directory folder
        Returns:
            None, but stores the logs of the test in a file in output_directory
        Example:
            > self.__run_test('data_to_load', '../Output_data')
        """

        # Read old data
        print(
            '\n\033[1mUsing test mode, will apply algorithm to data from file {}\033[0m\n'
            .format(filename))
        data = read_file(output_directory + filename)

        self.all_data = self.initialize_all_data()

        # some functions depend on sampling period, therefore extract correct
        # period and place into algorithm data so that it can be passed through
        average_cycle_time = numpy.mean(numpy.diff(data['time']))
        for algorithm in self.order:
            algorithm['period'] = average_cycle_time

        switch = 'switch'
        for i in xrange(len(data)):
            algo = self.algo_name

            # Make current row out of real values from data minus the position and algorithm
            # as those are the things we are running testing to watch
            row_no_pos_algo = list(data[i])[:-2]
            current_values = convert_list_dict(row_no_pos_algo +
                                               [algo, self.position])

            try:
                switch = self.__run_algorithm(switch, current_values)
            except AlgorithmFinished:
                print '\n\033[1mAlgorithm finished, stopping now\033[0m\n'
                break

        # Data loaded in will have ' Org' file so remove that and replace with ' Tst'
        store(filename[:-4] + ' Tst', self.all_data)
Ejemplo n.º 2
0
    def __run_test(self, filename, output_directory):
        """
        Function to run the interface with a fake robot and fake encoders

        Args:
            filename: The name of the file containing prvious data to run the interface off
            output_directory: name of the Directory containg the data file

        """

        # Read old data
        print(
            '\n\033[1mUsing test mode, will apply algorithm to data from file {}\033[0m\n'
            .format(filename))
        data = read_file(output_directory + filename)

        self.all_data = self.initialize_all_data()

        # some functions depend on sampling period, therefore extract correct
        # period and place into algorithm data so that it can be passed through
        average_cycle_time = numpy.mean(numpy.diff(data['time']))
        for algorithm in self.order:
            algorithm['period'] = average_cycle_time

        switch = 'switch'
        for i in xrange(len(data)):

            algo = self.algo_name

            # Make current row out of real values from data minus the position and algorithm
            # as those are the things we are running testing to watch
            row_no_pos_algo = list(data[i])[:-2]
            current_values = convert_list_dict(row_no_pos_algo +
                                               [algo, self.position])

            try:
                switch = self.__run_algorithm(switch, current_values)
            except AlgorithmFinished:
                print '\n\033[1mAlgorithm finished, stopping now\033[0m\n'
                break

        # Data loaded in will have ' Org' file so remove that and replace with ' Tst'
        store(filename[:-4] + ' Tst.txt', self.all_data)
Ejemplo n.º 3
0
    def finish_script(self):
        """
        Prints running time, cycle time, and stores current data to file
        Args:
            None
        Returns:
            None, but stores to file
        """
        # Check whether everything is running on schedule or not
        time_taken = tme.time() - self.initial_time
        print('\033[1mFinished in {:.2f}s\033[0m'.format(time_taken))
        # Check how fast code is running
        average_cycle_time = numpy.mean(numpy.diff(self.all_data['time']))
        print(
            '\033[1mExpected sampling period: {:.3f}s\nActual sampling period: {:.3f}s\033[0m'
            .format(self.period, average_cycle_time))

        # store data in txt file, all original data has ' Org' added to name
        store(self.filename + ' Org', self.all_data)