You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.8 KiB
67 lines
2.8 KiB
# -*- coding: utf-8 -*-
|
|
from datetime import date
|
|
from django.core.management.base import BaseCommand
|
|
from expobanner.models import Log, LogStat, Banner, PaidStat
|
|
from exposition.models import Exposition
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
today = date.today()
|
|
# banners
|
|
for banner in Banner.objects.select_related('group').filter(public=True):
|
|
try:
|
|
logstat = LogStat.objects.get(banner=banner, group=banner.group, date=today)
|
|
except LogStat.DoesNotExist:
|
|
logstat = LogStat(banner=banner, group=banner.group, date=today)
|
|
|
|
views = Log.objects.filter(datetime__startswith=today,
|
|
banner=banner,
|
|
group=banner.group,
|
|
type=1).count()
|
|
clicks = Log.objects.filter(datetime__startswith=today,
|
|
banner=banner,
|
|
group=banner.group,
|
|
type=2).count()
|
|
unique_views = Log.objects.filter(datetime__startswith=today,
|
|
banner=banner,
|
|
group=banner.group,
|
|
type=1).values('ip').distinct().count()
|
|
unique_clicks = Log.objects.filter(datetime__startswith=today,
|
|
banner=banner,
|
|
group=banner.group,
|
|
type=2).values('ip').distinct().count()
|
|
logstat.click = clicks
|
|
logstat.view = views
|
|
logstat.unique_click = unique_clicks
|
|
logstat.unique_view = unique_views
|
|
logstat.save()
|
|
|
|
# paid expos
|
|
expos = list(Exposition.objects.select_related('paid_new').filter(paid_new__isnull=False))
|
|
for expo in expos:
|
|
paid = expo.paid_new
|
|
try:
|
|
paidstat = PaidStat.objects.get(paid=paid, date=today)
|
|
except PaidStat.DoesNotExist:
|
|
paidstat = PaidStat(paid=paid, date=today)
|
|
|
|
t_clicks = Log.objects.filter(datetime__startswith=today, banner=paid.tickets, type=2).count()
|
|
p_clicks = Log.objects.filter(datetime__startswith=today, banner=paid.participation, type=2).count()
|
|
o_clicks = Log.objects.filter(datetime__startswith=today, banner=paid.official, type=2).count()
|
|
c_clicks = Log.objects.filter(datetime__startswith=today, banner=paid.catalog, type=2).count()
|
|
|
|
paidstat.tickets_clicks = t_clicks
|
|
paidstat.participation_clicks = p_clicks
|
|
paidstat.official_clicks = o_clicks
|
|
paidstat.catalog_clicks = c_clicks
|
|
|
|
paidstat.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|