Stats: hourly
This commit is contained in:
1 parent
3229d54365
commit
9854a17f4e
4 files changed
+87
-11
No files matched your search
@@ -7,6 +7,7 @@ urlpatterns = patterns('main.views',
|
|||||||
url(r'^log/all$', 'log', kwargs={'limit': None}, name='log-all'),
|
url(r'^log/all$', 'log', kwargs={'limit': None}, name='log-all'),
|
||||||
url(r'^stats/$', 'stats', name='stats'),
|
url(r'^stats/$', 'stats', name='stats'),
|
||||||
url(r'^stats/orders/$', 'stats_orders', name='stats-orders'),
|
url(r'^stats/orders/$', 'stats_orders', name='stats-orders'),
|
||||||
|
url(r'^stats/orders/hourly$', 'stats_orders_hourly', name='stats-orders-hourly'),
|
||||||
url(r'^stats/products/$', 'stats_products', name='stats-products'),
|
url(r'^stats/products/$', 'stats_products', name='stats-products'),
|
||||||
url(r'^stats/products/(?P<product>[0-9]+)/$', 'stats_products', name='stats-product'),
|
url(r'^stats/products/(?P<product>[0-9]+)/$', 'stats_products', name='stats-product'),
|
||||||
url(r'^products/(?P<product_id>[0-9]+)/$', 'products', name='json-product'),
|
url(r'^products/(?P<product_id>[0-9]+)/$', 'products', name='json-product'),
|
||||||
|
|||||||
+17
-1
@@ -1,6 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from datetime import timedelta
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timedelta
|
||||||
|
from itertools import groupby
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
from django.contrib.auth import login, logout as auth_logout
|
from django.contrib.auth import login, logout as auth_logout
|
||||||
@@ -210,6 +211,21 @@ def stats_orders(request):
|
|||||||
f_per_user.append([who, num])
|
f_per_user.append([who, num])
|
||||||
return HttpResponse(json.dumps(f_per_user), content_type='application/javascript; charset=utf8')
|
return HttpResponse(json.dumps(f_per_user), content_type='application/javascript; charset=utf8')
|
||||||
|
|
||||||
|
def stats_orders_hourly(request):
|
||||||
|
orders = Order.objects.all()
|
||||||
|
f_hourly = dict([(key,0) for key in range(0,24)]) # init
|
||||||
|
# group by hour
|
||||||
|
for key, values in groupby(orders, key=lambda row: row.created.hour):
|
||||||
|
count = len(list(values))
|
||||||
|
f_hourly[key] = f_hourly[key] + count
|
||||||
|
|
||||||
|
response = {
|
||||||
|
'start': str(orders[0].created),
|
||||||
|
'hourly' : [[k,v] for k,v in f_hourly.iteritems()],
|
||||||
|
'total' : sum(f_hourly.values()),
|
||||||
|
}
|
||||||
|
return HttpResponse(json.dumps(response), content_type='application/javascript; charset=utf8')
|
||||||
|
|
||||||
def logout(request):
|
def logout(request):
|
||||||
auth_logout(request)
|
auth_logout(request)
|
||||||
return render_to_response('registration/logout.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('registration/logout.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|||||||
+55
-1
@@ -1,7 +1,9 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
/* TODO select data element with index 0 of each pie-chart */
|
||||||
var charts = [];
|
var charts = [];
|
||||||
var products_url = '/stats/products/';
|
var products_url = '/stats/products/';
|
||||||
var order_url = '/stats/orders/';
|
var order_url = '/stats/orders/';
|
||||||
|
var order_hourly_url = '/stats/orders/hourly';
|
||||||
|
|
||||||
/* orders */
|
/* orders */
|
||||||
$.getJSON(order_url, function(data) {
|
$.getJSON(order_url, function(data) {
|
||||||
@@ -35,7 +37,7 @@ $(document).ready(function() {
|
|||||||
color: '#000000',
|
color: '#000000',
|
||||||
connectorColor: '#000000',
|
connectorColor: '#000000',
|
||||||
formatter: function() {
|
formatter: function() {
|
||||||
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
|
return '<b>'+ this.point.name +'</b>: '+ this.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,4 +99,56 @@ $(document).ready(function() {
|
|||||||
charts.push(new Highcharts.Chart(options));
|
charts.push(new Highcharts.Chart(options));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
/* orders hourly */
|
||||||
|
$.getJSON(order_hourly_url, function(data) {
|
||||||
|
var render_to = 'order_hourly_chart';
|
||||||
|
|
||||||
|
// define the options
|
||||||
|
var options = {
|
||||||
|
credits: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
chart: {
|
||||||
|
renderTo: render_to,
|
||||||
|
type: 'column'
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
text: 'Ordre - time for time'
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
formatter: function() {
|
||||||
|
return this.y + " stk";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
title: {
|
||||||
|
text: 'Ordre'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
title: {
|
||||||
|
text: 'Tid (h)'
|
||||||
|
},
|
||||||
|
labels: {
|
||||||
|
formatter: function() {
|
||||||
|
return this.value + ":00";
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
column: {
|
||||||
|
minPointLength: 3,
|
||||||
|
},
|
||||||
|
series: {
|
||||||
|
groupPadding: 0,
|
||||||
|
pointPadding: 0.05,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
series: [{
|
||||||
|
name: 'Ordre',
|
||||||
|
data: data.hourly
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
charts.push(new Highcharts.Chart(options));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+14
-9
@@ -5,25 +5,30 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section id="stats" class="row-fluid">
|
<section id="stats" class="row-fluid">
|
||||||
<section id="order" class="row-fluid">
|
|
||||||
<div class="span12">
|
|
||||||
<h2>Ordre</h2>
|
|
||||||
<div id="order_chart"></div>
|
|
||||||
<!--<div id="container" style="width: 800px; height: 400px; margin: 0 auto;"></div> -->
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section id="product" class="row-fluid">
|
<section id="product" class="row-fluid">
|
||||||
<h2>Produkter</h2>
|
<h2>Produkter</h2>
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
<section id="product_{{ product.id }}">
|
<section id="product_{{ product.id }}">
|
||||||
<div class="span6">
|
<div class="span6">
|
||||||
<div id="product_chart{{ product.id }}"></div>
|
<div id="product_chart{{ product.id }}"></div>
|
||||||
<!--<div id="container" style="width: 800px; height: 400px; margin: 0 auto;"></div> -->
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</section>
|
</section>
|
||||||
|
<section id="order_hourly" class="row-fluid">
|
||||||
|
<h2>Time for time</h2>
|
||||||
|
<div class="span11">
|
||||||
|
<div id="order_hourly_chart"></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="order" class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<h2>Ordre</h2>
|
||||||
|
<div id="order_chart"></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block tailinc %}
|
{% block tailinc %}
|
||||||
|
|||||||
Reference in new issue
Block a user