admin stats
This commit is contained in:
@@ -3,6 +3,8 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import io
|
import io
|
||||||
import datetime
|
import datetime
|
||||||
|
import calendar
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
@@ -217,28 +219,45 @@ def admin_stats(request):
|
|||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
# companies timeline: count companies at increments of 4 weeks
|
# companies timeline: count companies at increments of 4 weeks
|
||||||
companies_timeline = {}
|
companies_timeline = []
|
||||||
# products timeline: count products at increments of 4 weeks
|
# products timeline: count products at increments of 4 weeks
|
||||||
products_timeline = {}
|
products_timeline = []
|
||||||
# users timeline: count users at increments of 4 weeks
|
# 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: 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: count statlogs from shopping at increments of 4 weeks
|
||||||
shopping_timeline = {}
|
shopping_timeline = []
|
||||||
for i in range(1, 13):
|
|
||||||
before = today - datetime.timedelta(weeks=( (i-1) * 4 ))
|
for i in reversed(range(12)):
|
||||||
after = today - datetime.timedelta(weeks=(i*4))
|
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
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
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 = {
|
data = {
|
||||||
'company_count': company_count,
|
'company_count': company_count,
|
||||||
|
|||||||
Reference in New Issue
Block a user