Calculate percentages based on complete cases, not total.

git-svn-id: svn://10.0.0.236/trunk@227479 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ghendricks%novell.com
2007-06-04 19:19:43 +00:00
parent 1a9ff7ab95
commit 5be74efc99
5 changed files with 66 additions and 186 deletions

View File

@@ -58,7 +58,7 @@ use Bugzilla::Bug;
use Text::Diff;
use base qw(Exporter);
use base qw(Exporter Bugzilla::Object);
###############################
#### Initialization ####
@@ -77,6 +77,9 @@ use base qw(Exporter);
=cut
use constant DB_TABLE => "test_plans";
use constant NAME_FIELD => "name";
use constant ID_FIELD => "plan_id";
use constant DB_COLUMNS => qw(
plan_id
product_id
@@ -88,6 +91,15 @@ use constant DB_COLUMNS => qw(
isactive
);
use constant REQUIRED_CREATE_FIELDS => qw(product_id author_id type_id default_product_version name);
use constant VALIDATORS => {
product_id => \&_check_product,
author_id => \&_check_product,
type_id => \&_check_product,
default_product_version => \&_check_product,
};
use constant NAME_MAX_LENGTH => 255;
sub report_columns {

View File

@@ -51,8 +51,7 @@ use Bugzilla::Config;
use Bugzilla::Testopia::Environment;
use Bugzilla::Bug;
use base qw(Exporter);
@Bugzilla::Testopia::TestRun::EXPORT = qw(CalculatePercentCompleted);
use base qw(Exporter Bugzilla::Object);
###############################
#### Initialization ####
@@ -74,6 +73,9 @@ use base qw(Exporter);
=cut
use constant DB_TABLE => "test_runs";
use constant NAME_FIELD => "summary";
use constant ID_FIELD => "run_id";
use constant DB_COLUMNS => qw(
run_id
plan_id
@@ -107,6 +109,20 @@ sub report_columns {
}
use constant REQUIRED_CREATE_FIELDS => qw(plan_id environment_id build_id
product_version summary manager_id
plan_text_version);
use constant VALIDATORS => {
plan_id => \&_check_plan,
environment_id => \&_check_env,
build_id => \&_check_build,
product_version => \&_check_product_version,
summary => \&_check_summary,
manager_id => \&_check_manager,
plan_text_version => \&_check_plan_text_version,
};
###############################
#### Methods ####
###############################
@@ -174,17 +190,16 @@ and adds them to get a total then takes the percentage.
=cut
sub calculate_percent_completed {
sub calculate_percent {
my ($idle, $run) = (@_);
my $total = $idle + $run;
my ($total, $count) = (@_);
my $percent;
if ($total == 0) {
$percent = 0;
} else {
$percent = $run*100/$total;
$percent = $count*100/$total;
$percent = int($percent + 0.5);
if (($percent == 100) && ($idle != 0)) {
if (($percent == 100) && ($count != $total)) {
#I don't want to see 100% unless every test is run
$percent = 99;
}
@@ -1020,7 +1035,7 @@ sub case_run_count {
my $query =
"SELECT COUNT(*)
FROM test_case_runs
WHERE run_id = ? AND iscurrent = 1";
WHERE run_id = ?";
$query .= " AND case_run_status_id = ?" if $status_id;
my $count;
@@ -1034,144 +1049,20 @@ sub case_run_count {
return $count;
}
#TODO: Replace these with case_run_count
=head2 idle_count
Returns a count of the number of case-runs in this run with a status
of IDLE
=cut
sub idle_count {
sub finished_count {
my $self = shift;
my ($status_id) = @_;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('IDLE', $self->{'run_id'}));
$self->{'idle_count'} = $count;
return $self->{'idle_count'};
FROM test_case_runs
WHERE run_id = ?
AND case_run_status_id IN (?,?,?)",undef, ($self->id, FAILED, PASSED, BLOCKED));
return $count;
}
=head2 passed_count
Returns a count of the number of case-runs in this run with a status
of PASSED
=cut
sub passed_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('PASSED', $self->{'run_id'}));
$self->{'passed_count'} = $count;
return $self->{'passed_count'};
}
=head2 failed_count
Returns a count of the number of case-runs in this run with a status
of FAILED
=cut
sub failed_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('FAILED', $self->{'run_id'}));
$self->{'failed_count'} = $count;
return $self->{'failed_count'};
}
=head2 running_count
Returns a count of the number of case-runs in this run with a status
of RUNNING
=cut
sub running_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('RUNNING', $self->{'run_id'}));
$self->{'running_count'} = $count;
return $self->{'running_count'};
}
=head2 paused_count
Returns a count of the number of case-runs in this run with a status
of PAUSED
=cut
sub paused_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('PAUSED', $self->{'run_id'}));
$self->{'paused_count'} = $count;
return $self->{'paused_count'};
}
=head2 blocked_count
Returns a count of the number of case-runs in this run with a status
of BLOCKED
=cut
sub blocked_count {
my $self = shift;
my $dbh = Bugzilla->dbh;
my ($count) = $dbh->selectrow_array(
"SELECT COUNT(*)
FROM test_case_runs cr
JOIN test_case_run_status cs
ON cr.case_run_status_id = cs.case_run_status_id
WHERE cs.name = ? AND cr.run_id = ? AND cr.iscurrent = 1",
undef, ('BLOCKED', $self->{'run_id'}));
$self->{'blocked_count'} = $count;
return $self->{'blocked_count'};
}
=head2 percent_complete
@@ -1182,45 +1073,23 @@ that have a status vs. those with a status of IDLE
sub percent_complete {
my $self = shift;
my $notrun = $self->idle_count + $self->running_count + $self->paused_count;
my $run = $self->passed_count + $self->failed_count + $self->blocked_count;
$self->{'percent_complete'} = calculate_percent_completed($notrun, $run);
return $self->{'percent_complete'} if defined $self->{'percent_complete'};
$self->{'percent_complete'} = calculate_percent($self->case_run_count,$self->finished_count);
return $self->{'percent_complete'};
}
sub percent_passed {
sub percent_of_total {
my $self = shift;
my $notrun = $self->idle_count + $self->running_count + $self->paused_count + $self->failed_count + $self->blocked_count;
my $run = $self->passed_count;
$self->{'percent_passed'} = calculate_percent_completed($notrun, $run);
return $self->{'percent_passed'};
my ($status_id) = @_;
return calculate_percent($self->case_run_count,$self->case_run_count($status_id));
}
sub percent_failed {
sub percent_of_finished {
my $self = shift;
my $notrun = $self->idle_count + $self->running_count + $self->paused_count + $self->passed_count + $self->blocked_count;
my $run = $self->failed_count;
$self->{'percent_failed'} = calculate_percent_completed($notrun, $run);
return $self->{'percent_failed'};
my ($status_id) = @_;
return calculate_percent($self->finished_count,$self->case_run_count($status_id));
}
sub percent_blocked {
my $self = shift;
my $notrun = $self->idle_count + $self->running_count + $self->paused_count + $self->passed_count + $self->failed_count;
my $run = $self->blocked_count;
$self->{'percent_blocked'} = calculate_percent_completed($notrun, $run);
return $self->{'percent_blocked'};
}
sub percent_not_run {
my $self = shift;
my $notrun = $self->failed_count + $self->running_count + $self->paused_count + $self->passed_count;
my $run = $self->idle_count + $self->blocked_count;
$self->{'percent_not_run'} = calculate_percent_completed($notrun, $run);
return $self->{'percent_not_run'};
}
=head2 current_caseruns
Returns a reference to a list of TestCaseRun objects that are the

View File

@@ -26,9 +26,9 @@
<span style="width:82px;float:left;" id="bar_[% run.id FILTER none %]">
<span style="float:left;width:1px;height:13px;background-color:black;"></span>
[%# IFs needed for Opera browser #%]
<span style="float:left;"><img src="testopia/img/green_bar.gif" style="width:[% run.percent_passed * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/red_bar.gif" style="width:[% run.percent_failed * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/orange_bar.gif" style="width:[% run.percent_blocked * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/green_bar.gif" style="width:[% run.percent_of_total(2) * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/red_bar.gif" style="width:[% run.percent_of_total(3) * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/orange_bar.gif" style="width:[% run.percent_of_total(6) * 0.8 %]px;height:13px;padding:0px;margin:0px;border-width:0px;"/></span>
<span style="float:left;"><img src="testopia/img/pg.gif" style="width:[% 80 - run.percent_complete * 0.8 %]px;height:13px;"/></span>
<span style="float:left;width:1px;height:13px;background-color:black;"></span>
</span>
@@ -36,9 +36,9 @@
</div>
<span dojoType="toolTip" connectId="bar_[% run.id FILTER none %]" id="tip_[% run.id FILTER none %]" style="display:none">
<table>
<tr><th style="color:green" align="right">Passed:</th><td>[% run.passed_count %]</td><td align="right" style="border: 1px solid #000">[% run.percent_passed %]%</td></tr>
<tr><th style="color:red" align="right">Failed:</th><td>[% run.failed_count %]</td><td align="right" style="border: 1px solid #000">[% run.percent_failed %]%</td></tr>
<tr><th style="color:orange" align="right">Blocked:</th><td>[% run.blocked_count %]</td><td align="right" style="border: 1px solid #000">[% run.percent_blocked %]%</td></tr>
<tr><th style="color:blue" align="right">Total:</th><th colspan="2">[% run.case_count %]</td align="right"></tr>
<tr><th style="color:green" align="right">Passed:</th><td>[% run.case_run_count(2) %]</td><td align="right" style="border: 1px solid #000">[% run.percent_of_finished(2) %]%</td></tr>
<tr><th style="color:red" align="right">Failed:</th><td>[% run.case_run_count(3) %]</td><td align="right" style="border: 1px solid #000">[% run.percent_of_finished(3) %]%</td></tr>
<tr><th style="color:orange" align="right">Blocked:</th><td>[% run.case_run_count(6) %]</td><td align="right" style="border: 1px solid #000">[% run.percent_of_finished(6) %]%</td></tr>
<tr><th style="color:blue" align="right">Total Run:</th><th colspan="2">[% run.finished_count %] out of [% run.case_run_count %]</td align="right"></tr>
</table>
</span>

View File

@@ -247,28 +247,27 @@
<table align="center">
<tr>
<th align="right">Idle:</th>
<td class="number_cell"><b>[% run.idle_count FILTER html %]</b></td>
<td class="number_cell"><b>[% run.case_run_count(1) FILTER html %]</b></td>
</tr>
<tr>
<th align="right">Passed:</th>
<td class="number_cell"><b>[% run.passed_count FILTER html %]</b></td>
<td class="number_cell"><b>[% run.case_run_count(2) FILTER html %]</b></td>
</tr>
<tr>
<th align="right">Failed:</th>
<td class="number_cell"><b>[% run.failed_count FILTER html %]</b></td>
</td>
<td class="number_cell"><b>[% run.case_run_count(3) FILTER html %]</b></td>
</tr>
<tr>
<th align="right">Running:</th>
<td class="number_cell"><b>[% run.running_count FILTER html %]</b></td>
<td class="number_cell"><b>[% run.case_run_count(4) FILTER html %]</b></td>
</tr>
<tr>
<th align="right">Paused:</th>
<td class="number_cell"><b>[% run.paused_count FILTER html %]</b></td>
<td class="number_cell"><b>[% run.case_run_count(5) FILTER html %]</b></td>
</tr>
<tr>
<th align="right">Blocked:</th>
<td class="number_cell"><b>[% run.blocked_count FILTER html %]</b></td>
<td class="number_cell"><b>[% run.case_run_count(6) FILTER html %]</b></td>
</td>
</tr>
<tr>

View File

@@ -425,7 +425,7 @@ sub display {
$vars->{'filtered'} = 1;
}
$cgi->param('current_tab', 'case_run');
my $search = Bugzilla::Testopia::Search->new($cgi);
my $table = Bugzilla::Testopia::Table->new('case_run', 'tr_show_run.cgi', $cgi, undef, $search->query);