def get_meter_statistics(self, event_filter): """Return a dictionary containing meter statistics. described by the query parameters. The filter must have a meter value set. { 'min': 'max': 'avg': 'sum': 'count': 'duration': 'duration_start': 'duration_end': } """ query = self.session.query(func.min(Meter.timestamp), func.max(Meter.timestamp), func.sum(Meter.counter_volume), func.min(Meter.counter_volume), func.max(Meter.counter_volume), func.count(Meter.counter_volume)) query = make_query_from_filter(query, event_filter) results = query.all() res = results[0] count = int(res[5]) return {'count': count, 'min': res[3], 'max': res[4], 'avg': (res[2] / count) if count > 0 else None, 'sum': res[2], 'duration': None, 'duration_start': res[0], 'duration_end': res[1], }
def get_event_interval(self, event_filter): """Return the min and max timestamps from events, using the event_filter to limit the events seen. ( datetime.datetime(), datetime.datetime() ) """ query = self.session.query(func.min(Meter.timestamp), func.max(Meter.timestamp)) query = make_query_from_filter(query, event_filter) results = query.all() a_min, a_max = results[0] return (a_min, a_max)
def get_volume_max(self, event_filter): counter_volume_func = func.max(Meter.counter_volume) query = self._make_volume_query(event_filter, counter_volume_func) results = query.all() return ({'resource_id': x, 'value': y} for x, y in results)