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
| @@ -65,10 +65,7 @@ | @@ -65,10 +65,7 @@ | ||
| 65 | </section> | 65 | </section> |
| 66 | <section class="bottom-section"> | 66 | <section class="bottom-section"> |
| 67 | <div class="chart left-chart"> | 67 | <div class="chart left-chart"> |
| 68 | - <div id="date-selector"> | ||
| 69 | - <p>{% trans "Between" %} 20-20-17 {% trans "and" %} | ||
| 70 | - 20-20-17</p> | ||
| 71 | - </div> | 68 | + |
| 72 | 69 | ||
| 73 | <div id="left-data-selector"> | 70 | <div id="left-data-selector"> |
| 74 | 71 |
analytics/views.py
| @@ -9,6 +9,8 @@ from topics.models import Resource | @@ -9,6 +9,8 @@ from topics.models import Resource | ||
| 9 | from users.models import User | 9 | from users.models import User |
| 10 | from django.http import HttpResponse, JsonResponse | 10 | from django.http import HttpResponse, JsonResponse |
| 11 | from log.models import Log | 11 | from log.models import Log |
| 12 | +import operator | ||
| 13 | +from django.utils.translation import ugettext_lazy as _ | ||
| 12 | 14 | ||
| 13 | 15 | ||
| 14 | class GeneralView(generic.TemplateView): | 16 | class GeneralView(generic.TemplateView): |
| @@ -94,10 +96,17 @@ def most_accessed_categories(request): | @@ -94,10 +96,17 @@ def most_accessed_categories(request): | ||
| 94 | return JsonResponse(categories, safe= False) | 96 | return JsonResponse(categories, safe= False) |
| 95 | 97 | ||
| 96 | def most_accessed_resource_kind(request): | 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 | mapping = {} | 110 | mapping = {} |
| 102 | mapping['pdffile'] = str(_('PDF File')) | 111 | mapping['pdffile'] = str(_('PDF File')) |
| 103 | mapping['goals'] = str(_('Topic Goals')) | 112 | mapping['goals'] = str(_('Topic Goals')) |
| @@ -107,10 +116,9 @@ def most_accessed_resource_kind(request): | @@ -107,10 +116,9 @@ def most_accessed_resource_kind(request): | ||
| 107 | mapping['ytvideo'] = str(_('YouTube Video')) | 116 | mapping['ytvideo'] = str(_('YouTube Video')) |
| 108 | mapping['webpage'] = str(_('WebPage')) | 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 | def most_active_users(request): | 124 | def most_active_users(request): |
topics/views.py
| @@ -20,7 +20,6 @@ from subjects.models import Subject | @@ -20,7 +20,6 @@ from subjects.models import Subject | ||
| 20 | from .models import Topic, Resource | 20 | from .models import Topic, Resource |
| 21 | from .forms import TopicForm | 21 | from .forms import TopicForm |
| 22 | 22 | ||
| 23 | -import operator | ||
| 24 | 23 | ||
| 25 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | 24 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 26 | log_component = 'topic' | 25 | log_component = 'topic' |