]> git.ipfire.org Git - pbs.git/commitdiff
builds: Show some more stats on index page
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jun 2022 14:25:49 +0000 (14:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jun 2022 14:25:49 +0000 (14:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builders.py
src/templates/builders/list.html

index 28bf527ec5c17647433bf4d53cb49d0fbb7cd04e..852e827af62db11b90fef19bb0b3c358b34829e6 100644 (file)
@@ -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"
index e347bc3564d3499856b4095736d3add004d71192..768bc92aa76edd0767c0287f5030e625b962bafa 100644 (file)
                        {{ _("Create A New Builder") }}
                </a>
        {% end %}
+
+       <div class="callout">
+               <h5>{{ _("Statistics") }}</h5>
+
+               <div class="grid-x grid-padding-x">
+                       <div class="cell large-8">
+                               <p>{{ _("Total Build Time") }}</p>
+
+                               <div class="stat">
+                                       {{ format_time(backend.builders.total_build_time) }}
+                               </div>
+                       </div>
+
+                       {% set arches = backend.builders.total_build_time_by_arch %}
+
+                       <div class="cell large-4">
+                               <p>{{ _("Total Build Time By Architecture") }}</p>
+
+                               <table>
+                                       <tbody>
+                                               {% for arch in arches %}
+                                                       <tr>
+                                                               <th scope="row">{{ arch }}</th>
+                                                               <td>{{ arches[arch] }}</td>
+                                                       </tr>
+                                               {% end %}
+                                       </tbody>
+                               </table>
+                       </div>
+               </div>
+       </div>
 {% end block %}