diff --git a/logs/charts.py b/logs/charts.py new file mode 100644 index 00000000..58dadea8 --- /dev/null +++ b/logs/charts.py @@ -0,0 +1,50 @@ +from jchart import Chart +from jchart.config import Axes + +from users.models import User, Adherent +from re2o.utils import all_adherent + +from datetime import timedelta +from django.utils import timezone +from django.db.models import Count + +class ActiveUserChart(Chart): + """Create the hart of all active users for the 3 last months""" + chart_type = 'line' + scales = {'xAxes': [Axes(type='time', position='bottom')]} + + + def get_datasets(self, **kwargs): + data=[] + for i in range(100): + d = timedelta(days=i) + date = timezone.now()-d + data.append({'x':date,'y':all_adherent(search_time=date).count()}) + + return [{ + 'type': 'line', + 'label': "Nombre d'utilisateur actifs", + 'data': data + }] + +class MachinePerUserChart(Chart): + """Create the chart displaying the number of machines per users + for the 20 firsts users""" + + qs = User.objects.annotate(num=Count('machine')).order_by('-num')[:20] + + chart_type = 'bar' + scales = {'xAxes': [Axes(type='category', position='bottom',)]} + + def get_labels(self, **kwargs): + qs = User.objects.annotate(num=Count('machine')).order_by('-num')[:20] + return [u.name for u in qs] + + def get_datasets(self, **kwargs): + qs = User.objects.annotate(num=Count('machine')).order_by('-num')[:20] + data=[u.num for u in qs] + + return [{ + 'label': "Nombre de machines par utilisateurs", + 'data': data + }] diff --git a/logs/templates/logs/aff_charts.html b/logs/templates/logs/aff_charts.html index eeb29639..aea306e4 100644 --- a/logs/templates/logs/aff_charts.html +++ b/logs/templates/logs/aff_charts.html @@ -24,4 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc., -{{ ActiveUser.as_html }} + +{% for chart in charts_list %} + +{{ chart.as_html }} + +{% endfor %} diff --git a/logs/templates/logs/sidebar.html b/logs/templates/logs/sidebar.html index f168756e..685a4a19 100644 --- a/logs/templates/logs/sidebar.html +++ b/logs/templates/logs/sidebar.html @@ -53,7 +53,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Users" %} - + {% trans "Charts" %} {% acl_end %} diff --git a/logs/templates/logs/stats_charts.html b/logs/templates/logs/stats_charts.html new file mode 100644 index 00000000..a6b23699 --- /dev/null +++ b/logs/templates/logs/stats_charts.html @@ -0,0 +1,37 @@ +{% extends "logs/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} +{% load i18n %} + +{% block title %}{% trans "Statistics" %}{% endblock %} + +{% block content %} +