From 8269a6743c14cab1ca4105651255e6f908ee195c Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Tue, 6 Apr 2021 15:18:06 -0400 Subject: Analytics Board Signed-off-by: Sean Smith Change-Id: Id942628ff04cd2f3808f8608ac45989360717f34 --- src/booking/stats.py | 54 +++++- src/booking/urls.py | 2 - src/booking/views.py | 2 +- src/templates/base/booking/stats.html | 338 +++++++++++++++++++++++++++------- src/templates/base/layout.html | 6 +- 5 files changed, 330 insertions(+), 72 deletions(-) diff --git a/src/booking/stats.py b/src/booking/stats.py index bdb478a..626ed79 100644 --- a/src/booking/stats.py +++ b/src/booking/stats.py @@ -6,8 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import os from booking.models import Booking +from resource_inventory.models import ResourceQuery, ResourceProfile from datetime import datetime, timedelta +from collections import Counter import pytz @@ -23,9 +26,28 @@ class StatisticsManager(object): y values are the integer number of bookings/users active at time """ + anuket_colors = [ + '#6BDAD5', # Turquoise + '#E36386', # Pale Violet Red + '#F5B335', # Sandy Brown + '#007473', # Teal + '#BCE194', # Gainsboro + '#00CE7C', # Sea Green + ] + + lfedge_colors = [ + '#0049B0', + '#B481A5', + '#6CAFE4', + '#D33668', + '#28245A' + ] + x = [] y = [] users = [] + projects = [] + profiles = {str(profile): [] for profile in ResourceProfile.objects.all()} now = datetime.now(pytz.utc) delta = timedelta(days=span) @@ -49,10 +71,38 @@ class StatisticsManager(object): for booking in books: active_users += booking.collaborators.all().count() + 1 - x.append(str(start)) + x.append(str(start.month) + '-' + str(start.day)) y.append(books.count()) + + step_profiles = Counter([ + str(config.profile) + for book in books + for config in book.resource.template.getConfigs() + ]) + + for profile in ResourceProfile.objects.all(): + profiles[str(profile)].append(step_profiles[str(profile)]) users.append(active_users) start += timedelta(hours=12) - return {"booking": [x, y], "user": [x, users]} + in_use = len(ResourceQuery.filter(working=True, booked=True)) + not_in_use = len(ResourceQuery.filter(working=True, booked=False)) + maintenance = len(ResourceQuery.filter(working=False)) + + projects = [x.project for x in bookings] + proj_count = sorted(Counter(projects).items(), key=lambda x: x[1]) + + project_keys = [proj[0] for proj in proj_count[-5:]] + project_counts = [proj[1] for proj in proj_count[-5:]] + + resources = {key: [x, value] for key, value in profiles.items()} + + return { + "resources": resources, + "booking": [x, y], + "user": [x, users], + "utils": [in_use, not_in_use, maintenance], + "projects": [project_keys, project_counts], + "colors": anuket_colors if os.environ['TEMPLATE_OVERRIDE_DIR'] == 'laas' else lfedge_colors + } diff --git a/src/booking/urls.py b/src/booking/urls.py index d5287e9..cdf18ae 100644 --- a/src/booking/urls.py +++ b/src/booking/urls.py @@ -40,8 +40,6 @@ from booking.views import ( app_name = "booking" urlpatterns = [ - - url(r'^detail/(?P[0-9]+)/$', booking_detail_view, name='detail'), url(r'^(?P[0-9]+)/$', booking_detail_view, name='booking_detail'), url(r'^delete/$', BookingDeleteView.as_view(), name='delete_prefix'), diff --git a/src/booking/views.py b/src/booking/views.py index 66cb594..2b910e7 100644 --- a/src/booking/views.py +++ b/src/booking/views.py @@ -195,7 +195,7 @@ def booking_stats_view(request): return render( request, "booking/stats.html", - context={"data": StatisticsManager.getContinuousBookingTimeSeries(), "title": "Booking Statistics"} + context={"data": StatisticsManager.getContinuousBookingTimeSeries(), "title": ""} ) diff --git a/src/templates/base/booking/stats.html b/src/templates/base/booking/stats.html index 4c06b71..3429acf 100644 --- a/src/templates/base/booking/stats.html +++ b/src/templates/base/booking/stats.html @@ -1,78 +1,288 @@ {% extends "base.html" %} {% load staticfiles %} -{% block extrahead %} -{{ block.super }} - +{% block content %} +
+
+
+
+

Booking Statistics

+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ + -{% endblock %} + let utilization_config = { + type:"doughnut", + data: { + labels : ["In Use","Not In Use","Maitenance"], + datasets: [{ + label: 'Lab Utilization', + data : [data['utils'][0], data['utils'][1], data['utils'][2]], + backgroundColor: [ + primary_color, + secondary_color, + accent_color, + ] + }] + }, + options: { + circumference: Math.PI, + rotation : Math.PI, + cutoutPercentage : 80, + plugins: { + datalabels: { + backgroundColor: primary_color, + borderColor: secondary_color, + align: 'start', + anchor: 'start', + offset: 10, + borderRadius: 4, + borderWidth: 1, + } + }, + legend: { + display: false + }, + tooltips: { + enabled: true + }, + title: { + display: true, + text: "Lab Resources Utilization" + } + } + }; -{% block content %} -
-
-

Number of days to plot:

-
- - -
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
- {% endblock content %} diff --git a/src/templates/base/layout.html b/src/templates/base/layout.html index edf9b6b..2132dc6 100644 --- a/src/templates/base/layout.html +++ b/src/templates/base/layout.html @@ -14,6 +14,9 @@ OPNFV Laas {{ title }} {% endblock head-title %} + + + @@ -27,9 +30,6 @@ - - - {% block extrahead %} {% endblock extrahead %} -- cgit 1.2.3-korg