From: Michael Tremer Date: Sat, 29 Apr 2023 13:02:40 +0000 (+0000) Subject: users: Redesign index page with some hopefully intersting statistics X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=282e875cd50f6bd38f1cf708131f1e476fa0f8da;p=pbs.git users: Redesign index page with some hopefully intersting statistics Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/users.py b/src/buildservice/users.py index f717c541..15785057 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -287,6 +287,30 @@ class Users(base.Object): return sorted(users) + @property + def top(self): + """ + Returns the top users (with the most builds in the last year) + """ + users = self._get_users(""" + SELECT + DISTINCT users.*, + COUNT(builds.id) AS _sort + FROM + users + LEFT JOIN + builds ON users.id = builds.owner_id + GROUP BY + users.id + ORDER BY + _sort DESC + LIMIT + 30 + """, + ) + + return list(users) + class User(base.DataObject): table = "users" @@ -489,6 +513,46 @@ class User(base.DataObject): return 0 + # Stats + + @lazy_property + def total_builds(self): + res = self.db.get(""" + SELECT + COUNT(*) AS builds + FROM + builds + WHERE + owner_id = %s + """, self.id, + ) + + if res: + return res.builds + + return 0 + + @lazy_property + def total_build_time(self): + res = self.db.get(""" + SELECT + SUM(jobs.finished_at - jobs.started_at) AS total_time + FROM + jobs + LEFT JOIN + builds ON jobs.build_id = builds.id + WHERE + jobs.finished_at IS NOT NULL + AND + jobs.started_at IS NOT NULL + AND + builds.owner_id = %s + """, self.id, + ) + + if res: + return res.total_time + # Custom repositories @property diff --git a/src/templates/users/index.html b/src/templates/users/index.html index 684e479f..7b226e7f 100644 --- a/src/templates/users/index.html +++ b/src/templates/users/index.html @@ -3,26 +3,19 @@ {% block title %}{{ _("Users") }}{% end block %} {% block container %} -