Merge branch 'development' of bitbucket.org:enreda/back-latienda into development
This commit is contained in:
@@ -3,6 +3,8 @@ import logging
|
||||
import json
|
||||
import io
|
||||
import datetime
|
||||
import calendar
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
@@ -217,28 +219,45 @@ def admin_stats(request):
|
||||
|
||||
today = datetime.date.today()
|
||||
# companies timeline: count companies at increments of 4 weeks
|
||||
companies_timeline = {}
|
||||
companies_timeline = []
|
||||
# products timeline: count products at increments of 4 weeks
|
||||
products_timeline = {}
|
||||
products_timeline = []
|
||||
# users timeline: count users at increments of 4 weeks
|
||||
users_timeline = {}
|
||||
users_timeline = []
|
||||
# contact timeline: count statlogs from contact at increments of 4 weeks
|
||||
contact_timeline = {}
|
||||
contact_timeline = []
|
||||
# shopping timeline: count statlogs from shopping at increments of 4 weeks
|
||||
shopping_timeline = {}
|
||||
for i in range(1, 13):
|
||||
before = today - datetime.timedelta(weeks=( (i-1) * 4 ))
|
||||
after = today - datetime.timedelta(weeks=(i*4))
|
||||
shopping_timeline = []
|
||||
|
||||
for i in reversed(range(12)):
|
||||
before = datetime.date(today.year, today.month, 1, ) - relativedelta(months=i)
|
||||
after = datetime.date(today.year, today.month, 1) - relativedelta(months=i-1)
|
||||
|
||||
# companies
|
||||
companies_timeline[i] = Company.objects.filter(created__range= [after, before]).count()
|
||||
companies_timeline.append({
|
||||
'month': before.month,
|
||||
'value': Company.objects.filter(created__range=[before,after]).count()
|
||||
})
|
||||
# products
|
||||
products_timeline[i] = Product.objects.filter(created__range= [after, before]).count()
|
||||
products_timeline.append({
|
||||
'month': before.month,
|
||||
'value': Product.objects.filter(created__range=[before,after]).count()
|
||||
})
|
||||
# users
|
||||
users_timeline[i] = User.objects.filter(created__range= [after, before]).count()
|
||||
users_timeline.append({
|
||||
'month': before.month,
|
||||
'value': User.objects.filter(created__range=[before,after]).count()
|
||||
})
|
||||
# contact
|
||||
contact_timeline[i] = StatsLog.objects.filter(contact=True, created__range= [after, before]).count()
|
||||
contact_timeline.append({
|
||||
'month': before.month,
|
||||
'value': StatsLog.objects.filter(contact=True, created__range=[before,after]).count()
|
||||
})
|
||||
# shopping
|
||||
shopping_timeline[i] = StatsLog.objects.filter(shop=True, created__range= [after, before]).count()
|
||||
shopping_timeline.append({
|
||||
'month': before.month,
|
||||
'value': StatsLog.objects.filter(shop=True, created__range=[before,after]).count()
|
||||
})
|
||||
|
||||
data = {
|
||||
'company_count': company_count,
|
||||
|
||||
Reference in New Issue
Block a user