Example #1
0
    def get_variables(self, data_source):
        '''Returns a list of all stored variables corresponding to the input data source

        Keyword arguments:
        @param data_source -- a string denoting the name of a data source; collection names
                              corresponding to data from this data source are expected to
                              start with the data source name

        '''
        (host, port) = DBUtils.get_db_host_and_port()
        if port != self.db_port:
            port = self.db_port

        client = pm.MongoClient(host=host, port=port)
        database = client[self.db_name]
        collection_names = database.list_collection_names()

        variable_list = []
        for collection_name in collection_names:
            if collection_name == 'system.indexes' or \
               not collection_name.startswith(data_source):
                continue

            collection = database[collection_name]
            variable_names = DataUtils.get_variable_list(
                collection_name, collection)
            variable_list.extend(variable_names)
        return variable_list
Example #2
0
 def test_get_variable_list(self):
     database = self.client[self.test_db_name]
     collection = database[self.collection_name]
     variable_list = DataUtils.get_variable_list(self.collection_name, collection)
     self.assertCountEqual(variable_list, ['ros_ropod_cmd_vel/linear/x', 'ros_ropod_cmd_vel/linear/y', 'ros_ropod_cmd_vel/linear/z', 'ros_ropod_cmd_vel/angular/x', 'ros_ropod_cmd_vel/angular/y', 'ros_ropod_cmd_vel/angular/z'])