def _do_time_count(self, period, query, ensure_single=False):
    if ('time' not in query):
        raise ValueError('Counting through time requires a "time" range query argument')
    query = dict(query)
    (start, end) = query['time']
    del query['time']
    product_quries = list(self._get_product_queries(query))
    if ensure_single:
        if (len(product_quries) == 0):
            raise ValueError(('No products match search terms: %r' % query))
        if (len(product_quries) > 1):
            raise ValueError(('Multiple products match single query search: %r' % ([dt.name for (q, dt) in product_quries],)))
    for (q, dataset_type) in product_quries:
        dataset_fields = dataset_type.metadata_type.dataset_fields
        query_exprs = tuple(fields.to_expressions(dataset_fields.get, **q))
        (yield (dataset_type, list(self._db.count_datasets_through_time(start, end, period, dataset_fields.get('time'), query_exprs))))
def _do_time_count(self, period, query, ensure_single=False):
    if ('time' not in query):
        raise ValueError('Counting through time requires a "time" range query argument')
    query = dict(query)
    (start, end) = query['time']
    del query['time']
    product_quries = list(self._get_product_queries(query))
    if ensure_single:
        if (len(product_quries) == 0):
            raise ValueError(('No products match search terms: %r' % query))
        if (len(product_quries) > 1):
            raise ValueError(('Multiple products match single query search: %r' % ([dt.name for (q, dt) in product_quries],)))
    for (q, dataset_type) in product_quries:
        dataset_fields = dataset_type.metadata_type.dataset_fields
        query_exprs = tuple(fields.to_expressions(dataset_fields.get, **q))
        (yield (dataset_type, list(self._db.count_datasets_through_time(start, end, period, dataset_fields.get('time'), query_exprs))))