Commit c18c7f639bbb52ff086ea8d8547d9729cb20a160
1 parent
e9e67da2
Exists in
master
and in
2 other branches
added analytics method to handle amount of comments inside the whole system or c…
…ategory specific case
Showing
2 changed files
with
22 additions
and
3 deletions
Show diff stats
analytics/urls.py
| @@ -13,4 +13,5 @@ urlpatterns = [ | @@ -13,4 +13,5 @@ urlpatterns = [ | ||
| 13 | url(r'^amount_active_users_per_day/$', views.most_active_users_in_a_month, name="most_active_users_in_a_month"), | 13 | url(r'^amount_active_users_per_day/$', views.most_active_users_in_a_month, name="most_active_users_in_a_month"), |
| 14 | url(r'^get_days_of_the_week_log/$', views.get_days_of_the_week_log, name="get_days_of_the_week_log"), | 14 | url(r'^get_days_of_the_week_log/$', views.get_days_of_the_week_log, name="get_days_of_the_week_log"), |
| 15 | url(r'^get_category_tags/$', views.category_tags, name='get_category_tags'), | 15 | url(r'^get_category_tags/$', views.category_tags, name='get_category_tags'), |
| 16 | + url(r'^get_comments_count/$', views.get_amount_of_comments, name='get_amount_of_comments'), | ||
| 16 | ] | 17 | ] |
| 17 | \ No newline at end of file | 18 | \ No newline at end of file |
analytics/views.py
| @@ -18,7 +18,7 @@ import calendar | @@ -18,7 +18,7 @@ import calendar | ||
| 18 | from collections import OrderedDict | 18 | from collections import OrderedDict |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | - | 21 | +from mural.models import Comment |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | def most_used_tags(request): | 24 | def most_used_tags(request): |
| @@ -192,7 +192,7 @@ def get_days_of_the_week_log(request): | @@ -192,7 +192,7 @@ def get_days_of_the_week_log(request): | ||
| 192 | 192 | ||
| 193 | params = request.GET | 193 | params = request.GET |
| 194 | date = params['date'] | 194 | date = params['date'] |
| 195 | - date = datetime.strptime( date, '%m/%d/%Y',) | 195 | + date = datetime.strptime( date, '%m/%d/%Y') |
| 196 | days = get_days_of_the_week(date) | 196 | days = get_days_of_the_week(date) |
| 197 | data = activity_in_timestamp(days, params = params) | 197 | data = activity_in_timestamp(days, params = params) |
| 198 | #mapping of number to days | 198 | #mapping of number to days |
| @@ -239,4 +239,22 @@ def most_tags_inside_category(category_id): | @@ -239,4 +239,22 @@ def most_tags_inside_category(category_id): | ||
| 239 | else: | 239 | else: |
| 240 | data[tag.name] = {'name': tag.name} | 240 | data[tag.name] = {'name': tag.name} |
| 241 | data[tag.name]['count'] = resources_count | 241 | data[tag.name]['count'] = resources_count |
| 242 | - return data | ||
| 243 | \ No newline at end of file | 242 | \ No newline at end of file |
| 243 | + return data | ||
| 244 | + | ||
| 245 | + | ||
| 246 | +def get_amount_of_comments(request): | ||
| 247 | + params = request.GET | ||
| 248 | + init_date = params.get('init_date') | ||
| 249 | + end_date = params.get('end_date') | ||
| 250 | + init_date = datetime.strptime( init_date, '%m/%d/%Y') | ||
| 251 | + end_date = datetime.strptime(end_time, '%m/%d/%Y') | ||
| 252 | + day_count = (end_date - init_date).days + 1 | ||
| 253 | + data = {} | ||
| 254 | + for i in range(day_count): | ||
| 255 | + single_day = init_date + timedelta(i) | ||
| 256 | + if params.get('category_id'): | ||
| 257 | + category_id = int(params['category_id']) | ||
| 258 | + data[single_day] = Mural.objects.filter(space__id = category_id, create_date = single_day).count() | ||
| 259 | + else: | ||
| 260 | + data[single_day] = Comment.objects.filter(create_date = single_day).count() | ||
| 261 | + return JsonResponse(data, safe=False) | ||
| 244 | \ No newline at end of file | 262 | \ No newline at end of file |