File Coverage

blib/lib/Tapper/Reports/Web/Util/Report.pm
Criterion Covered Total %
statement 23 62 37.1
branch 0 20 0.0
condition 0 21 0.0
subroutine 4 4 100.0
pod 0 1 0.0
total 27 108 25.0


line stmt bran cond sub pod time code
1             package Tapper::Reports::Web::Util::Report;
2             our $AUTHORITY = 'cpan:TAPPER';
3             $Tapper::Reports::Web::Util::Report::VERSION = '5.0.14';
4 11     11   92 use Moose;
  11         29  
  11         113  
5 11     11   78255 use Tapper::Model 'model';
  11         35  
  11         829  
6              
7             extends 'Tapper::Reports::Web::Util';
8              
9 11     11   100 use common::sense;
  11         37  
  11         108  
10              
11             sub prepare_simple_reportlist {
12              
13 1     1 0 4 my ( $self, $c, $reports ) = @_;
14              
15             # Mnemonic:
16             # rga = ReportGroup Arbitrary
17             # rgt = ReportGroup Testrun
18              
19 1         16 my $or_schema = model('TestrunDB');
20 1         15 my @all_reports;
21             my @reports;
22 1         0 my %rgt;
23 1         0 my %rga;
24 1         0 my %rgt_prims;
25 1         0 my %rga_prims;
26 1         7 while (my $report = $reports->next)
27             {
28 0         0 my %cols = $report->get_columns;
29 0         0 my $rga_id = $cols{rga_id};
30 0         0 my $rga_primary = $cols{rga_primary};
31 0         0 my $rgt_id = $cols{rgt_id};
32 0         0 my $rgt_primary = $cols{rgt_primary};
33 0   0     0 my $suite_name = $cols{suite_name} || 'unknownsuite';
34 0   0     0 my $suite_id = $cols{suite_id} || '0';
35 0 0 0     0 my $r = {
36             id => $report->id,
37             suite_name => $suite_name,
38             suite_id => $suite_id,
39             machine_name => $report->machine_name || 'unknownmachine',
40             created_at_ymd_hms => $report->created_at->ymd('-')." ".$report->created_at->hms(':'),
41             created_at_ymd_hm => sprintf("%s %02d:%02d",$report->created_at->ymd('-'), $report->created_at->hour, $report->created_at->minute),
42             created_at_ymd => $report->created_at->ymd('-'),
43             success_ratio => $report->success_ratio,
44             successgrade => $report->parse_errors ? 'ERROR' : $report->successgrade,
45             total => $report->total,
46             rga_id => $rga_id,
47             rga_primary => $rga_primary,
48             rgt_id => $rgt_id,
49             rgt_primary => $rgt_primary,
50             parse_errors => $report->parse_errors,
51             peerport => $report->peerport,
52             peeraddr => $report->peeraddr,
53             peerhost => $report->peerhost,
54             };
55              
56             # --- scheduling state ---
57 0         0 my $testrun_scheduling = $or_schema->resultset('TestrunScheduling')->search({testrun_id => $rgt_id}, {rows => 1})->first;
58 0 0       0 $r->{testrunscheduling_status} = $testrun_scheduling->status if $testrun_scheduling;
59              
60             # --- arbitrary ---
61 0 0 0     0 if ($rga_id and $rga_primary)
62             {
63 0         0 $r->{owner} = $report->reportgrouparbitrary->owner;
64 0         0 push @reports, $r;
65 0         0 $rga_prims{$rga_id} = 1;
66             }
67 0 0 0     0 if ($rga_id and not $rga_primary)
68             {
69 0         0 push @{$rga{$rga_id}}, $r;
  0         0  
70             }
71              
72             # --- testrun ---
73 0 0 0     0 if ($rgt_id and $rgt_primary)
74             {
75 0         0 $r->{owner} = $report->reportgrouptestrun->owner;
76 0         0 push @reports, $r;
77 0         0 $rgt_prims{$rgt_id} = 1;
78             }
79 0 0 0     0 if ($rgt_id and not $rgt_primary)
80             {
81 0         0 push @{$rgt{$rgt_id}}, $r;
  0         0  
82             }
83              
84             # --- none ---
85 0 0 0     0 if (! $rga_id and ! $rgt_id)
86             {
87 0         0 push @reports, $r;
88             }
89              
90 0         0 push @all_reports, $r; # for easier overall stats
91             }
92              
93             # Find groups without primary report
94 1         15253 my @rga_noprim;
95             my @rgt_noprim;
96 1         7 foreach (keys %rga) {
97 0 0       0 push @rga_noprim, $_ unless $rga_prims{$_};
98             }
99 1         4 foreach (keys %rgt) {
100 0 0       0 push @rgt_noprim, $_ unless $rgt_prims{$_};
101             }
102             # Pull out latest one and put into @reports as primary
103 1         4 foreach (@rga_noprim) {
104 0         0 my $rga_primary = pop @{$rga{$_}};
  0         0  
105 0         0 $rga_primary->{rga_primary} = 1;
106 0         0 push @reports, $rga_primary;
107             }
108 1         4 foreach (@rgt_noprim) {
109 0         0 my $rgt_primary = pop @{$rgt{$_}};
  0         0  
110 0         0 $rgt_primary->{rgt_primary} = 1;
111              
112 0         0 my $testrun = model('TestrunDB')->resultset('Testrun')->find($_);
113 0 0       0 $rgt_primary->{owner} = $testrun->owner->login if $testrun;
114              
115 0         0 push @reports, $rgt_primary;
116             }
117              
118             return {
119 1         49 all_reports => \@all_reports,
120             reports => \@reports,
121             rga => \%rga,
122             rgt => \%rgt,
123             };
124             }
125              
126              
127             1;
128              
129             __END__
130              
131             =pod
132              
133             =encoding UTF-8
134              
135             =head1 NAME
136              
137             Tapper::Reports::Web::Util::Report
138              
139             =head1 AUTHORS
140              
141             =over 4
142              
143             =item *
144              
145             AMD OSRC Tapper Team <tapper@amd64.org>
146              
147             =item *
148              
149             Tapper Team <tapper-ops@amazon.com>
150              
151             =back
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is Copyright (c) 2019 by Advanced Micro Devices, Inc..
156              
157             This is free software, licensed under:
158              
159             The (two-clause) FreeBSD License
160              
161             =cut