def get_ping_aggregates(self, template):
now = datetime.utcnow()
if template == '30m':
a = now - timedelta(days=7)
agg_date = sqle.text("datetime((strftime('%s', time) / 1800) * 1800, 'unixepoch')")
else:
raise Exception()
cnt = sqlf.count(Ping.id)
q = sql.select([
agg_date,
sqlf.sum(Ping.response_time) / cnt,
sqlf.sum(Ping.users) / cnt,
sqlf.sum(Ping.statuses) / cnt,
sqlf.sum(Ping.connections) / cnt,
])
q = q.where((Ping.time >= a) & (Ping.instance_id == self.id))
q = q.group_by(agg_date)
q = q.order_by(Ping.id)
Nt = namedtuple('PingAgg', ['time', 'response_time', 'users', 'statuses', 'connections'])
r = db.session.execute(q)
return [Nt(*t) for t in r]
评论列表
文章目录