Commit 7433e08d6181cebc6ece07f8e24782f360db9d1b
1 parent
6fd02a38
Exists in
master
and in
2 other branches
finished collecting data from bottom left side
Showing
3 changed files
with
16 additions
and
12 deletions
Show diff stats
analytics/templates/analytics/general.html
analytics/views.py
... | ... | @@ -9,6 +9,8 @@ from topics.models import Resource |
9 | 9 | from users.models import User |
10 | 10 | from django.http import HttpResponse, JsonResponse |
11 | 11 | from log.models import Log |
12 | +import operator | |
13 | +from django.utils.translation import ugettext_lazy as _ | |
12 | 14 | |
13 | 15 | |
14 | 16 | class GeneralView(generic.TemplateView): |
... | ... | @@ -94,10 +96,17 @@ def most_accessed_categories(request): |
94 | 96 | return JsonResponse(categories, safe= False) |
95 | 97 | |
96 | 98 | def most_accessed_resource_kind(request): |
97 | - resources_names = [cls.__name__ for cls in Resource.__subclasses__()] | |
98 | - print(resources_names) | |
99 | - resources = {} | |
99 | + resources = Resource.objects.distinct() | |
100 | 100 | |
101 | + data = {} | |
102 | + for resource in resources: | |
103 | + key = resource.__dict__['_my_subclass'] | |
104 | + if key in data.keys(): | |
105 | + data[key]['count'] = data[key]['count'] + 1 | |
106 | + else: | |
107 | + data[key] = {'name': key, 'count': 1} | |
108 | + | |
109 | + data = sorted(data.values(), key = lambda x: x['count'], reverse= True) | |
101 | 110 | mapping = {} |
102 | 111 | mapping['pdffile'] = str(_('PDF File')) |
103 | 112 | mapping['goals'] = str(_('Topic Goals')) |
... | ... | @@ -107,10 +116,9 @@ def most_accessed_resource_kind(request): |
107 | 116 | mapping['ytvideo'] = str(_('YouTube Video')) |
108 | 117 | mapping['webpage'] = str(_('WebPage')) |
109 | 118 | |
110 | - | |
111 | - | |
112 | - | |
113 | - return JsonResponse(resources, safe = False) | |
119 | + data = [ {'name': mapping[resource['name']] , 'count': resource['count']} for resource in data] | |
120 | + data = data[:5] | |
121 | + return JsonResponse(data, safe=False) | |
114 | 122 | |
115 | 123 | |
116 | 124 | def most_active_users(request): | ... | ... |
topics/views.py