Commit 4dabdf60 authored by Luko van der Maas's avatar Luko van der Maas

added statistics for current and all pizza orders

parent 735514e6
......@@ -173,4 +173,76 @@ $(function () {
}]
}]
});
$('#pizzaTotalTypeChart').highcharts({
chart: {
type: 'pie'
},
title: {
text: "Total pizza orders of type",
},
plotOptions: {
pie: pieOptions
},
series: [{
name: 'Pizzas',
colorByPoint: true,
data : [{
name: total_pizza_orders[0].name,
y: total_pizza_orders[0].total
},{
name: total_pizza_orders[1].name,
y: total_pizza_orders[1].total
},{
name: total_pizza_orders[2].name,
y: total_pizza_orders[2].total
},{
name: total_pizza_orders[3].name,
y: total_pizza_orders[3].total
},{
name: total_pizza_orders[4].name,
y: total_pizza_orders[4].total
},{
name: total_pizza_orders[5].name,
y: total_pizza_orders[5].total
}]
}]
});
if (current_pizza_orders != null) {
$('#pizzaCurrentTypeChart').highcharts({
chart: {
type: 'pie'
},
title: {
text: "Current pizza orders of type",
},
plotOptions: {
pie: pieOptions
},
series: [{
name: 'Pizzas',
colorByPoint: true,
data : [{
name: current_pizza_orders[0].name,
y: current_pizza_orders[0].total
},{
name: current_pizza_orders[1].name,
y: current_pizza_orders[1].total
},{
name: current_pizza_orders[2].name,
y: current_pizza_orders[2].total
},{
name: current_pizza_orders[3].name,
y: current_pizza_orders[3].total
},{
name: current_pizza_orders[4].name,
y: current_pizza_orders[4].total
},{
name: current_pizza_orders[5].name,
y: current_pizza_orders[5].total
}]
}]
});
}
});
......@@ -14,6 +14,10 @@
<div id="totalYearChart" style="width:100%; height:400px;"></div>
<div id="membersYearChart" style="width:100%; height:400px;"></div>
<div id="supportersYearChart" style="width:100%; height:400px;"></div>
<div id="pizzaTotalTypeChart" style="width:100%; height:400px;"></div>
{% if current_pizza_orders != 'null' %} {# None is json-serialized to 'null' #}
<div id="pizzaCurrentTypeChart" style="width:100%; height:400px;"></div>
{% endif %}
<br/><br/>
{% endblock %}
......@@ -29,6 +33,8 @@
{% autoescape off %}
var total_stats_year = {{ total_stats_year }};
var total_stats_member_type = {{ total_stats_member_type }};
var total_pizza_orders = {{ total_pizza_orders }};
var current_pizza_orders = {{ current_pizza_orders }};
{% endautoescape %}
</script>
......
......@@ -16,6 +16,7 @@ from members import services
from .services import member_achievements
from . import models
from .forms import ProfileForm
import pizzas.services
class ObtainThaliaAuthToken(ObtainAuthToken):
......@@ -217,6 +218,10 @@ def statistics(request):
"total_stats_year": json.dumps(services.gen_stats_year(member_types)),
"total_stats_member_type": json.dumps(
services.gen_stats_member_type(member_types)),
"total_pizza_orders": json.dumps(
pizzas.services.gen_stats_pizza_orders()),
"current_pizza_orders": json.dumps(
pizzas.services.gen_stats_current_pizza_orders()),
}
return render(request, 'members/statistics.html', context)
from . models import Product, Order, PizzaEvent
def gen_stats_pizza_orders():
total = []
for product in Product.objects.all():
total.append({
'name': product.name,
'total': Order.objects.filter(product=product).count(),
})
total.sort(key=lambda prod: prod['total'], reverse=True)
return total
def gen_stats_current_pizza_orders():
total = []
current_pizza_event = PizzaEvent.current()
if not current_pizza_event:
return None
for product in Product.objects.filter():
total.append({
'name': product.name,
'total': Order.objects.filter(
product=product,
pizza_event=current_pizza_event,
).count(),
})
total.sort(key=lambda prod: prod['total'], reverse=True)
return total
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