'Computes the statistics of the samples in the time range given.
:param q: Filter rules for the data to be returned.
:param groupby: Fields for group by aggregation
:param period: Returned result will be an array of statistics for a
period long of that number of seconds.
:param aggregate: The selectable aggregation functions to be applied.'

@wsme_pecan.wsexpose([Statistics], [base.Query], [six.text_type], int, [Aggregate])
def statistics(self, q=None, groupby=None, period=None, aggregate=None):

    rbac.enforce('compute_statistics', pecan.request)
    q = (q or [])
    groupby = (groupby or [])
    aggregate = (aggregate or [])
    if (period and (period < 0)):
        raise base.ClientSideError(_('Period    must    be    positive.'))
    kwargs = v2_utils.query_to_kwargs(q, storage.SampleFilter.__init__)
    kwargs['meter'] = self.meter_name
    f = storage.SampleFilter(**kwargs)
    g = _validate_groupby_fields(groupby)
    aggregate = utils.uniq(aggregate, ['func', 'param'])
    start = end = None
    for i in q:
        if ((i.field == 'timestamp') and (i.op in ('lt', 'le'))):
            end = timeutils.parse_isotime(i.value).replace(tzinfo=None)
        elif ((i.field == 'timestamp') and (i.op in ('gt', 'ge'))):
            start = timeutils.parse_isotime(i.value).replace(tzinfo=None)
    try:
        computed = pecan.request.storage_conn.get_meter_statistics(f, period, g, aggregate)
        return [Statistics(start_timestamp=start, end_timestamp=end, **c.as_dict()) for c in computed]
    except OverflowError as e:
        params = dict(period=period, err=e)
        raise base.ClientSideError((_('Invalid    period    %(period)s:    %(err)s') % params))
