Exemplo n.º 1
0
    def stat(self, l):
        # if typ == 'clicks':
        #     values = ('date', ) if not hourly else ('created_at', )
        #     count = 'date'
        #     order = 'date'
        # elif typ == 'domains':
        #     values = ('domain', )
        #     count = 'referrer'
        #     order = '-clicks'
        # elif typ == 'countries':
        #     values = ('country__code', )
        #     count = 'country'
        #     order = '-clicks'
        # elif typ == 'referrer':
        #     values = ('domain', 'referrer', )
        #     count = 'referrer'
        #     order = '-clicks'
        # else:
        #     raise ValueError('Invalid type: %s' % typ)

        # if not timestamp:
        #     q = self.for_link(l).values(*values)
        #     q = q.annotate(clicks=models.Count(count)).order_by(order)
        #     return q
        #
        # q = self.for_link(link).exclude(created_at__lt=timestamp)
        # q = q.values(*values).annotate(clicks=models.Count(count))
        # return q.order_by(order)

        return {
            'redirects': [{
                'date': utils.datetime2timestamp(i['date']),
                'redirects': i['redirects']
            } for i in self.for_link(l).values('date')
                .annotate(redirects=models.Count('date'))
                .order_by('date')
            ],
            'countries': [{
                'country': i['country__code'],
                'redirects': i['redirects']
            } for i in self.for_link(l).values('country__code')
                .annotate(redirects=models.Count('country'))
                .order_by('-redirects')
            ],
            'domains': [{
                'domain': i['domain'],
                'redirects': i['redirects']
            } for i in self.for_link(l).values('domain')
                .annotate(redirects=models.Count('referrer'))
                .order_by('-redirects')
            ],
            'referrer': [{
                'referrer': i['referrer'],
                'redirects': i['redirects']
            } for i in self.for_link(l).values('domain', 'referrer')
                .annotate(redirects=models.Count('referrer'))
                .order_by('-redirects')
            ]
        }
Exemplo n.º 2
0
 def to_json(self):
     return {
         'id': self.id,
         'url': self.url,
         'qlink': self.qlink,
         'favicon': self.favicon,
         'title': self.title,
         'created_at': utils.datetime2timestamp(self.created_at),
         'redirects': self.redirects,
         'qr_code': self.qr_code
     }