From c18c7f639bbb52ff086ea8d8547d9729cb20a160 Mon Sep 17 00:00:00 2001 From: Felipe Bormann Date: Tue, 6 Jun 2017 22:09:49 -0300 Subject: [PATCH] added analytics method to handle amount of comments inside the whole system or category specific case --- analytics/urls.py | 1 + analytics/views.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/analytics/urls.py b/analytics/urls.py index c43835c..b7dc44c 100644 --- a/analytics/urls.py +++ b/analytics/urls.py @@ -13,4 +13,5 @@ urlpatterns = [ url(r'^amount_active_users_per_day/$', views.most_active_users_in_a_month, name="most_active_users_in_a_month"), url(r'^get_days_of_the_week_log/$', views.get_days_of_the_week_log, name="get_days_of_the_week_log"), url(r'^get_category_tags/$', views.category_tags, name='get_category_tags'), + url(r'^get_comments_count/$', views.get_amount_of_comments, name='get_amount_of_comments'), ] \ No newline at end of file diff --git a/analytics/views.py b/analytics/views.py index 44b10ac..a829f55 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -18,7 +18,7 @@ import calendar from collections import OrderedDict - +from mural.models import Comment def most_used_tags(request): @@ -192,7 +192,7 @@ def get_days_of_the_week_log(request): params = request.GET date = params['date'] - date = datetime.strptime( date, '%m/%d/%Y',) + date = datetime.strptime( date, '%m/%d/%Y') days = get_days_of_the_week(date) data = activity_in_timestamp(days, params = params) #mapping of number to days @@ -239,4 +239,22 @@ def most_tags_inside_category(category_id): else: data[tag.name] = {'name': tag.name} data[tag.name]['count'] = resources_count - return data \ No newline at end of file + return data + + +def get_amount_of_comments(request): + params = request.GET + init_date = params.get('init_date') + end_date = params.get('end_date') + init_date = datetime.strptime( init_date, '%m/%d/%Y') + end_date = datetime.strptime(end_time, '%m/%d/%Y') + day_count = (end_date - init_date).days + 1 + data = {} + for i in range(day_count): + single_day = init_date + timedelta(i) + if params.get('category_id'): + category_id = int(params['category_id']) + data[single_day] = Mural.objects.filter(space__id = category_id, create_date = single_day).count() + else: + data[single_day] = Comment.objects.filter(create_date = single_day).count() + return JsonResponse(data, safe=False) \ No newline at end of file -- libgit2 0.21.2