finished admin_stats endpoint
This commit is contained in:
@@ -25,6 +25,7 @@ from companies.models import Company
|
||||
from companies.serializers import CompanySerializer
|
||||
from products.models import Product
|
||||
from geo.models import City, Region
|
||||
from stats.models import StatsLog
|
||||
|
||||
from . import models
|
||||
from . import serializers as core_serializers
|
||||
@@ -214,10 +215,41 @@ def admin_stats(request):
|
||||
count = Product.objects.filter(company__geo__within=region.geo).count()
|
||||
products_per_region[region.name] = count
|
||||
|
||||
today = datetime.date.today()
|
||||
# companies timeline: count companies at increments of 4 weeks
|
||||
companies_timeline = {}
|
||||
# products timeline: count products at increments of 4 weeks
|
||||
products_timeline = {}
|
||||
# users timeline: count users at increments of 4 weeks
|
||||
users_timeline = {}
|
||||
# contact timeline: count statlogs from contact at increments of 4 weeks
|
||||
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))
|
||||
# companies
|
||||
companies_timeline[i] = Company.objects.filter(created__range= [after, before]).count()
|
||||
# products
|
||||
products_timeline[i] = Product.objects.filter(created__range= [after, before]).count()
|
||||
# users
|
||||
users_timeline[i] = User.objects.filter(created__range= [after, before]).count()
|
||||
# contact
|
||||
contact_timeline[i] = StatsLog.objects.filter(contact=True, created__range= [after, before]).count()
|
||||
# shopping
|
||||
shopping_timeline[i] = StatsLog.objects.filter(shop=True, created__range= [after, before]).count()
|
||||
|
||||
data = {
|
||||
'company_count': company_count,
|
||||
'product_count': product_count,
|
||||
'companies_per_region': companies_per_region,
|
||||
'products_per_region': products_per_region,
|
||||
'companies_timeline': companies_timeline,
|
||||
'products_timeline': products_timeline,
|
||||
'users_timeline': users_timeline,
|
||||
'contact_timeline': contact_timeline,
|
||||
'shopping_timeline': shopping_timeline,
|
||||
}
|
||||
|
||||
return Response(data=data)
|
||||
|
||||
Reference in New Issue
Block a user