mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 20:33:11 +00:00
Second graphique, changement de fichier templates pour suivre les autres catégories
This commit is contained in:
parent
5f8d0976b9
commit
77bb201d8d
5 changed files with 100 additions and 4 deletions
50
logs/charts.py
Normal file
50
logs/charts.py
Normal file
|
@ -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
|
||||||
|
}]
|
|
@ -24,4 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
|
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.bundle.min.js"></script>
|
||||||
{{ ActiveUser.as_html }}
|
|
||||||
|
{% for chart in charts_list %}
|
||||||
|
|
||||||
|
{{ chart.as_html }}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
|
@ -53,7 +53,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% trans "Users" %}
|
{% trans "Users" %}
|
||||||
</a>
|
</a>
|
||||||
<a class="list-group-item list-group-item-info" href="{% url "logs:stats-charts" %}">
|
<a class="list-group-item list-group-item-info" href="{% url "logs:stats-charts" %}">
|
||||||
<i class="fa fa-users"></i>
|
<i class="fa fa-chart-line"></i>
|
||||||
{% trans "Charts" %}
|
{% trans "Charts" %}
|
||||||
</a>
|
</a>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
|
|
37
logs/templates/logs/stats_charts.html
Normal file
37
logs/templates/logs/stats_charts.html
Normal file
|
@ -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 %}
|
||||||
|
<h2>{% trans "Graphiques" %}</h2>
|
||||||
|
{% include "logs/aff_charts.html" with charts_list=charts_list %}
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
{% endblock %}
|
|
@ -53,6 +53,7 @@ from reversion.models import Version, ContentType
|
||||||
|
|
||||||
from .charts import (
|
from .charts import (
|
||||||
ActiveUserChart,
|
ActiveUserChart,
|
||||||
|
MachinePerUserChart,
|
||||||
)
|
)
|
||||||
from users.models import (
|
from users.models import (
|
||||||
User,
|
User,
|
||||||
|
@ -541,9 +542,12 @@ def charts(request):
|
||||||
"""Sert les graphiques des statistiques"""
|
"""Sert les graphiques des statistiques"""
|
||||||
|
|
||||||
ActiveUser = ActiveUserChart()
|
ActiveUser = ActiveUserChart()
|
||||||
|
MachinePerUser = MachinePerUserChart()
|
||||||
|
|
||||||
|
chart_list=[ActiveUser,MachinePerUser]
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'logs/aff_charts.html',
|
'logs/stats_charts.html',
|
||||||
{'ActiveUser': ActiveUser}
|
{'charts_list': chart_list}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue