Commit feaf5b504f5ffdfbb6cc70260d6c58a640e155ea
1 parent
caa3f758
Exists in
master
and in
2 other branches
finished weekly chart backend, still has event handler to fix
Showing
9 changed files
with
66 additions
and
26 deletions
Show diff stats
analytics/static/.sass-cache/01cecb7b42e56765f6ed49ed3c70281ebdc742c7/general.sassc
No preview for this file type
analytics/static/analytics/general.css
analytics/static/analytics/general.css.map
| 1 | 1 | { |
| 2 | 2 | "version": 3, |
| 3 | -"mappings": "AAEA,YAAY;EACR,MAAM,EAAE,iBAAiB;EACzB,aAAa,EAAE,IAAI;EACnB,OAAO,EAAE,IAAI;EACb,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;EACX,gBAAgB,EAAE,OAAO;;AAE7B,sBAAsB;EAClB,MAAM,EAAE,GAAG;EACX,OAAO,EAAE,KAAK;EACd,yBAAE;IACE,KAAK,EAdC,OAAO;EAgBjB,yBAAE;IACE,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,GAAG;IACV,aAAa,EAAE,GAAG;IAElB,4BAAE;MACE,YAAY,EAAE,EAAE;MAChB,KAAK,EAAE,GAAG;MACV,KAAK,EAAE,KAAK;MACZ,SAAS,EAAE,IAAI;MACf,gBAAgB,EAAE,OAAO;MACzB,KAAK,EAAE,IAAI;MACX,UAAU,EAAE,MAAM;MAClB,aAAa,EAAE,IAAI;MACnB,MAAM,EAAE,IAAI;IAGhB,qCAAW;MACP,gBAAgB,EAAE,OAAO;MACzB,KAAK,EAAE,IAAI;MACX,UAAU,EAAE,MAAM;MAClB,aAAa,EAAE,IAAI;;AAM/B,sBAAsB;EAClB,UAAU,EAAE,2CAA2C;EACvD,MAAM,EAAE,IAAI;EACZ,aAAa,EAAE,IAAI;EACnB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,GAAG;EAChB,UAAU,EAAE,IAAI;EAEhB,yBAAE;IACE,WAAW,EAAE,EAAE;;AAGvB,UAAU;EACN,aAAa,EAAE,IAAI;EACnB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AmB;EACf,UAAU,EAAE,MAAM;EAClB,KAAK,EAAE,OAAO", | |
| 4 | 4 | "sources": ["general.sass"], |
| 5 | 5 | "names": [], |
| 6 | 6 | "file": "general.css" | ... | ... |
analytics/static/analytics/general.sass
analytics/static/analytics/js/behavior.js
| ... | ... | @@ -8,7 +8,7 @@ $(document).ready(function(){ |
| 8 | 8 | |
| 9 | 9 | $('#month_selector').change(function(){ |
| 10 | 10 | $.get('/analytics/amount_active_users_per_day', {month: $(this).val() }).done(function(data){ |
| 11 | - charts.month_heatmap(data); | |
| 11 | + charts.month_heatmap(data, '#right-chart-body'); | |
| 12 | 12 | |
| 13 | 13 | }); |
| 14 | 14 | }); |
| ... | ... | @@ -17,7 +17,10 @@ $(document).ready(function(){ |
| 17 | 17 | format: 'L', |
| 18 | 18 | defaultDate: new Date(), |
| 19 | 19 | }).on('dp.change', function(ev){ |
| 20 | - console.log(ev.date._i); | |
| 20 | + $.get('/analytics/get_days_of_the_week_log', {date: ev.date._i}).done(function(data){ | |
| 21 | + charts.month_heatmap(data, '#bottom-right-chart-body'); | |
| 22 | + }); | |
| 23 | + | |
| 21 | 24 | }); |
| 22 | 25 | |
| 23 | 26 | ... | ... |
analytics/static/analytics/js/charts.js
| ... | ... | @@ -436,16 +436,30 @@ var charts = { |
| 436 | 436 | |
| 437 | 437 | }); |
| 438 | 438 | }, |
| 439 | - month_heatmap: function(data){ | |
| 439 | + month_heatmap: function(data, target){ | |
| 440 | 440 | |
| 441 | - if($('#month-chart').length != 0){ | |
| 441 | + | |
| 442 | + if(target == '#right-chart-body' && $('#month-chart').length != 0){ | |
| 442 | 443 | $('#month-chart').fadeOut(); |
| 443 | 444 | $('#month-chart').remove(); |
| 444 | 445 | } |
| 445 | - var svg = d3.select('#right-chart-body').append('svg') | |
| 446 | + | |
| 447 | + if(target == "#bottom-right-chart-body" && $('#weekly-chart').length != 0){ | |
| 448 | + $('#weekly-chart').fadeOut(); | |
| 449 | + $('#weekly-chart').remove(); | |
| 450 | + } | |
| 451 | + | |
| 452 | + var svg = d3.select(target).append('svg') | |
| 446 | 453 | .attr('width', 300) |
| 447 | - .attr('height', 200) | |
| 448 | - .attr('id', 'month-chart'); | |
| 454 | + .attr('height', 200); | |
| 455 | + | |
| 456 | + if (target == "#right-chart-body"){ | |
| 457 | + svg.attr('id', 'month-chart'); | |
| 458 | + } | |
| 459 | + | |
| 460 | + if (target == "#bottom-right-chart-body"){ | |
| 461 | + svg.attr('id', 'weekly-chart'); | |
| 462 | + } | |
| 449 | 463 | |
| 450 | 464 | //color range |
| 451 | 465 | var color = d3.scaleLinear().range(["#29c8b8", '#149e91']).domain([0, d3.max(data, function(d){ return d.count; })]); |
| ... | ... | @@ -460,12 +474,12 @@ var charts = { |
| 460 | 474 | .attr("width", rect_width) |
| 461 | 475 | .attr("height", rect_height) |
| 462 | 476 | .attr("class", "day_rect") |
| 463 | - .attr("x", function(d){ | |
| 477 | + .attr("x", function(d, i){ | |
| 464 | 478 | |
| 465 | - return rect_width* (d.day % 7); | |
| 466 | - }).attr("y", function(d){ | |
| 467 | - return rect_height*(Math.floor(d.day / 7)); | |
| 468 | - }).attr("fill", function(d){ | |
| 479 | + return rect_width* (i % 7); | |
| 480 | + }).attr("y", function(d, i){ | |
| 481 | + return rect_height*(Math.floor(i / 7)); | |
| 482 | + }).attr("fill", function(d, i ){ | |
| 469 | 483 | return color(d.count); |
| 470 | 484 | }); |
| 471 | 485 | |
| ... | ... | @@ -474,10 +488,10 @@ var charts = { |
| 474 | 488 | return d.day; |
| 475 | 489 | }).attr("fill", "white") |
| 476 | 490 | .attr("text-anchor", "middle") |
| 477 | - .attr("x", function(d){ | |
| 478 | - return rect_width* (d.day % 7) + rect_width/2; | |
| 479 | - }).attr("y", function(d){ | |
| 480 | - return rect_height*(Math.floor(d.day / 7)) + rect_height/2; | |
| 491 | + .attr("x", function(d, i){ | |
| 492 | + return rect_width* ( i % 7) + rect_width/2; | |
| 493 | + }).attr("y", function(d, i){ | |
| 494 | + return rect_height*(Math.floor( i / 7)) + rect_height/2; | |
| 481 | 495 | }); |
| 482 | 496 | |
| 483 | 497 | } | ... | ... |
analytics/templates/analytics/general.html
analytics/urls.py
| ... | ... | @@ -11,5 +11,6 @@ urlpatterns = [ |
| 11 | 11 | url(r'^most_accessed_categories/$', views.most_accessed_categories, name = "most_accessed_categories"), |
| 12 | 12 | url(r'^most_accessed_resources/$', views.most_accessed_resource_kind, name= "most_accessed_resources"), |
| 13 | 13 | url(r'^most_active_users/$', views.most_active_users, name= "most_active_users"), |
| 14 | - url(r'^amount_active_users_per_day/$', views.most_active_users_in_a_month, name="most_active_users_in_a_month") | |
| 14 | + url(r'^amount_active_users_per_day/$', views.most_active_users_in_a_month, name="most_active_users_in_a_month"), | |
| 15 | + url(r'^get_days_of_the_week_log/$', views.get_days_of_the_week_log, name="get_days_of_the_week_log"), | |
| 15 | 16 | ] |
| 16 | 17 | \ No newline at end of file | ... | ... |
analytics/views.py
| ... | ... | @@ -13,8 +13,9 @@ import operator |
| 13 | 13 | from django.utils.translation import ugettext_lazy as _ |
| 14 | 14 | from django.shortcuts import render, get_object_or_404, redirect |
| 15 | 15 | |
| 16 | -from datetime import date | |
| 16 | +from datetime import date, timedelta, datetime | |
| 17 | 17 | import calendar |
| 18 | +from collections import OrderedDict | |
| 18 | 19 | |
| 19 | 20 | |
| 20 | 21 | class GeneralView(generic.TemplateView): |
| ... | ... | @@ -71,7 +72,6 @@ def most_active_users_in_a_month(request): |
| 71 | 72 | |
| 72 | 73 | for day in days: |
| 73 | 74 | built_date = date(date.today().year, mappings[params['month']], day) |
| 74 | - print(built_date) | |
| 75 | 75 | day_count = Log.objects.filter(datetime__date = built_date).count() |
| 76 | 76 | data[day] = day_count |
| 77 | 77 | |
| ... | ... | @@ -159,6 +159,8 @@ def most_active_users(request): |
| 159 | 159 | return JsonResponse(fifty_users, safe=False) |
| 160 | 160 | |
| 161 | 161 | |
| 162 | + | |
| 163 | + | |
| 162 | 164 | def get_days_of_the_month(month): |
| 163 | 165 | |
| 164 | 166 | #get current year |
| ... | ... | @@ -176,7 +178,24 @@ def get_days_of_the_month(month): |
| 176 | 178 | return days_set |
| 177 | 179 | |
| 178 | 180 | |
| 181 | + | |
| 182 | +def get_days_of_the_week_log(request): | |
| 183 | + date = request.GET['date'] | |
| 184 | + date = datetime.strptime( date, '%m/%d/%Y',) | |
| 185 | + days = get_days_of_the_week(date) | |
| 186 | + data = {} | |
| 187 | + | |
| 188 | + for day in days: | |
| 189 | + day_count = Log.objects.filter(datetime__date = day).count() | |
| 190 | + data[day] = day_count | |
| 191 | + data = [{"day": day.day, "count": day_count} for day, day_count in data.items()] | |
| 192 | + | |
| 193 | + return JsonResponse(data, safe= False) | |
| 194 | + | |
| 179 | 195 | def get_days_of_the_week(date): |
| 180 | 196 | |
| 181 | - days_set = set() | |
| 197 | + days_set = [] | |
| 198 | + days_set.append(date) | |
| 199 | + for j in range(1, 7): | |
| 200 | + days_set.append(date + timedelta(days=j)) | |
| 182 | 201 | return days_set |
| 183 | 202 | \ No newline at end of file | ... | ... |