From 0de41f312fe7d002dedfdbf849efe7349df45612 Mon Sep 17 00:00:00 2001
From: Flavio Tarsetti <flavio.tarsetti@idiap.ch>
Date: Wed, 16 Aug 2017 17:22:36 +0200
Subject: [PATCH] [statistics] added statistics about user profiles on the
 platform for the superusers

---
 .../templates/statistics/statistics.html          | 15 +++++++++++++++
 beat/web/statistics/views.py                      | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/beat/web/statistics/templates/statistics/statistics.html b/beat/web/statistics/templates/statistics/statistics.html
index ebd752a71..40e783bfa 100644
--- a/beat/web/statistics/templates/statistics/statistics.html
+++ b/beat/web/statistics/templates/statistics/statistics.html
@@ -91,6 +91,21 @@
     <p class="help">Items available and managed by administrators</p>
   </div>
 </div>
+<div class="row">
+  <div class="col-sm-3">
+    <h3>Users Profiles</h3>
+    <ul class="list-group">
+      <li class="list-group-item">Total Users <span class="badge">{{ totals.users }}</span></li>
+      <li class="list-group-item">New Users Unvalidated <span class="badge">{{ totals.newusers }}</span></li>
+      <li class="list-group-item">New Users Waiting Validation <span class="badge">{{ totals.waitingvalidationusers}}</span></li>
+      <li class="list-group-item">Accepted Users <span class="badge">{{ totals.acceptedusers }}</span></li>
+      <li class="list-group-item">Year Revalidation Users <span class="badge">{{ totals.yearrevalidationusers }}</span></li>
+      <li class="list-group-item">Rejected Users <span class="badge">{{ totals.rejectedusers }}</span></li>
+      <li class="list-group-item">Blocked Users <span class="badge">{{ totals.blockedusers }}</span></li>
+    </ul>
+    <p class="help">Users on the platform</p>
+  </div>
+</div>
 
 
 <!-- tabs -->
diff --git a/beat/web/statistics/views.py b/beat/web/statistics/views.py
index d13a7e073..2b1664ffc 100644
--- a/beat/web/statistics/views.py
+++ b/beat/web/statistics/views.py
@@ -56,6 +56,7 @@ def calculate_totals():
     from ..plotters.models import Plotter
     from ..plotters.models import PlotterParameter
     from ..search.models import Search
+    from ..accounts.models import Profile
 
     # for calculating the total cpu time, we use the HourlyStatistics and
     # accumulate over the whole history
@@ -78,6 +79,13 @@ def calculate_totals():
     output_size = details['data_written_size']
     output_time = details['data_written_time']
 
+    new_users = User.objects.filter(profile__status = Profile.NEWUSER)
+    waiting_validation_users = User.objects.filter(profile__status = Profile.WAITINGVALIDATION)
+    accepted_users = User.objects.filter(profile__status = Profile.ACCEPTED)
+    rejected_users = User.objects.filter(profile__status = Profile.REJECTED)
+    yearrevalidation_users = User.objects.filter(profile__status = Profile.YEARREVALIDATION)
+    blocked_users = User.objects.filter(profile__status = Profile.BLOCKED)
+
     return dict(
 
             counter=counter,
@@ -89,6 +97,12 @@ def calculate_totals():
             output_bw_mb_s = int((output_size/float(2**20))/output_time) if output_size else 0,
 
             users=User.objects.count(),
+            newusers=new_users.count(),
+            waitingvalidationusers=waiting_validation_users.count(),
+            acceptedusers=accepted_users.count(),
+            rejectedusers=rejected_users.count(),
+            yearrevalidationusers=yearrevalidation_users.count(),
+            blockedusers=blocked_users.count(),
             databases=Database.objects.count(),
             environments=Environment.objects.count(),
             queues=Queue.objects.count(),
-- 
GitLab