summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/dashboard/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/dashboard/views.py')
-rw-r--r--tools/pharos-dashboard/dashboard/views.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/tools/pharos-dashboard/dashboard/views.py b/tools/pharos-dashboard/dashboard/views.py
index ef1845c8..0eddc130 100644
--- a/tools/pharos-dashboard/dashboard/views.py
+++ b/tools/pharos-dashboard/dashboard/views.py
@@ -1,7 +1,9 @@
from datetime import timedelta
+from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.utils import timezone
+from django.views import View
from django.views.generic import TemplateView
from booking.models import Booking
@@ -40,10 +42,18 @@ class DevelopmentPodsView(TemplateView):
dev_pods = []
for resource in resources:
- dev_pod = (resource, None)
+ booking_utilization = resource.get_booking_utilization(weeks=4)
+ total = booking_utilization['booked_seconds'] + booking_utilization['available_seconds']
+ try:
+ utilization_percentage = "%d%%" % (float(booking_utilization['booked_seconds']) /
+ total * 100)
+ except (ValueError, ZeroDivisionError):
+ return ""
+
+ dev_pod = (resource, None, utilization_percentage)
for booking in bookings:
if booking.resource == resource:
- dev_pod = (resource, booking)
+ dev_pod = (resource, booking, utilization_percentage)
dev_pods.append(dev_pod)
context = super(DevelopmentPodsView, self).get_context_data(**kwargs)
@@ -59,7 +69,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 +87,47 @@ 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})
+
+
+class JenkinsUtilizationJSON(View):
+ def get(self, request, *args, **kwargs):
+ resource = get_object_or_404(Resource, id=kwargs['resource_id'])
+ weeks = int(kwargs['weeks'])
+ utilization = resource.slave.get_utilization(timedelta(weeks=weeks))
+ utilization = [
+ {
+ 'label': 'Offline',
+ 'data': utilization['offline'],
+ 'color': '#d9534f'
+ },
+ {
+ 'label': 'Online',
+ 'data': utilization['online'],
+ 'color': '#5cb85c'
+ },
+ {
+ 'label': 'Idle',
+ 'data': utilization['idle'],
+ 'color': '#5bc0de'
+ },
+ ]
+ return JsonResponse({'data': utilization})