def make_query_from_filter(sample_filter, require_meter=True):
 q = {}
 if sample_filter.user:
  q['user_id'] = sample_filter.user
 if sample_filter.project:
  q['project_id'] = sample_filter.project
 if sample_filter.meter:
  q['counter_name'] = sample_filter.meter
 elif require_meter:
  raise RuntimeError('Missing required meter specifier')
 ts_range = make_timestamp_range(sample_filter.start_timestamp, sample_filter.end_timestamp, sample_filter.start_timestamp_op, sample_filter.end_timestamp_op)
 if ts_range:
  q['timestamp'] = ts_range
 if sample_filter.resource:
  q['resource_id'] = sample_filter.resource
 if sample_filter.source:
  q['source'] = sample_filter.source
 if sample_filter.message_id:
  q['message_id'] = sample_filter.message_id
 q.update(dict(((('resource_%s' % k), v) for (k, v) in six.iteritems(improve_keys(sample_filter.metaquery, metaquery=True)))))
 return q

def make_query_from_filter ( sample_filter , require_meter = True ) : q = { } if sample_filter . user : q [ 'user_id' ] = sample_filter . user if sample_filter . project : q [ 'project_id' ] = sample_filter . project if sample_filter . meter : q [ 'counter_name' ] = sample_filter . meter elif require_meter : raise RuntimeError ( 'Missing required meter specifier' ) ts_range = make_timestamp_range ( sample_filter . start_timestamp , sample_filter . end_timestamp , sample_filter . start_timestamp_op , sample_filter . end_timestamp_op ) if ts_range : q [ 'timestamp' ] = ts_range if sample_filter . resource : q [ 'resource_id' ] = sample_filter . resource if sample_filter . source : q [ 'source' ] = sample_filter . source if sample_filter . message_id : q [ 'message_id' ] = sample_filter . message_id q . update ( dict ( ( ( ( 'resource_%s' % k ) , v ) for ( k , v ) in six . iteritems ( improve_keys ( sample_filter . metaquery , metaquery = True ) ) ) ) ) return q
return a query dictionary based on the settings in the filter .