diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-09-12 11:08:56 +0200 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2016-09-12 11:08:56 +0200 |
commit | e74c3f8f656a35bc8d482f997b4cea7515916026 (patch) | |
tree | 2f947e746c6e41105d19f89bf8f41b6a75b03a09 /pharos-dashboard/dashboard/views.py | |
parent | 2481f29a0f558f2d1b0140b9ab34615d96a4f222 (diff) |
Add booking utilization chart
JIRA: PHAROS-263
Change-Id: I3a3a5115a1cf7742f9ac5a3ec753699c36b49815
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/dashboard/views.py')
-rw-r--r-- | pharos-dashboard/dashboard/views.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/pharos-dashboard/dashboard/views.py b/pharos-dashboard/dashboard/views.py index ef1845c..8954f6c 100644 --- a/pharos-dashboard/dashboard/views.py +++ b/pharos-dashboard/dashboard/views.py @@ -59,7 +59,8 @@ class ResourceView(TemplateView): utilization = resource.slave.get_utilization(timedelta(days=7)) bookings = Booking.objects.filter(resource=resource, end__gt=timezone.now()) context = super(ResourceView, self).get_context_data(**kwargs) - context.update({'title': str(resource), 'resource': resource, 'utilization': utilization, 'bookings': bookings}) + context.update({'title': str(resource), 'resource': resource, 'utilization': utilization, + 'bookings': bookings}) return context @@ -76,3 +77,22 @@ class LabOwnerView(TemplateView): context = super(LabOwnerView, self).get_context_data(**kwargs) context.update({'title': "Overview", 'pods': pods}) return context + + +class BookingUtilizationJSON(View): + def get(self, request, *args, **kwargs): + resource = get_object_or_404(Resource, id=kwargs['resource_id']) + utilization = resource.get_booking_utilization(int(kwargs['weeks'])) + utilization = [ + { + 'label': 'Booked', + 'data': utilization['booked_seconds'], + 'color': '#d9534f' + }, + { + 'label': 'Available', + 'data': utilization['available_seconds'], + 'color': '#5cb85c' + }, + ] + return JsonResponse({'data': utilization}) |