From: Michael Tremer Date: Sun, 26 Jun 2022 14:25:49 +0000 (+0000) Subject: builds: Show some more stats on index page X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dd347b1aae6aee7ea6ae3f717e3566b26e2ebda;p=pbs.git builds: Show some more stats on index page Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index 28bf527e..852e827a 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -192,6 +192,54 @@ class Builders(base.Object): *(builder.stop(wait=wait) for builder in builders_to_be_shut_down), ) + # Stats + + @property + def total_build_time(self): + """ + Returns the total build time + """ + res = self.db.get(""" + SELECT + SUM( + COALESCE(jobs.finished_at, CURRENT_TIMESTAMP) + - + jobs.started_at + ) AS t + FROM + jobs + WHERE + started_at IS NOT NULL""", + ) + + return res.t + + @property + def total_build_time_by_arch(self): + """ + Returns a dict with the total build times grouped by architecture + """ + res = self.db.query(""" + SELECT + jobs.arch AS arch, + SUM( + COALESCE(jobs.finished_at, CURRENT_TIMESTAMP) + - + jobs.started_at + ) AS t + FROM + jobs + WHERE + started_at IS NOT NULL + GROUP BY + jobs.arch + ORDER BY + jobs.arch""", + ) + + return { row.arch : row.t for row in res } + + class Builder(base.DataObject): table = "builders" diff --git a/src/templates/builders/list.html b/src/templates/builders/list.html index e347bc35..768bc92a 100644 --- a/src/templates/builders/list.html +++ b/src/templates/builders/list.html @@ -37,4 +37,35 @@ {{ _("Create A New Builder") }} {% end %} + +
+
{{ _("Statistics") }}
+ +
+
+

{{ _("Total Build Time") }}

+ +
+ {{ format_time(backend.builders.total_build_time) }} +
+
+ + {% set arches = backend.builders.total_build_time_by_arch %} + +
+

{{ _("Total Build Time By Architecture") }}

+ + + + {% for arch in arches %} + + + + + {% end %} + +
{{ arch }}{{ arches[arch] }}
+
+
+
{% end block %}