Commit 0c76fcab authored by Praibait's avatar Praibait

Affiche les stats d'entrée selon un menu déroulant

parent 0a477e34
......@@ -336,3 +336,17 @@ def toggle_transaction(request):
return HttpResponse(json.dumps(out))
else:
return HttpResponse(u'"Erreur"')
def stats_pot(request, idpot = None):
if (request.method == "GET") or (request.session.get("logged", None) != "ok"):
return HttpResponse("Get the fuck out of here", status=44)
else:
success, sock_ou_response = nk.socket_still_alive(request)
if success:
sock = sock_ou_response
sock.write(json.dumps(["stats_entree_pot", idpot]))
out = nk.full_read(sock)["msg"]
out = [ [l[0], l[1]] for l in out]
return HttpResponse(json.dumps(out))
else:
return HttpResponse(u'"Erreur"')
{% extends "note/base.html" %}
{% load note_templatetags %}
{% load i18n %}
{% load staticfiles %}
{% block title %}Administration des [Pot]s{% endblock %}
......@@ -23,6 +24,11 @@
{% else %}
<h3>Graphiques d'entrées</h3>
{% endif %}
<select id="selecteur">
<option value=-1 selected></option>
<option value=1790>1790</option>
<option value=1754>1754</option>
<select/>
<div id="container" style="width:50%; height:400px;"></div>
<br>
{% if request.META.HTTP_HOST == 'note-test.crans.org' %}
......@@ -73,43 +79,62 @@
{% block additional_javascript %}
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="{% static 'js/custom/getXMLHttpRequest.js' %}"></script>
<script>
var liste = {{liste|safe}}
var liste1 = {{liste1|safe}}
var max = liste[liste.length-1][1], max1 = liste1[liste1.length-1][1];
$(function () {
var myChart = Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: "Graphique du nombre d'entrées en fonction du temps"
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
minute: '%H:%M:%S'
var selec = document.getElementById("selecteur");
selec.addEventListener("change", change_pot);
function change_pot() {
var xhr = getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
// la fonction de callback a besoin aussi de la question
affiche_stats(JSON.parse(xhr.responseText));
}
};
xhr.open("POST", NOTE_ROOT_URL + "stats_pot/" + selec.value , true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("X-CSRFToken", csrftoken);
xhr.send();
}
function affiche_stats(liste) {
var max = liste[liste.length-1][1];
$(function () {
var myChart = Highcharts.chart('container', {
chart: {
type: 'line'
},
max: Date.parse("2000/01/02 00:59:59")
},
yAxis: {
title: {
text: "Nombre d'entrées"
}
},
tooltip: {
headerFormat: '',
pointFormat: 'À {point.x:%H:%M}, {point.y} entrées'
},
series: [{
name: '[Pot] 1790 : <b>' + max + '</b> entrées',
data: liste
}, {
name: '[Pot] 1754 : <b>' + max1 + '</b> entrées',
data: liste1
}]
text: "Graphique du nombre d'entrées en fonction du temps"
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
minute: '%H:%M:%S'
},
max: Date.parse("2000/01/02 00:59:59")
},
yAxis: {
title: {
text: "Nombre d'entrées"
}
},
tooltip: {
headerFormat: '',
pointFormat: 'À {point.x:%H:%M}, {point.y} entrées'
},
series: [{
name: '[Pot] ' + selec.value + ' : <b>' + max + '</b> entrées',
data: liste
}
]
});
});
});
}
</script>
{% endblock %}
......
......@@ -89,6 +89,7 @@ urlpatterns += [
url(ur'^/search/*$', note.ajaj.search,name='search'),
url(ur'^/search_readhesion/*$', note.ajaj.search_readhesion,name='search_readhesion'),
url(ur'^/search_pot/(?P<idpot>[^/]*)/*$', note.ajaj.search_pot, name='search_pot'),
url(ur'^/stats_pot/(?P<idpot>[^/]*)/*$', note.ajaj.stats_pot, name='stats_pot'),
url(ur'^/get_boutons/(?P<flags>[^/]*)/*$', note.ajaj.get_boutons,name='get_boutons'),
url(ur'^/get_display_info/*$', note.ajaj.get_display_info,name='get_display_info'),
url(ur'^/get_photo/(?P<idbde>[^/]*)/*$', note.ajaj.get_photo,name='get_photo'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment