aboutsummaryrefslogtreecommitdiffstats
path: root/servo/views
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2016-03-21 19:14:11 +0200
committerFilipp Lepalaan <filipp@mac.com>2016-03-21 19:14:11 +0200
commitf30d6d73513a5535cae4d97ee2cc85f01660750c (patch)
tree4536e266855a08965b6acef0fd4f90d7c23659a2 /servo/views
parent367aba3c306a49cb8f8e16b34625f51396e3aacf (diff)
downloadServo-f30d6d73513a5535cae4d97ee2cc85f01660750c.tar.gz
Servo-f30d6d73513a5535cae4d97ee2cc85f01660750c.tar.bz2
Servo-f30d6d73513a5535cae4d97ee2cc85f01660750c.zip
Adding device stats
Diffstat (limited to 'servo/views')
-rw-r--r--servo/views/stats.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/servo/views/stats.py b/servo/views/stats.py
index 0acf9f7..6a9f9a8 100644
--- a/servo/views/stats.py
+++ b/servo/views/stats.py
@@ -421,3 +421,30 @@ def repairs(request):
totals['turnaround'] = ServoTimeDelta(totals['turnaround']/totals['dispatched'])
return render(request, "stats/newstats.html", locals())
+
+
+def devices(request):
+ data = prep_view(request)
+ data['form'] = DeviceStatsForm()
+ start_date = data['initial']['start_date']
+ end_date = data['initial']['end_date']
+
+ if request.method == 'POST':
+ form = DeviceStatsForm(request.POST)
+ if form.is_valid():
+ start_date = form.cleaned_data['start_date']
+ end_date = form.cleaned_data['end_date']
+
+ cursor = connection.cursor()
+ query = '''SELECT d.description device, count(o) AS orders, count(r) AS repairs
+ FROM servo_device d, servo_order o, servo_repair r, servo_orderdevice od
+ WHERE d.id = od.device_id
+ AND o.id = od.order_id
+ AND r.order_id = o.id
+ AND (o.created_at, o.created_at) OVERLAPS (%s, %s)
+ GROUP BY d.description''';
+ cursor.execute(query, [start_date, end_date])
+ data['results'] = cursor.fetchall()
+ data['title'] = _('Device statistics')
+
+ return render(request, "stats/devices.html", data)