models.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:minstances 作者: 0xa 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号