From 11cdd665c10e947b1accd240ee93167ed0baaab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Such=C3=BD?= Date: Thu, 29 Aug 2024 12:47:31 +0200 Subject: [PATCH] frontend: provide statistics on how many users submitted at least one build in past month Fixes: # 3315 --- frontend/coprs_frontend/coprs/logic/builds_logic.py | 13 +++++++++++++ .../coprs/templates/status/stats.html | 6 ++++++ .../coprs/views/status_ns/status_general.py | 2 ++ 3 files changed, 21 insertions(+) diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py b/frontend/coprs_frontend/coprs/logic/builds_logic.py index 64c1429e2..98e8980bb 100644 --- a/frontend/coprs_frontend/coprs/logic/builds_logic.py +++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py @@ -129,6 +129,18 @@ def get_running_tasks_by_time(cls, start, end): return result + @classmethod + def get_users_by_time(cls, start, end): + """ Returns number of user that submitted at least one build in + the period. + """ + result = db.session.query(models.Build.user_id)\ + .join(models.BuildChroot)\ + .filter(models.BuildChroot.ended_on > start)\ + .filter(models.BuildChroot.started_on < end)\ + .group_by(models.Build.user_id).count() + return result + @classmethod def get_chroot_histogram(cls, start, end): chroots = [] @@ -150,6 +162,7 @@ def get_chroot_histogram(cls, start, end): l[0] = mock_chroot.name return chroots + @classmethod def get_pending_jobs_bucket(cls, start, end): query = text(""" diff --git a/frontend/coprs_frontend/coprs/templates/status/stats.html b/frontend/coprs_frontend/coprs/templates/status/stats.html index f4551689b..8ecc7e40c 100644 --- a/frontend/coprs_frontend/coprs/templates/status/stats.html +++ b/frontend/coprs_frontend/coprs/templates/status/stats.html @@ -20,6 +20,12 @@

Builds during last 24 hours

Builds during last 90 days

+
+

Number of users that submitted at least one build in past 30 days.

+
+
+

{{ users_in_past_month }}

+

Builds divided by chroots

diff --git a/frontend/coprs_frontend/coprs/views/status_ns/status_general.py b/frontend/coprs_frontend/coprs/views/status_ns/status_general.py index 3e79be987..4243f35f8 100644 --- a/frontend/coprs_frontend/coprs/views/status_ns/status_general.py +++ b/frontend/coprs_frontend/coprs/views/status_ns/status_general.py @@ -165,6 +165,7 @@ def stats(): curr_time = int(time()) chroots_24h = builds_logic.BuildsLogic.get_chroot_histogram(curr_time - 86400, curr_time) chroots_90d = builds_logic.BuildsLogic.get_chroot_histogram(curr_time - 90*86400, curr_time) + users_in_past_month = builds_logic.BuildsLogic.get_users_by_time(curr_time - 30*86400, curr_time) data_24h = builds_logic.BuildsLogic.get_task_graph_data('10min') data_90d = builds_logic.BuildsLogic.get_task_graph_data('24h') actions_24h = builds_logic.ActionsLogic.get_action_graph_data('10min') @@ -173,6 +174,7 @@ def stats(): return flask.render_template("status/stats.html", data1=data_24h, data2=data_90d, + users_in_past_month=users_in_past_month, chroots1=chroots_24h, chroots2=chroots_90d, actions1=actions_24h,