From 38a1b0d7ef3f74c33e68904f19c6c456591be9da Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 26 Nov 2008 23:49:51 +0000 Subject: [PATCH] * Show global and per-project statistics. --- src/Hydra/lib/Hydra/Controller/Root.pm | 45 +++++++++++++++----------- src/Hydra/root/common.tt | 32 ++++++++++++++++++ src/Hydra/root/index.tt | 5 +++ src/Hydra/root/project.tt | 29 ++--------------- 4 files changed, 65 insertions(+), 46 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index 38e2982a..8a13a14c 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -46,11 +46,36 @@ sub getBuild { } +sub getBuildStats { + my ($c, $builds) = @_; + + $c->stash->{finishedBuilds} = $builds->search({finished => 1}) || 0; + + $c->stash->{succeededBuilds} = $builds->search( + {finished => 1, buildStatus => 0}, + {join => 'resultInfo'}) || 0; + + $c->stash->{scheduledBuilds} = $builds->search({finished => 0}) || 0; + + $c->stash->{busyBuilds} = $builds->search( + {finished => 0, busy => 1}, + {join => 'schedulingInfo'}) || 0; + + $c->stash->{totalBuildTime} = $builds->search({}, + {join => 'resultInfo', select => {sum => 'stoptime - starttime'}, as => ['sum']}) + ->first->get_column('sum') || 0; +} + + sub index :Path :Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'index.tt'; + + getBuildStats($c, $c->model('DB::Builds')); + $c->stash->{allBuilds} = [$c->model('DB::Builds')->search( {finished => 1}, {order_by => "timestamp DESC"})]; + # Get the latest finished build for each unique job. $c->stash->{latestBuilds} = [$c->model('DB::Builds')->search(undef, { join => 'resultInfo' @@ -272,25 +297,7 @@ sub project :Local { $c->stash->{curProject} = $project; - $c->stash->{finishedBuilds} = $c->model('DB::Builds')->search( - {project => $projectName, finished => 1}); - - $c->stash->{succeededBuilds} = $c->model('DB::Builds')->search( - {project => $projectName, finished => 1, buildStatus => 0}, - {join => 'resultInfo'}); - - $c->stash->{scheduledBuilds} = $c->model('DB::Builds')->search( - {project => $projectName, finished => 0}); - - $c->stash->{busyBuilds} = $c->model('DB::Builds')->search( - {project => $projectName, finished => 0, busy => 1}, - {join => 'schedulingInfo'}); - - $c->stash->{totalBuildTime} = $c->model('DB::Builds')->search( - {project => $projectName}, - {join => 'resultInfo', select => {sum => 'stoptime - starttime'}, as => ['sum']}) - ->first->get_column('sum'); - $c->stash->{totalBuildTime} = 0 unless defined $c->stash->{totalBuildTime}; + getBuildStats($c, scalar $project->builds); $c->stash->{jobNames} = [$c->model('DB::Builds')->search({project => $projectName}, {select => [{distinct => 'attrname'}], as => ['attrname']})]; diff --git a/src/Hydra/root/common.tt b/src/Hydra/root/common.tt index ad237fd1..bd71f399 100644 --- a/src/Hydra/root/common.tt +++ b/src/Hydra/root/common.tt @@ -61,4 +61,36 @@ [% END -%] +[% END %] + + +[% BLOCK showBuildStats %] + + + + + + + + + + + + + + + + + + + + + + + + + + +
Finished builds:[% finishedBuilds %]
Succeeded builds:[% succeededBuilds %]
Failed builds:[% finishedBuilds - succeededBuilds %]
Total build time:[% totalBuildTime %]s
Scheduled builds:[% scheduledBuilds %]
Currently executing builds:[% busyBuilds %]
+ [% END %] \ No newline at end of file diff --git a/src/Hydra/root/index.tt b/src/Hydra/root/index.tt index 9763cd60..543e4d69 100644 --- a/src/Hydra/root/index.tt +++ b/src/Hydra/root/index.tt @@ -5,6 +5,11 @@

Hydra Overview

+

Statistics

+ +[% PROCESS showBuildStats %] + +

Job status

Below are the latest builds for each job.

diff --git a/src/Hydra/root/project.tt b/src/Hydra/root/project.tt index 04d9234e..37c7cc60 100644 --- a/src/Hydra/root/project.tt +++ b/src/Hydra/root/project.tt @@ -245,7 +245,7 @@

Jobs

-[% IF jobName && jobNames.size > 0 %] +[% IF jobNames && jobNames.size > 0 %]