(self)
return 'Saved aggregation to ID: {0:d}'.format(self._resource_id)
Save the aggregation in the database.
Save the aggregation in the database.
Save the aggregation in the database .
def save(self):
        """Save the aggregation in the database."""
        data = {
            'name': self.name,
            'description': self.description,
            'agg_type': self.aggregator_name,
            'parameters': self._parameters,
            'chart_type': self.chart_type,
        }
        if self.search_id:
            data['view_id'] = self.search_id
        if self._labels:
            data['labels'] = json.dumps(self._labels)

        if self._resource_id:
            resource_url = '{0:s}/sketches/{1:d}/aggregation/{2:d}/'.format(
                self.api.api_root, self._sketch.id, self._resource_id)
        else:
            resource_url = '{0:s}/sketches/{1:d}/aggregation/'.format(
                self.api.api_root, self._sketch.id)

        response = self.api.session.post(resource_url, json=data)
        if not error.check_return_status(response, logger):
            return 'Unable to save the aggregation'

        response_json = response.json()
        objects = response_json.get('objects')
        if not objects:
            return 'Unable to determine ID of saved object.'
        agg_data = objects[0]
        self._resource_id = agg_data.get('id', 0)
        return 'Saved aggregation to ID: {0:d}'.format(self._resource_id)
def save ( self ) : data = { 'name' : self . name , 'description' : self . description , 'agg_type' : self . aggregator_name , 'parameters' : self . _parameters , 'chart_type' : self . chart_type , } if self . search_id : data [ 'view_id' ] = self . search_id if self . _labels : data [ 'labels' ] = json . dumps ( self . _labels ) if self . _resource_id : resource_url = '{0:s}/sketches/{1:d}/aggregation/{2:d}/' . format ( self . api . api_root , self . _sketch . id , self . _resource_id ) else : resource_url = '{0:s}/sketches/{1:d}/aggregation/' . format ( self . api . api_root , self . _sketch . id ) response = self . api . session . post ( resource_url , json = data ) if not error . check_return_status ( response , logger ) : return 'Unable to save the aggregation' response_json = response . json ( ) objects = response_json . get ( 'objects' ) if not objects : return 'Unable to determine ID of saved object.' agg_data = objects [ 0 ] self . _resource_id = agg_data . get ( 'id' , 0 ) return 'Saved aggregation to ID: {0:d}' . format ( self . _resource_id )