Calculate totals over numeric columns

beta
Vitaliy Filippov 2018-05-29 19:55:06 +03:00
parent a4f77c4340
commit 4b7a51efa8
4 changed files with 39 additions and 40 deletions

View File

@ -463,11 +463,12 @@ sub STATIC_COLUMNS
reporter_short => { title => 'Reporter Login' },
qa_contact_short => { title => 'QA Contact Login' },
# FIXME save aggregated work_time in bugs table and search on it
work_time => { name => $actual_time },
interval_time => { name => $actual_time, title => 'Period Worktime', noreports => 1 },
work_time => { name => $actual_time, numeric => 1 },
interval_time => { name => $actual_time, title => 'Period Worktime', noreports => 1, numeric => 1 },
percentage_complete => {
name => "(CASE WHEN $actual_time + bugs.remaining_time = 0.0 THEN 0.0" .
" ELSE 100 * ($actual_time / ($actual_time + bugs.remaining_time)) END)",
numeric => 1,
},
'flagtypes.name' => {
name =>
@ -625,6 +626,10 @@ sub STATIC_COLUMNS
elsif ($bug_columns->{$id})
{
$columns->{$id}->{name} ||= "bugs.$id";
if ($field->type == FIELD_TYPE_NUMERIC)
{
$columns->{$id}->{numeric} = 1;
}
}
}

View File

@ -707,22 +707,16 @@ $buglist_sth->execute();
# Retrieve the query results one row at a time and write the data into a list of Perl records.
# If we're doing time tracking, then keep totals for all bugs.
my $percentage_complete = 1 && grep { $_ eq 'percentage_complete' } @$displaycolumns;
my $estimated_time = 1 && grep { $_ eq 'estimated_time' } @$displaycolumns;
my $remaining_time = $percentage_complete || grep { $_ eq 'remaining_time' } @$displaycolumns;
my $work_time = $percentage_complete || grep { $_ eq 'work_time' } @$displaycolumns;
my $interval_time = $percentage_complete || grep { $_ eq 'interval_time' } @$displaycolumns;
my $time_info = {
estimated_time => 0,
remaining_time => 0,
work_time => 0,
percentage_complete => 0,
interval_time => 0, # CustIS Bug 68921
time_present => ($estimated_time || $remaining_time ||
$work_time || $percentage_complete || $interval_time),
};
# Calculate totals
my $total_info;
for my $column (@$displaycolumns)
{
if (Bugzilla::Search->COLUMNS->{$column}->{numeric})
{
$total_info ||= {};
$total_info->{$column} = 0;
}
}
my $bugowners = {};
my $bugproducts = {};
@ -763,10 +757,10 @@ while (my @row = $buglist_sth->fetchrow_array())
push(@bugidlist, $bug->{bug_id});
# Compute time tracking info.
$time_info->{estimated_time} += $bug->{estimated_time} if $estimated_time;
$time_info->{remaining_time} += $bug->{remaining_time} if $remaining_time;
$time_info->{work_time} += $bug->{work_time} if $work_time;
$time_info->{interval_time} += $bug->{interval_time} if $interval_time;
for my $column (keys %$total_info)
{
$total_info->{$column} += $bug->{$column} if $column ne 'percentage_complete';
}
}
my $query_template_time = gettimeofday();
@ -806,15 +800,18 @@ if (@bugidlist)
}
# Compute percentage complete without rounding.
my $sum = $time_info->{work_time} + $time_info->{remaining_time};
if ($sum > 0)
if (exists $total_info->{percentage_complete})
{
$time_info->{percentage_complete} = 100*$time_info->{work_time}/$sum;
}
else
{
# remaining_time <= 0
$time_info->{percentage_complete} = 0
my $sum = $total_info->{work_time} + $total_info->{remaining_time};
if ($sum > 0)
{
$total_info->{percentage_complete} = 100*$total_info->{work_time}/$sum;
}
else
{
# remaining_time <= 0
$total_info->{percentage_complete} = 0
}
}
################################################################################
@ -877,7 +874,7 @@ $vars->{order_columns} = $orderstrings;
$vars->{order_dir} = [ map { s/ DESC$// ? 1 : 0 } @{$vars->{order_columns}} ];
$vars->{caneditbugs} = 1;
$vars->{time_info} = $time_info;
$vars->{total_info} = $total_info;
$vars->{query_params} = { %$params }; # now used only in superworktime
$vars->{query_params}->{chfieldfrom} = $search->{interval_from};

View File

@ -78,7 +78,8 @@ td.bz_total {
.bz_buglist .bz_estimated_time_column,
.bz_buglist .bz_remaining_time_column,
.bz_buglist .bz_work_time_column,
.bz_buglist .bz_percentage_complete_column { text-align: right; }
.bz_buglist .bz_percentage_complete_column,
.bz_buglist .bz_f30 { text-align: right; }
.bz_buglist .bz_short_desc_column,
.bz_buglist .bz_short_short_desc_column,

View File

@ -282,7 +282,7 @@
</tr>
[% IF loop.last() && time_info.time_present == 1 %]
[% IF loop.last() && total_info %]
[% PROCESS time_summary_line %]
[% END %]
@ -324,22 +324,18 @@
[% columns_to_span = columns_to_span + 1 %]
[% END %]
[% FOREACH column = displaycolumns %]
[% IF column == 'work_time' ||
column == 'remaining_time' ||
column == 'estimated_time' ||
column == 'percentage_complete' ||
column == 'interval_time' %]
[% IF total_info.defined(column) %]
[% IF columns_to_span > 0 %]
<td class="bz_total bz_total_label" colspan="
[%- columns_to_span FILTER html %]"><b>Totals</b></td>
[% columns_to_span = 0 %]
[% END %]
[% IF column == 'percentage_complete' %]
<td class="bz_total">[% time_info.percentage_complete
<td class="bz_total">[% total_info.percentage_complete
FILTER format(abbrev.$column.format_value) FILTER html %]</td>
[% ELSE %]
<td class="bz_total">
[%- PROCESS formattimeunit time_unit=time_info.$column %]</td>
[%- PROCESS formattimeunit time_unit=total_info.$column %]</td>
[% END %]
[% ELSIF columns_to_span == 0 %] [%# A column following the first total %]
<td class="bz_total">&nbsp;</td>