def add_data_to_dataset(self, ds_name, data): """Adds data to the end of a dataset. The data is a list of dicts, with each dict representing a parameter set.""" ds_list = [ds for ds in self.datasets if ds.name == ds_name] if not ds_list: raise self.InvalidInputException( 'No dataset with name %s found.' % ds_name) dataset = ds_list[0] assert isinstance(data, list) for params in data: assert isinstance(params, dict) param_set = ParamSet() for key in dataset.schema: if not key in params: raise KeyError('Key %s not found in parameter set' % key) param = Parameter(name=key, obj_type='UnicodeString', values=[params[key]]) param_set.params.append(param) param_set_key = param_set.put() dataset.param_sets.append(param_set_key) self.put()
def test_paramset_class(self): """Test the ParamSet class.""" param1 = Parameter(name='param1', obj_type='Int', values=[6]) param2 = Parameter(name='param2', obj_type='Int', values=[8]) params = [param1, param2] paramset = ParamSet(params=params) paramset.put() assert isinstance(paramset.params, list) self.assertEqual(len(paramset.params), 2) for param in paramset.params: assert isinstance(param, Parameter)
def get_random_param_set(self): """Returns a list of parameter values. This is a parameter set that is chosen at random from the dataset.""" if not self.param_sets: return None param_set_key = utils.get_random_choice(self.param_sets) return ParamSet.get_by_id(param_set_key.id())