From d6585d894ef7872fb0fab6a31fa87b8ec7996ae8 Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Thu, 16 Jan 2020 19:37:22 +0600 Subject: [PATCH] Data for Current Trust Score and Action Solved elements on every page. --- backend/device_registry/templates/admin_base.html | 10 +++++----- backend/profile_page/models.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/device_registry/templates/admin_base.html b/backend/device_registry/templates/admin_base.html index 6478e0b83..d9619a729 100644 --- a/backend/device_registry/templates/admin_base.html +++ b/backend/device_registry/templates/admin_base.html @@ -101,14 +101,14 @@

Status Overview

- + {% endblock %} {% block scripts %} @@ -165,7 +165,7 @@

Status Overview

#trust-graph-var { width: 75%; } - + {% endblock %} diff --git a/backend/profile_page/models.py b/backend/profile_page/models.py index d43912670..fa57d249a 100644 --- a/backend/profile_page/models.py +++ b/backend/profile_page/models.py @@ -9,6 +9,7 @@ from django.dispatch import receiver from django.utils import timezone +from dateutil.relativedelta import relativedelta, MO from mixpanel import Mixpanel, MixpanelException from phonenumber_field.modelfields import PhoneNumberField @@ -53,6 +54,12 @@ def actions_count(self): Q(device__owner=self.user) & RecommendedAction.get_affected_query()) \ .values('action_id').distinct().count() + @property + def actions_resolved_since_monday(self): + monday = (timezone.now() - relativedelta(weekday=MO(-1))).date() + return RecommendedAction.objects.filter(device__owner=self.user, resolved_at__gte=monday)\ + .values('action_id').distinct().count() + @property def github_repos(self): try: @@ -80,6 +87,10 @@ def average_trust_score(self): return None return devices.aggregate(Avg('trust_score'))['trust_score__avg'] + @property + def average_trust_score_100(self): + return int(self.average_trust_score * 100) + def sample_history(self): """ Count the number of newly resolved user's RAs in the last 24h, save it together with the user's average trust