Commit e9e67da2b1628b46f617d3c53b460ff475eea691

Authored by Felipe Bormann
1 parent c0a86c45

finished adding correspondent and dynamic updating of heatmaps inside category view

analytics/views.py
@@ -72,12 +72,10 @@ def most_active_users_in_a_month(request): @@ -72,12 +72,10 @@ def most_active_users_in_a_month(request):
72 def activity_in_timestamp(days, **kwargs): 72 def activity_in_timestamp(days, **kwargs):
73 data = {} 73 data = {}
74 params = kwargs.get('params') 74 params = kwargs.get('params')
75 - print(params)  
76 for day in days: 75 for day in days:
77 if params.get('category_id'): 76 if params.get('category_id'):
78 category_id = params['category_id'] 77 category_id = params['category_id']
79 day_count = Log.objects.filter(datetime__date = day, context__contains = {"category_id" : int(category_id)}).count() 78 day_count = Log.objects.filter(datetime__date = day, context__contains = {"category_id" : int(category_id)}).count()
80 -  
81 else: 79 else:
82 day_count = Log.objects.filter(datetime__date = day).count() 80 day_count = Log.objects.filter(datetime__date = day).count()
83 data[day] = day_count 81 data[day] = day_count
dashboards/static/dashboards/js/behavior_categories.js
1 $(document).ready(function(){ 1 $(document).ready(function(){
2 charts.most_used_tags('/analytics/get_category_tags/?category_id='+$("#category-selector").val()); 2 charts.most_used_tags('/analytics/get_category_tags/?category_id='+$("#category-selector").val());
3 3
  4 + //first call to month selector
  5 + var month = new Array();
  6 + month[0] = "January";
  7 + month[1] = "February";
  8 + month[2] = "March";
  9 + month[3] = "April";
  10 + month[4] = "May";
  11 + month[5] = "June";
  12 + month[6] = "July";
  13 + month[7] = "August";
  14 + month[8] = "September";
  15 + month[9] = "October";
  16 + month[10] = "November";
  17 + month[11] = "December";
  18 +
  19 +
  20 + $.get('/analytics/amount_active_users_per_day', { month: month[(new Date()).getMonth()], category_id: $("#category-selector").val() }).done(function(data){
  21 + charts.month_heatmap(data, '#upper-right-part', 'month-chart');
  22 + });
  23 + //first call to weekly chart
  24 + var today_date = new Date();
  25 + var date = (today_date.getMonth() + 1) + '/' + today_date.getDate() + '/' + today_date.getFullYear();
  26 + $.get('/analytics/get_days_of_the_week_log', {date: date, category_id: $("#category-selector").val()}).done(function(data){
  27 + charts.month_heatmap(data, '#bottom-right-part', 'weekly-chart');
  28 + });
  29 +
  30 +
4 $("#category-selector").on("change", function(e){ 31 $("#category-selector").on("change", function(e){
5 //when it changes, the tag chart is replaced and all others are. 32 //when it changes, the tag chart is replaced and all others are.
6 var category_id = $(e.target).val(); 33 var category_id = $(e.target).val();
7 charts.most_used_tags('/analytics/get_category_tags/?category_id='+category_id); 34 charts.most_used_tags('/analytics/get_category_tags/?category_id='+category_id);
8 35
9 -  
10 - //first call to month selector  
11 - var month = new Array();  
12 - month[0] = "January";  
13 - month[1] = "February";  
14 - month[2] = "March";  
15 - month[3] = "April";  
16 - month[4] = "May";  
17 - month[5] = "June";  
18 - month[6] = "July";  
19 - month[7] = "August";  
20 - month[8] = "September";  
21 - month[9] = "October";  
22 - month[10] = "November";  
23 - month[11] = "December";  
24 -  
25 -  
26 $.get('/analytics/amount_active_users_per_day', { month: month[(new Date()).getMonth()], category_id: category_id }).done(function(data){ 36 $.get('/analytics/amount_active_users_per_day', { month: month[(new Date()).getMonth()], category_id: category_id }).done(function(data){
27 - charts.month_heatmap(data, '#right-side-heatmaps', 'month-chart'); 37 + charts.month_heatmap(data, '#upper-right-part', 'month-chart');
28 }); 38 });
29 39
  40 +
  41 + $.get('/analytics/get_days_of_the_week_log', {date: date, category_id: $("#category-selector").val()}).done(function(data){
  42 + charts.month_heatmap(data, '#bottom-right-part', 'weekly-chart');
  43 + });
  44 +
  45 +
30 }); 46 });
31 47
32 48
@@ -37,7 +53,7 @@ $(document).ready(function(){ @@ -37,7 +53,7 @@ $(document).ready(function(){
37 53
38 var date = $(this).val().split("/"); 54 var date = $(this).val().split("/");
39 $.get('/analytics/amount_active_users_per_day', {month: date[0], year: date[1], category_id: $("#category-selector").val() }).done(function(data){ 55 $.get('/analytics/amount_active_users_per_day', {month: date[0], year: date[1], category_id: $("#category-selector").val() }).done(function(data){
40 - charts.month_heatmap(data, '#right-side-heatmaps', 'month-chart'); 56 + charts.month_heatmap(data, '#upper-right-part', 'month-chart');
41 57
42 }); 58 });
43 }); 59 });
@@ -49,8 +65,8 @@ $(document).ready(function(){ @@ -49,8 +65,8 @@ $(document).ready(function(){
49 }).on('dp.change', function(ev){ 65 }).on('dp.change', function(ev){
50 new_date = new Date(ev.date); 66 new_date = new Date(ev.date);
51 var date = (new_date.getMonth() + 1) + '/' + new_date.getDate() + '/' + new_date.getFullYear(); 67 var date = (new_date.getMonth() + 1) + '/' + new_date.getDate() + '/' + new_date.getFullYear();
52 - $.get('/analytics/get_days_of_the_week_log', {date: date}).done(function(data){  
53 - charts.month_heatmap(data, '#bottom-right-chart-body', 'weekly-chart'); 68 + $.get('/analytics/get_days_of_the_week_log', {date: date,category_id: $("#category-selector").val()}).done(function(data){
  69 + charts.month_heatmap(data, '#bottom-right-part', 'weekly-chart');
54 }); 70 });
55 71
56 }); 72 });
dashboards/templates/dashboards/category.html
@@ -76,7 +76,10 @@ @@ -76,7 +76,10 @@
76 <div id="left-chart"> 76 <div id="left-chart">
77 77
78 </div> 78 </div>
79 - <div id="month_selector_div"> 79 +
  80 +
  81 + <div id="right-side-heatmaps">
  82 + <div id="month_selector_div">
80 <h4>{% trans "Amount of access in: " %} 83 <h4>{% trans "Amount of access in: " %}
81 <select id="month_selector"> 84 <select id="month_selector">
82 {% for month in months %} 85 {% for month in months %}
@@ -86,9 +89,16 @@ @@ -86,9 +89,16 @@
86 </select> 89 </select>
87 </h4> 90 </h4>
88 </div> 91 </div>
  92 + <div id="upper-right-part"></div>
89 93
90 - <div id="right-side-heatmaps">  
91 - 94 + <div class='input-group date'>
  95 + <label>{% trans "Select the begin of the week: " %}</label>
  96 + <input type='text' class="datepicker form-control" />
  97 + <span class="input-group-addon">
  98 + <span class="glyphicon glyphicon-calendar"></span>
  99 + </span>
  100 + </div>
  101 + <div id="bottom-right-part"></div>
92 </div> 102 </div>
93 </div> 103 </div>
94 </article> 104 </article>