示例#1
0
文件: stats.py 项目: jrburke/f1
    def accounts(self):
        start = request.params.get('start',None)
        end = request.params.get('end',None)
        limit = int(request.params.get('days','0'))
        opts = request.params.get('opts','').split(',')
        groupby = []
        whereclause = []
        if limit and not start and not end:
            whereclause.append(Account.created >= UTCDateTime.now() - timedelta(days=limit))
        if start:
            whereclause.append(Account.created >= UTCDateTime.from_string(start))
        if end:
            whereclause.append(Account.created < UTCDateTime.from_string(end))
        if 'perday' in opts:
            if 'domain' in opts:
                s = select([func.date(Account.created), Account.domain, func.count(Account.id)])
                groupby.append(func.to_days(Account.created))
                groupby.append(Account.domain)
            else:
                s = select([func.date(Account.created), func.count(Account.id)])
                groupby.append(func.to_days(Account.created))
        else:
            s = select([func.count(Account.domain), Account.domain])
            groupby.append(Account.domain)

        if whereclause:
            s = s.where(*whereclause)
        if groupby:
            s = s.group_by(*groupby)
        return [list(a) for a in Session.execute(s).fetchall()]
示例#2
0
文件: stats.py 项目: jrburke/f1
 def history(self):
     start = request.params.get('start',None)
     end = request.params.get('end',None)
     limit = int(request.params.get('days','0'))
     opts = request.params.get('opts','').split(',')
     whereclause = []
     vars = {}
     groupby = []
     if limit and not start and not end:
         whereclause.append(History.published >= UTCDateTime.now() - timedelta(days=limit))
     if start:
         whereclause.append(History.published >= UTCDateTime.from_string(start))
     if end:
         whereclause.append(History.published < UTCDateTime.from_string(end))
     if 'perday' in opts:
         if 'domain' in opts:
             s = select([func.date_format(History.published, "%Y-%m-%d"), History.domain, func.count(History.domain)],)
             groupby.append(func.to_days(History.published))
             groupby.append(History.domain)
         else:
             s = select([func.date_format(History.published, "%Y-%m-%d"), func.count(History.id)])
             groupby.append(func.to_days(History.published))
     else:
         s = select([func.count(History.domain), History.domain])
         groupby.append(History.domain)
     
     if whereclause:
         s = s.where(and_(*whereclause))
     if groupby:
         s = s.group_by(*groupby)
     return [list(a) for a in Session.execute(s).fetchall()]