def setup_class(cls): cls.ds = cls.api.create_dataset( Dataset.from_dict({ "name": "Test custom dataset", "fields": ["timestamp_utc", "rp_entity_id", "entity_name", "AVG_REL"], "filters": { "relevance": { "$gte": 90 } }, "custom_fields": [{ "AVG_REL": { "avg": { "field": "RELEVANCE", "mode": "daily" } } }], "conditions": { "$and": [{ "AVG_REL": { "$gt": 30 } }, { "rp_entity_id": { "$in": ["ROLLUP"] } }] }, "frequency": "daily", "tags": [] }))
def list_datasets(self, scope=None, tags=None): """ Return a DataSetList of datasets in the scope """ response = self.request('/datasets', params=dict( tags=tags or None, scope=scope or 'private', )) return DatasetList( map(lambda item: Dataset.from_dict(item, api=self), response.json()['datasets']))
def list_datasets(self, scope=None, tags=None, options=None): """ Return a DataSetList of datasets in the scope """ response = self.request('/datasets', params=dict( tags=tags or None, scope=scope or 'private', )) datasets = DatasetList( map(lambda item: Dataset.from_dict(item, api=self), response.json()['datasets'])) # Returns either the dataset class or the datasets if options == 'by_name': return datasets.by_name if options == 'by_id': return datasets.by_id else: return datasets
print("Creating a new dataset with functions and conditions...") dataset = api.create_dataset( Dataset.from_dict({ "name": "Dataset with functions and conditions", "fields": ["timestamp_utc", "rp_entity_id", "entity_name", "AVG_REL"], "filters": {}, "custom_fields": [{ "AVG_REL": { "avg": { "field": "RELEVANCE", "mode": "daily" } } }], "conditions": { "$and": [{ "AVG_REL": { "$gt": 30 } }, { "rp_entity_id": { "$in": ["ROLLUP"] } }] }, "frequency": "daily", "tags": [] })) dataset.save()