Tapper/Reports/DPath.pm

filter: Statementstmt 75.9% 177 / 233 Branchbran 62.5% 65 / 104 Conditioncond 47.8% 11 / 23 MC/DCmcdc 28.5% 4 / 14 Subroutinesub 84.8% 28 / 33 Podpod 100% 10 / 10 totaltotal 70.7% 295 / 417 CC 65 SCAR 23.5
CC
65
Cov
70%
cached_whole_dpath
28.7
testplan_dpath_search
20.0
_groupcontext
19.0
CRAP 10.5
↑ Summary Tapper/Reports/DPath/Mason.pm »
1 ## no critic (RequireUseStrict)
2 package Tapper::Reports::DPath;
3 # git description: v5.0.4-3-g41ece2e
4  
5 11 our $AUTHORITY = 'cpan:TAPPER';
6 # ABSTRACT: Tapper - Extended DPath functionality for Tapper reports
7 11 $Tapper::Reports::DPath::VERSION = '5.0.5';
8 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶ use Tapper::Model 'model', 'get_hardware_overview'; #, 'get_systems_id_for_hostname'
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶ use Text::Balanced 'extract_codeblock';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶ use Data::DPath::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶ use CHI;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 11 our $puresqlabstract = 0;
18  
19 11 ▶ use Sub::Exporter -setup => { exports => [ 'reportdata', 'testrundata', 'testplandata' ],
Subroutine BEGIN: called CC=1 SCAR=0.0
20 groups => { all => [ 'reportdata', 'testrundata', 'testplandata' ] },
21 11 };
22  
23 38 ▶ sub _extract_condition_attrs_and_path {
Subroutine _extract_condition_attrs_and_path: called CC=2 SCAR=6.9
24 38 my ($query_path) = @_;
25  
26 38 my $condition;
27 my $attrs;
28 38 my $path;
29  
30 38 my $head;
31 38 my $tail;
32 38 my $count;
33  
34 # first codeblock is condition
35 38 ($condition, $tail) = extract_codeblock($query_path, '{}');
36 38 $count = ($tail =~ s/^\s*::\s*//g);
37  
38 # Maybe there is an optional second codeblock (attrs)
39 # but we need to find out by looking for a third block
40 # and then decide.
41 38 ($head, $tail) = extract_codeblock($tail, '{}');
42 38 $count = ($tail =~ s/^\s*::\s*//g);
43  
44 38 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) { } 6 32 38
45 6 $attrs = $head;
46 6 $path = $tail;
47 } else {
48 32 $attrs = undef;
49 32 $path = $head;
50 }
51  
52 # tail is path
53 38 $path = $tail;
54 38 return ($condition, $attrs, $path);
55 }
56  
57 # backwards compatible frontend to new triplet API
58 23 ▶ sub _extract_condition_and_path {
Subroutine _extract_condition_and_path: called CC=1 SCAR=0.0
59 23 my ($condition, $attrs, $path) = _extract_condition_attrs_and_path(@_);
60 23 warn "DEPRECATED _extract_condition_and_path() - use _extract_condition_attrs_and_path()\n";
61 23 return ($condition, $path); # no attrs
62 }
63  
64 # frontend alias for reports_dpath_search
65 16 ▶ sub reportdata { reports_dpath_search(@_) } ## no critic (ProhibitSubroutinePrototypes)
Subroutine reportdata: called CC=1 SCAR=0.0
Pod documented
66  
67 # frontend alias for testrun_dpath_search
68 3 ▶ sub testrundata { testrun_dpath_search(@_) } ## no critic (ProhibitSubroutinePrototypes)
Subroutine testrundata: called CC=1 SCAR=0.0
Pod documented
69  
70 # frontend alias for testplan_dpath_search
71 0 ▶ sub testplandata { testplan_dpath_search(@_) } ## no critic (ProhibitSubroutinePrototypes)
Subroutine testplandata: not called CC=1 SCAR=6.9
Pod documented
72  
73 # allow trivial better readable column names
74 # - foo => 23 ... mapped to "me.foo" => 23
75 # - "report.foo" => 23 ... mapped to "me.foo" => 23
76 # - suite_name => "bar" ... mapped to "suite.name" => "bar"
77 # - -and => ... ... mapped to "-and" => ... # just to ensure that it doesn't produce: "me.-and" => ...
78 sub _fix_condition_reportdata
79 55 ▶ {
Subroutine _fix_condition_reportdata: called CC=1 SCAR=0.0
80 11 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 55 my $SQLKEYWORDS = 'like|-in|-and|-or';
82 55 my ($condition) = @_;
83 # joined suite
84 55 $condition =~ s/(['"])?\bsuite_name\b(['"])?\s*=>/"suite.name" =>/; # ';
85 55 $condition =~ s/(['"])?\breportgroup_testrun_id\b(['"])?\s*=>/"reportgrouptestrun.testrun_id" =>/; # ';
86 55 $condition =~ s/(['"])?\breportgroup_arbitrary_id\b(['"])?\s*=>/"reportgrouparbitrary.arbitrary_id" =>/; # ';
87 55 $condition =~ s/([^-\w])(['"])?((report|me)\.)?(?<!suite\.)(?<!reportgrouparbitrary\.)(?<!reportgrouptestrun\.)(?!$SQLKEYWORDS)(\w+)\b(['"])?(\s*)=>/$1"me.$5" =>/; # ';
88  
89 55 return $condition;
90  
91 }
92  
93 # allow trivial better readable column names
94 # - foo => 23 ... mapped to "me.foo" => 23
95 # - "report.foo" => 23 ... mapped to "me.foo" => 23
96 # - testrun_id => 23 ... mapped to "me.testrun_id" => 23
97 # - suite_name => "bar" ... mapped to "suite.name" => "bar"
98 # - -and => ... ... mapped to "-and" => ... # just to ensure that it doesn't produce: "me.-and" => ...
99 sub _fix_condition_testrundata
100 3 ▶ {
Subroutine _fix_condition_testrundata: called CC=1 SCAR=0.0
101 11 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
102 3 my $SQLKEYWORDS = 'like|-in|-and|-or';
103 3 my ($condition) = @_;
104 # joined suite
105 3 $condition =~ s/([^-\w])(?<!\.)(['"])?((host|queue|testrun)_)(\w+)\b(['"])?(\s*)=>/$1"$4.$5" =>/g; # ';
106 3 return $condition;
107  
108 }
109  
110 # ===== CACHE =====
111  
112 # ----- cache complete Tapper::Reports::DPath queries -----
113  
114 0 ▶ sub _cachekey_whole_dpath {
Subroutine _cachekey_whole_dpath: not called CC=2 SCAR=17.9
115 0 my ($query_path) = @_;
116 0 ▶ my $key = ($ENV{TAPPER_DEVELOPMENT} || "0") . '::' . $query_path;
Condition0%0/2
$ENV{'TAPPER_DEVELOPMENT'} || '0'
l!l
00
MC/DC0%0/1
$ENV{'TAPPER_DEVELOPMENT'} || '0'
$ENV{'TAPPER_DEVELOPMENT'}
Truth table0%0/2
A
A= $ENV{'TAPPER_DEVELOPMENT'}
Aresult
11
00
117 0 return $key;
118 }
119  
120 19 ▶ sub cache_whole_dpath {
Subroutine cache_whole_dpath: called CC=3 SCAR=17.3
Pod documented
121 19 my ($query_path, $rs_count, $res) = @_;
122  
123 19 ▶ return if $ENV{HARNESS_ACTIVE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 19 0 19
124  
125 0 my $cache = CHI->new( driver => 'File',
126 root_dir => '/tmp/cache/dpath',
127 serializer => 'Data::Dumper',
128 compress => 1,
129 );
130  
131 0 ▶ $cache->clear() if -e '/tmp/TAPPER_CACHE_CLEAR';
Branch: 1 branch
BranchTrueFalseTotal
if -e "/tmp/TAPPER_CACHE_CLEAR" 0 0 0
132  
133 # we cache on the dpath
134 # but need count to verify and maintain cache validity
135  
136 # say STDERR " -> set whole: $query_path ($rs_count)";
137 0 $cache->set( _cachekey_whole_dpath($query_path),
138 {
139 count => $rs_count,
140 res => $res,
141 });
142 }
143  
144 19 ▶ sub cached_whole_dpath {
Subroutine cached_whole_dpath: called CC=6 SCAR=33.6
Pod documented
145 19 my ($query_path, $rs_count) = @_;
146  
147 19 ▶ return if $ENV{HARNESS_ACTIVE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 19 0 19
148  
149 0 my $cache = CHI->new( driver => 'File',
150 root_dir => '/tmp/cache/dpath',
151 serializer => 'Data::Dumper',
152 compress => 1,
153 );
154 0 ▶ $cache->clear() if -e '/tmp/TAPPER_CACHE_CLEAR';
Branch: 1 branch
BranchTrueFalseTotal
if -e "/tmp/TAPPER_CACHE_CLEAR" 0 0 0
155 0 my $cached_res = $cache->get( _cachekey_whole_dpath($query_path) );
156  
157 0 ▶ my $cached_res_count = $cached_res->{count} || 0;
Condition0%0/2
$cached_res->{'count'} || 0
l!l
00
MC/DC0%0/1
$cached_res->{'count'} || 0
$cached_res->{'count'}
Truth table0%0/2
A
A= $cached_res->{'count'}
Aresult
11
00
158 # say STDERR " <- get whole: $query_path ($rs_count vs. $cached_res_count)";
159 0 ▶ return if not defined $cached_res;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cached_res 0 0 0
160  
161 0 ▶ if ($cached_res_count == $rs_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached_res_count == $rs_count) 0 0 0
162 # say STDERR " Gotcha!";
163 return $cached_res->{res}
164 0 }
165  
166 # clean up when matching report count changed
167 0 $cache->remove( $query_path );
168 0 return;
169 }
170  
171 # ----- cache single report dpaths queries -----
172  
173 0 ▶ sub _cachekey_single_dpath {
Subroutine _cachekey_single_dpath: not called CC=2 SCAR=17.9
174 0 my ($path, $reports_id) = @_;
175 0 ▶ my $key = ($ENV{TAPPER_DEVELOPMENT} || "0") . '::' . $reports_id."::".$path;
Condition0%0/2
$ENV{'TAPPER_DEVELOPMENT'} || '0'
l!l
00
MC/DC0%0/1
$ENV{'TAPPER_DEVELOPMENT'} || '0'
$ENV{'TAPPER_DEVELOPMENT'}
Truth table0%0/2
A
A= $ENV{'TAPPER_DEVELOPMENT'}
Aresult
11
00
176 #say STDERR " . $key";
177 0 return $key;
178 }
179  
180 41 ▶ sub cache_single_dpath {
Subroutine cache_single_dpath: called CC=3 SCAR=17.3
Pod documented
181 41 my ($path, $cache_key, $res) = @_;
182  
183 41 ▶ return if $ENV{HARNESS_ACTIVE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 41 0 41
184  
185 0 my $cache = CHI->new( driver => 'File',
186 root_dir => '/tmp/cache/dpath',
187 serializer => 'Data::Dumper',
188 compress => 1,
189 );
190 0 ▶ $cache->clear() if -e '/tmp/TAPPER_CACHE_CLEAR';
Branch: 1 branch
BranchTrueFalseTotal
if -e "/tmp/TAPPER_CACHE_CLEAR" 0 0 0
191 0 $cache->set( _cachekey_single_dpath( $path, $cache_key ),
192 $res
193 );
194 }
195  
196 41 ▶ sub cached_single_dpath {
Subroutine cached_single_dpath: called CC=3 SCAR=18.1
Pod documented
197 41 my ($path, $cache_key) = @_;
198  
199 41 ▶ return if $ENV{HARNESS_ACTIVE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 41 0 41
200  
201 0 my $cache = CHI->new( driver => 'File',
202 root_dir => '/tmp/cache/dpath',
203 serializer => 'Data::Dumper',
204 compress => 1,
205 );
206 0 ▶ $cache->clear() if -e '/tmp/TAPPER_CACHE_CLEAR';
Branch: 1 branch
BranchTrueFalseTotal
if -e "/tmp/TAPPER_CACHE_CLEAR" 0 0 0
207 0 my $cached_res = $cache->get( _cachekey_single_dpath( $path, $cache_key ));
208  
209 # print STDERR " <- get single: $cache_key -- $path: ".Dumper($cached_res);
210 0 return $cached_res;
211 }
212  
213 # ===== the query search =====
214  
215 16 ▶ sub reports_dpath_search($) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine reports_dpath_search: called CC=6 SCAR=18.1
Pod documented
216 16 my ($query_path) = @_;
217  
218 16 my ($condition, $path) = _extract_condition_and_path($query_path);
219 16 $path =~ s/^\s+|\s+$//; # drop leading+trailing whitespace
220 16 my $dpath = new Data::DPath::Path( path => $path );
221 16 ▶ $condition = _fix_condition_reportdata($condition) unless $puresqlabstract;
Branch: 1 branch
BranchTrueFalseTotal
unless $Tapper::Reports::DPath::puresqlabstract 16 0 16
222 16 ▶ my %condition = $condition ? %{ eval $condition } : (); ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 15 1 16
223 16 my $rs = model('TestrunDB')->resultset('Report')->search
224 (
225 {
226 %condition
227 },
228 {
229 order_by => 'me.id asc',
230 columns => [ qw(
231 id
232 suite_id
233 suite_version
234 reportername
235 peeraddr
236 peerport
237 peerhost
238 successgrade
239 total
240 failed
241 parse_errors
242 passed
243 skipped
244 todo
245 todo_passed
246 success_ratio
247 starttime_test_program
248 endtime_test_program
249 machine_name
250 machine_description
251 created_at
252 updated_at
253 )],
254 join => [ 'suite', 'reportgrouptestrun', 'reportgrouparbitrary' ],
255 '+select' => [ 'suite.name', 'reportgrouptestrun.testrun_id', 'reportgrouparbitrary.arbitrary_id'],
256 '+as' => [ 'suite.name', 'reportgrouptestrun.testrun_id', 'reportgrouparbitrary.arbitrary_id'],
257 }
258 );
259 16 my $rs_count = $rs->count();
260 16 my @res = ();
261  
262 # layer 2 cache
263 16 my $cached_res = cached_whole_dpath( $query_path, $rs_count );
264 16 ▶ return @$cached_res if defined $cached_res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cached_res 0 16 16
265  
266 16 ▶ while (my $row = $rs->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $rs->next) 34 16 50
267 {
268 34 my $report_id = $row->id;
269  
270 # layer 1 cache
271 34 my $cached_row_res = cached_single_dpath( $path, "r$report_id" );
272  
273 34 ▶ if (defined $cached_row_res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cached_row_res) 0 34 34
274 0 push @res, @$cached_row_res;
275 0 next;
276 }
277  
278 34 my $data = _report_as_data($row);
279 34 my @row_res = $dpath->match( $data );
280  
281 34 cache_single_dpath($path, "r$report_id", \@row_res);
282  
283 34 push @res, @row_res;
284 }
285  
286 16 cache_whole_dpath($query_path, $rs_count, \@res);
287  
288 16 return @res;
289 }
290  
291 3 ▶ sub testrun_dpath_search($) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine testrun_dpath_search: called CC=11 SCAR=24.3
Pod documented
292 3 my ($query_path, $nohost) = @_;
293  
294 #my ($condition, $path) = _extract_condition_and_path($query_path);
295 3 my ($condition, $attrs, $path) = _extract_condition_attrs_and_path($query_path);
296 3 my $dpath = Data::DPath::Path->new( path => $path );
297 3 ▶ $condition = _fix_condition_testrundata($condition) unless $puresqlabstract;
Branch: 1 branch
BranchTrueFalseTotal
unless $Tapper::Reports::DPath::puresqlabstract 3 0 3
298 3 ▶ my %condition = $condition ? %{ eval $condition } : (); ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 3 0 3
299 3 ▶ my %attrs = $attrs ? %{ eval $attrs } : (); ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
$attrs ? : 3 0 3
300  
301 3 ▶ my $joins = [ ($nohost ? () : ('host')), 'requested_hosts', 'requested_features', 'queue', 'testrun' ];
Branch: 1 branch
BranchTrueFalseTotal
$nohost ? : 2 1 3
302 3 ▶ my $selects = [ ($nohost ? () : ('host.name', 'host.free', 'host.active')), 'queue.name', 'testrun.shortname', 'testrun.notes', 'testrun.starttime_testrun', 'testrun.starttime_test_program', 'testrun.endtime_test_program', 'testrun.owner_id', 'testrun.testplan_id', 'testrun.wait_after_tests', 'testrun.rerun_on_error', 'testrun.created_at', 'testrun.updated_at', 'testrun.topic_name', ];
Branch: 1 branch
BranchTrueFalseTotal
$nohost ? : 2 1 3
303 3 ▶ my $as = [ ($nohost ? () : ('host_name', 'host_free', 'host_active')), 'queue_name', 'testrun_shortname', 'testrun_notes', 'testrun_starttime_testrun', 'testrun_starttime_test_program', 'testrun_endtime_test_program', 'testrun_owner_id', 'testrun_testplan_id', 'testrun_wait_after_tests', 'testrun_rerun_on_error', 'testrun_created_at', 'testrun_updated_at', 'testrun_topic_name', ];
Branch: 1 branch
BranchTrueFalseTotal
$nohost ? : 2 1 3
304  
305 3 ▶ my %merged_attrs = (
Branch: 1 branch
BranchTrueFalseTotal
$nohost ? : 2 1 3
306 order_by => 'testrun_id asc',
307 columns => [ qw(
308 testrun_id
309 queue_id
310 prioqueue_seq
311 status
312 auto_rerun
313 created_at
314 updated_at
315 ),
316 ($nohost ? () : ('host_id')),
317 ],
318 join => $joins,
319 '+select' => $selects,
320 '+as' => $as,
321 limit => 10,
322 %attrs,
323 );
324  
325 3 print STDERR "query: $query_path\n";
326 # print STDERR "testrun_dpath_search: ".Dumper(
327 # {
328 # condition => \%condition,
329 # attrs => \%attrs,
330 # merged_attrs => \%merged_attrs,
331 # });
332  
333 3 my $rs = model('TestrunDB')->resultset('TestrunScheduling')->search
334 (
335 { %condition },
336 { %merged_attrs },
337 );
338  
339 #print STDERR Dumper($rs);
340  
341 3 my $rs_count = $rs->count();
342 3 my @res = ();
343  
344 # layer 2 cache
345 3 my $cached_res = cached_whole_dpath( $query_path, $rs_count );
346 3 ▶ return @$cached_res if defined $cached_res;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cached_res 0 3 3
347  
348 3 ▶ while (my $row = $rs->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $rs->next) 7 3 10
349 {
350 7 my $testrun_id = $row->testrun_id;
351  
352 # layer 1 cache
353 7 my $cached_row_res = cached_single_dpath( $path, "tr$testrun_id" );
354  
355 7 ▶ if (defined $cached_row_res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cached_row_res) 0 7 7
356 0 push @res, @$cached_row_res;
357 0 next;
358 }
359  
360 7 my $data = _testrun_as_data($row, $nohost);
361 7 my @row_res = $dpath->match( $data );
362  
363 7 cache_single_dpath($path, "tr$testrun_id", \@row_res);
364  
365 7 push @res, @row_res;
366 }
367  
368 3 cache_whole_dpath($query_path, $rs_count, \@res);
369  
370 3 return @res;
371 }
372  
373 0 ▶ sub testplan_dpath_search($) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine testplan_dpath_search: not called CC=4 SCAR=30.0
Pod documented
374 0 my ($query_path) = @_;
375  
376 0 my ($condition, $attrs, $path) = _extract_condition_attrs_and_path($query_path);
377 0 my $dpath = Data::DPath::Path->new( path => $path );
378 0 ▶ my %condition = $condition ? %{ eval $condition } : (); ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 0 0 0
379 0 ▶ my %attrs = $attrs ? %{ eval $attrs } : (); ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
$attrs ? : 0 0 0
380  
381 0 print STDERR "testplan_dpath_search: ".Dumper(
382 {
383 condition => \%condition,
384 attrs => \%attrs,
385 });
386 0 my $rs = model('TestrunDB')->resultset('TestplanInstance')->search
387 (
388 {
389 %condition
390 },
391 {
392 order_by => 'id asc',
393 columns => [ qw(
394 id
395 path
396 name
397 evaluated_testplan
398 created_at
399 updated_at
400 )],
401 limit => 10,
402 %attrs,
403 }
404 );
405  
406 #print STDERR Dumper($rs);
407  
408 0 my @res = ();
409  
410 0 ▶ while (my $row = $rs->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $rs->next) 0 0 0
411 {
412 0 my $testplan_id = $row->id;
413  
414 0 my $data = _testplan_as_data($row);
415 0 my @row_res = $dpath->match( $data );
416  
417 0 push @res, @row_res;
418 }
419  
420 0 return @res;
421 }
422  
423 1 ▶ sub _dummy_needed_for_tests {
Subroutine _dummy_needed_for_tests: called CC=1 SCAR=0.0
424 # once there were problems with eval
425 1 return eval "12345"; ## no critic (ProhibitStringyEval)
426 }
427  
428 36 ▶ sub _groupcontext {
Subroutine _groupcontext: called CC=19 SCAR=29.5
429 36 my ($report) = @_;
430  
431 36 my %groupcontext = ();
432 36 my $id = $report->id;
433 36 my $rga = $report->reportgrouparbitrary;
434 36 my $rgt = $report->reportgrouptestrun;
435 36 ▶ my %groupreports = (
Branch: 4 branches
BranchTrueFalseTotal
$rga ? : 15 21 36
$rga ? : 15 21 36
$rgt ? : 30 6 36
$rgt ? : 30 6 36
436 arbitrary => $rga ? scalar $rga->groupreports : undef,
437 arbitrary_id => $rga ? $rga->arbitrary_id : undef,
438 testrun => $rgt ? scalar $rgt->groupreports : undef,
439 testrun_id => $rgt ? $rgt->testrun_id : undef,
440 );
441  
442 # if ($report->reportgrouptestrun) {
443 # my $rgt_id = $report->reportgrouptestrun->testrun_id;
444 # my $rgt_reports = model('TestrunDB')->resultset('ReportgroupTestrun')->search({ testrun_id => $rgt_id});
445 # # say STDERR "\nrgt $rgt_id count: ", $rgt_reports->count;
446 # }
447  
448 36 foreach my $type (qw(arbitrary testrun))
449 {
450 72 ▶ next unless $groupreports{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $groupreports{$type} 27 45 72
451 45 my $group_id = $groupreports{"${type}_id"};
452  
453 # say STDERR "${type}_id: ", $groupreports{"${type}_id"};
454 # say STDERR " groupreports{$type}.count: ", $groupreports{$type}->count;
455 # say STDERR "* $id - groupreports{$type}.count: ", $groupreports{$type}->count;
456 45 ▶ while (my $groupreport = $groupreports{$type}->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $groupreport = $groupreports{$type}->next) 120 45 165
457 {
458 120 my $groupreport_id = $groupreport->id;
459 # say STDERR " gr.id: $groupreport_id";
460 120 my @greportsection_meta = ();
461 120 my $grsections = $groupreport->reportsections;
462 # say STDERR "* $groupreport_id GROUPREPORT_SECTIONS count: ", $grsections->count;
463 120 ▶ while (my $section = $grsections->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $section = $grsections->next) 180 120 300
464 {
465 180 my %columns = $section->get_columns;
466 180 foreach (keys %columns) {
467 8100 ▶ delete $columns{$_} unless defined $columns{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $columns{$_} 6795 1305 8100
468 }
469 180 delete $columns{$_} foreach qw(succession name id report_id);
470 180 ▶ push @greportsection_meta, {
Branch: 1 branch
BranchTrueFalseTotal
if keys %columns 180 0 180
471 $section->name => {
472 %columns
473 }
474 }
475 if keys %columns;
476 }
477 120 my $primary = 0;
478 120 ▶ $primary = 1 if $type eq "arbitrary" && $groupreport->reportgrouparbitrary->primaryreport;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "arbitrary" and $groupreport->reportgrouparbitrary->primaryreport 0 120 120
Condition66%2/3
$type eq "arbitrary" and $groupreport->reportgrouparbitrary->primaryreport
!ll&&!rl&&r
90300
MC/DC0%0/2
$type eq "arbitrary" and $groupreport->reportgrouparbitrary->primaryreport
$type eq "arbitrary" $groupreport->reportgrouparbitrary->primaryreport
Truth table66%2/3
A and B
A= $type eq "arbitrary"B= $groupreport->reportgrouparbitrary->primaryreport
ABresult
0X0
100
111
479 120 ▶ $primary = 1 if $type eq "testrun" && $groupreport->reportgrouptestrun->primaryreport;
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "testrun" and $groupreport->reportgrouptestrun->primaryreport 30 90 120
Condition100%3/3
$type eq "testrun" and $groupreport->reportgrouptestrun->primaryreport
!ll&&!rl&&r
306030
MC/DC100%2/2
$type eq "testrun" and $groupreport->reportgrouptestrun->primaryreport
$type eq "testrun" $groupreport->reportgrouptestrun->primaryreport
Truth table100%3/3
A and B
A= $type eq "testrun"B= $groupreport->reportgrouptestrun->primaryreport
ABresult
0X0
100
111
480  
481 120 ▶ $groupcontext{$type}{$group_id}{$groupreport_id}{myself} = $groupreport_id == $id ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$groupreport_id == $id ? : 45 75 120
482 120 ▶ $groupcontext{$type}{$group_id}{$groupreport_id}{primary} = $primary ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$primary ? : 30 90 120
483 120 $groupcontext{$type}{$group_id}{$groupreport_id}{meta} = \@greportsection_meta;
484 }
485 }
486  
487 # say STDERR Dumper(\%groupcontext);
488 36 return \%groupcontext;
489 }
490  
491 36 ▶ sub _reportgroupstats {
Subroutine _reportgroupstats: called CC=5 SCAR=16.1
492 36 my ($report) = @_;
493  
494 36 my $rgt = $report->reportgrouptestrun;
495 36 my $reportgroupstats = {};
496  
497 # create report group stats
498 36 ▶ if ($report->reportgrouptestrun and $report->reportgrouptestrun->testrun_id)
Branch: 1 branch
BranchTrueFalseTotal
if ($report->reportgrouptestrun and $report->reportgrouptestrun->testrun_id) 30 6 36
Condition66%2/3
$report->reportgrouptestrun and $report->reportgrouptestrun->testrun_id
!ll&&!rl&&r
6030
MC/DC50%1/2
$report->reportgrouptestrun and $report->reportgrouptestrun->testrun_id
$report->reportgrouptestrun $report->reportgrouptestrun->testrun_id
Truth table66%2/3
A and B
A= $report->reportgrouptestrunB= $report->reportgrouptestrun->testrun_id
ABresult
0X0
100
111
499 {
500 30 my $rgt_stats = model('TestrunDB')->resultset('ReportgroupTestrunStats')->find($rgt->testrun_id);
501 30 ▶ unless ($rgt_stats and $rgt_stats->testrun_id)
Branch: 1 branch
BranchTrueFalseTotal
unless ($rgt_stats and $rgt_stats->testrun_id) 3 27 30
Condition66%2/3
$rgt_stats and $rgt_stats->testrun_id
!ll&&!rl&&r
3027
MC/DC50%1/2
$rgt_stats and $rgt_stats->testrun_id
$rgt_stats $rgt_stats->testrun_id
Truth table66%2/3
A and B
A= $rgt_statsB= $rgt_stats->testrun_id
ABresult
0X0
100
111
502 {
503 # This is just a fail-back mechanism, in case the "fix-missinging-groupstats" script has not yet been run.
504 3 $rgt_stats = model('TestrunDB')->resultset('ReportgroupTestrunStats')->new({ testrun_id => $rgt->testrun_id});
505 3 $rgt_stats->update_failed_passed;
506 3 $rgt_stats->insert;
507 }
508 30 my @stat_fields = (qw/failed passed total parse_errors skipped todo todo_passed success_ratio/);
509 11 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
510 $reportgroupstats = {
511 30 map { ($_ => $rgt_stats->$_ ) } @stat_fields
512 };
513 }
514 36 return $reportgroupstats;
515 }
516  
517 sub _report_as_data
518 36 ▶ {
Subroutine _report_as_data: called CC=8 SCAR=22.8
519 36 my ($report) = @_;
520  
521 36 my $hwdb;
522 36 ▶ if (my $host = model('TestrunDB')->resultset("Host")->search({name => $report->machine_name}, {rows => 1})->first) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = model("TestrunDB")->resultset("Host")->search({"name", $report->machine_name}, {"rows", 1})->first) 0 36 36
523 0 $hwdb = get_hardware_overview($host->id);
524 }
525 36 ▶ my %hardwaredb_overview = (defined($hwdb) and %$hwdb) ? (hardwaredb => $hwdb) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $hwdb && %$hwdb ? : 0 36 36
Condition33%1/3
defined $hwdb and %$hwdb
!ll&&!rl&&r
3600
MC/DC0%0/2
defined $hwdb and %$hwdb
defined $hwdb %$hwdb
Truth table33%1/3
A and B
A= defined $hwdbB= %$hwdb
ABresult
0X0
100
111
526  
527 36 my $reportgroupstats = _reportgroupstats($report);
528  
529 36 ▶ my $simple_hash = {
Branch: 3 branches
BranchTrueFalseTotal
$report->suite ? : 36 0 36
$report->reportgrouptestrun ? : 30 6 36
$report->reportgrouparbitrary ? : 15 21 36
Condition50%1/2
$report->machine_name || 'unknown'
l!l
036
MC/DC0%0/1
$report->machine_name || 'unknown'
$report->machine_name
Truth table50%1/2
A
A= $report->machine_name
Aresult
11
00
530 report => {
531 $report->get_columns,
532 suite_name => $report->suite ? $report->suite->name : 'unknown',
533 reportgroup_testrun_id => $report->reportgrouptestrun ? $report->reportgrouptestrun->testrun_id : undef,
534 reportgroup_arbitrary_id => $report->reportgrouparbitrary ? $report->reportgrouparbitrary->arbitrary_id : undef,
535 machine_name => $report->machine_name || 'unknown',
536 created_at_ymd_hms => $report->created_at->ymd('-')." ".$report->created_at->hms(':'),
537 created_at_ymd => $report->created_at->ymd('-'),
538 %hardwaredb_overview,
539 groupstats => {
540 DEPRECATED => 'BETTER_USE_groupstats_FROM_ONE_LEVEL_ABOVE',
541 %$reportgroupstats,
542 },
543 },
544 results => $report->get_cached_tapdom,
545 groupcontext => _groupcontext($report),
546 groupstats => $reportgroupstats,
547 };
548 36 return $simple_hash;
549 }
550  
551 sub _testrun_as_data
552 7 ▶ {
Subroutine _testrun_as_data: called CC=2 SCAR=6.9
553 7 my ($testrun, $nohost) = @_;
554  
555 7 ▶ my $simple_hash = {
Branch: 1 branch
BranchTrueFalseTotal
$nohost ? : 5 2 7
556 testrun => {
557 $testrun->get_columns,
558 },
559 ($nohost ? () : ( host => { $testrun->host->get_columns } ) ),
560 queue => {
561 $testrun->queue->get_columns,
562 },
563 };
564 7 return $simple_hash;
565 }
566  
567 sub _testplan_as_data
568 0 ▶ {
Subroutine _testplan_as_data: not called CC=3 SCAR=24.8
569 0 my ($testplan) = @_;
570  
571 0 my @testruns = $testplan->testruns->all;
572  
573 my $simple_hash = {
574 testplan => {
575 id => $testplan->id,
576 name => $testplan->name,
577 created_at_ymd_hms => $testplan->created_at->ymd('-')." ".$testplan->created_at->hms(':'),
578 created_at_ymd => $testplan->created_at->ymd('-'),
579 #testplan_evaluated_testplan => $testplan->evaluated_testplan,
580 },
581 testruns => [
582 map {
583 0 my $ts = $_->testrun_scheduling;
584 0 my $rgts = $_->reportgrouptestrunstats;
585 0 my $host = $ts->host;
586 0 ▶ my $host_name = $host ? $host->name : 'undefined_host';
Branch: 1 branch
BranchTrueFalseTotal
$host ? : 0 0 0
587 {
588 0 ▶ id => $_->id,
Branch: 1 branch
BranchTrueFalseTotal
$rgts ? : 0 0 0
589 topic_name => $_->topic_name,
590 host_name => $host_name,
591 status => $ts->status->value,
592 stats => {
593 $rgts ? $rgts->get_columns : (),
594 },
595 }
596 } @testruns
597 ],
598 };
599 0 return $simple_hash;
600 }
601  
602 11 1;
603  
604 __END__
↑ Summary Tapper/Reports/DPath/Mason.pm »