diff options
author | ankitjavalkar | 2019-09-26 15:01:49 +0530 |
---|---|---|
committer | GitHub | 2019-09-26 15:01:49 +0530 |
commit | 0a862f665ae5bb373ffac47888915a140beb53a8 (patch) | |
tree | 4cc8b2f6db31171cb5009da00e9082dc3d7f6229 /statistics_app | |
parent | 4a8ae597541d744c4e172dfd71b8d0a617c2d1dd (diff) | |
parent | 194ee67048b80655f3da6be1f5018fdc278ffc58 (diff) | |
download | workshop_booking-0a862f665ae5bb373ffac47888915a140beb53a8.tar.gz workshop_booking-0a862f665ae5bb373ffac47888915a140beb53a8.tar.bz2 workshop_booking-0a862f665ae5bb373ffac47888915a140beb53a8.zip |
Merge pull request #100 from FOSSEE/temp-fixes
Multiple Temporary Fixes
Diffstat (limited to 'statistics_app')
-rw-r--r-- | statistics_app/templates/statistics_app/team_stats.html | 124 | ||||
-rw-r--r-- | statistics_app/urls.py | 5 | ||||
-rw-r--r-- | statistics_app/views.py | 26 |
3 files changed, 153 insertions, 2 deletions
diff --git a/statistics_app/templates/statistics_app/team_stats.html b/statistics_app/templates/statistics_app/team_stats.html new file mode 100644 index 0000000..4e3e870 --- /dev/null +++ b/statistics_app/templates/statistics_app/team_stats.html @@ -0,0 +1,124 @@ +{% extends 'workshop_app/base.html' %} + +{% block title %} + Workshop Statistics +{% endblock %} + + +{% block extra %} + + <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> + <script src="https://code.jquery.com/jquery-1.12.4.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> + + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> + <script src="{{URL_ROOT}}/static/workshop_app/js/bootstrap-3.3.7.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> + <!-- For Charts --> + + <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script> + + <!-- For Google GeoChart India Map --> + <script type='text/javascript' src='https://www.google.com/jsapi'></script> + +{% endblock %} + +{% block content %} + +<div class="container"> +<div class="row"> + <br> + <div class="col-md-12 "> + <br> + <canvas id="myChartPie" ></canvas> + <script> + var dynamic_pie_color = []; + var data = {{ workshop_data.data}}; + + var dynamicColors = function() { + var r = Math.floor(Math.random() * 255); + var g = Math.floor(Math.random() * 255); + var b = Math.floor(Math.random() * 255); + return "rgb(" + r + "," + g + "," + b + ")"; + }; + + + for (var i in data) { + dynamic_pie_color.push(dynamicColors()); + } + + var data = { + datasets: [{ + data: data, + label: 'My dataset', // for legend + backgroundColor: dynamic_pie_color, + }], + labels: [{% for label in workshop_data.labels %}"{{ label }}",{% endfor %}] + }; + + var pieOptions = { + events: false, + animation: { + duration: 500, + easing: "easeOutQuart", + onComplete: function () { + var ctx = this.chart.ctx; + ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily); + ctx.textAlign = 'center'; + ctx.textBaseline = 'bottom'; + + this.data.datasets.forEach(function (dataset) { + + for (var i = 0; i < dataset.data.length; i++) { + var model = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._model, + total = dataset._meta[Object.keys(dataset._meta)[0]].total, + mid_radius = model.innerRadius + (model.outerRadius - model.innerRadius)/2, + start_angle = model.startAngle, + end_angle = model.endAngle, + mid_angle = start_angle + (end_angle - start_angle)/2; + + var x = mid_radius * Math.cos(mid_angle); + var y = mid_radius * Math.sin(mid_angle); + + ctx.fillStyle = '#fff'; + if (i == 3){ // Darker text color for lighter background + ctx.fillStyle = '#444'; + } + + var val = dataset.data[i]; + var percent = String(Math.round(val/total*100)) + "%"; + + if(val != 0) { + ctx.fillText(dataset.data[i], model.x + x, model.y + y); + // Display percent in another line, line break doesn't work for fillText + ctx.fillText(percent, model.x + x, model.y + y + 15); + } + } + }); + } + } + }; + + var pieChartCanvas = $("#myChartPie"); + var pieChart = new Chart(pieChartCanvas, { + type: 'pie', // or doughnut + data: data, + options: pieOptions + }); + </script> + <style> + #visualization path { + stroke-width:1; /* control the countries borders width */ + stroke:white; /* choose a color for the border */ + } + </style> + <div id="visualization" style="width: 400px; height: 300px; display: block; margin: 0 auto;" ></div> + + </div> +</div> +</div> +<br> +{% endblock %} diff --git a/statistics_app/urls.py b/statistics_app/urls.py index 94b358e..9e0dbbf 100644 --- a/statistics_app/urls.py +++ b/statistics_app/urls.py @@ -2,12 +2,13 @@ from django.conf.urls import url from django.contrib import admin from statistics_app import views -import django - urlpatterns = [ url(r'^statistics/$', views.workshop_stats), url(r'^statistics/public_stats/$', views.workshop_public_stats), url(r'^statistics/profile_stats/$', views.profile_stats), + url(r'^statistics/v1/team_stats/$', views.team_stats), + # url(r'^statistics/v1/filter/$', views.team_stats), + url(r'^statistics/v1/all/$', views.all_stats), ] diff --git a/statistics_app/views.py b/statistics_app/views.py index 1507196..8c3a6f0 100644 --- a/statistics_app/views.py +++ b/statistics_app/views.py @@ -10,6 +10,8 @@ from workshop_app.models import ( BookedWorkshop, ProposeWorkshopDate, Testimonial ) +from teams.models import Team + from django.template.loader import get_template from django.template import RequestContext from datetime import datetime, date @@ -582,3 +584,27 @@ def profile_stats(request): else: logout(request) return render(request, "workshop_app/logout.html") + +@login_required +def team_stats(request, team_id): + user = request.user + team = Team.objects.get(team_id) + if user not in team.members.all(): + if user.groups.filter(name='instructor').count() > 0: + return redirect('/manage/') + return redirect('/book/') + + member_workshop_data = {} + for member in team.members.all(): + workshop_count = ProposeWorkshopDate.objects.filter(proposed_workshop_instructor=member.id).count() + if member_workshop_data.get('data'): + member_workshop_data['data'].append(workshop_count) + else: + member_workshop_data['data'] = [workshop_count] + if member_workshop_data.get('labels'): + member_workshop_data['labels'].append(member.user.username) + else: + member_workshop_data['labels'] = [member.user.username] + return render(request, 'statistics_app/team_stats.html', {'workshop_data': member_workshop_data}) + + |