Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
4dabdf60
Commit
4dabdf60
authored
Apr 10, 2018
by
Luko van der Maas
Browse files
added statistics for current and all pizza orders
parent
735514e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
website/members/static/members/js/statistics.js
View file @
4dabdf60
...
...
@@ -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
}]
}]
});
}
});
website/members/templates/members/statistics.html
View file @
4dabdf60
...
...
@@ -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>
...
...
website/members/views.py
View file @
4dabdf60
...
...
@@ -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
)
website/pizzas/services.py
0 → 100644
View file @
4dabdf60
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment