| 1 | package Test2::Harness::UI::Schema::Result::Project; | ||||||||||||||
| 2 | 2 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 2 | ▶ | use Statistics::Basic qw/median/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | ▶ | use Test2::Harness::UI::UUID qw/uuid_deflate/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 2 | ▶ | use Carp qw/confess/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 2 | ▶ | confess "You must first load a Test2::Harness::UI::Schema::NAME module" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 11 | unless $Test2::Harness::UI::Schema::LOADED; | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 2 | our $VERSION = '0.000150'; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub last_covered_run { | ||||||||||||
|
Subroutine
last_covered_run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 16 | 0 | my $self = shift; | |||||||||||||
| 17 | 0 | my %params = @_; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | my $query = { | |||||||||||||
| 20 | status => 'complete', | ||||||||||||||
| 21 | project_id => $self->project_id, | ||||||||||||||
| 22 | has_coverage => 1, | ||||||||||||||
| 23 | }; | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | my $attrs = { | |||||||||||||
| 26 | order_by => {'-desc' => 'run_ord'}, | ||||||||||||||
| 27 | rows => 1, | ||||||||||||||
| 28 | }; | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | ▶ | if ($params{user}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 0 | $query->{'user.username'} = $params{user}; | |||||||||||||
| 32 | 0 | ▶ | push @{$attrs->{join} //= []} => 'user'; | ||||||||||||
|
Condition0%0/2
$attrs->{"join"} //= []
MC/DC0%0/1
$attrs->{"join"} //= []
$attrs->{"join"}
Truth table0%0/2
A
A= $attrs->{"join"}
| |||||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | my $schema = $self->result_source->schema; | |||||||||||||
| 36 | |||||||||||||||
| 37 | 0 | my $run = $schema->resultset('Run')->find($query, $attrs); | |||||||||||||
| 38 | 0 | return $run; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | ▶ | sub durations { | ||||||||||||
|
Subroutine
durations: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||
| 43 | 0 | my %params = @_; | |||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | my $median = $params{median} || 0; | ||||||||||||
|
Condition0%0/2
$params{'median'} || 0
MC/DC0%0/1
$params{'median'} || 0
$params{'median'}
Truth table0%0/2
A
A= $params{'median'}
| |||||||||||||||
| 46 | 0 | ▶ | my $short = $params{short} || 15; | ||||||||||||
|
Condition0%0/2
$params{'short'} || 15
MC/DC0%0/1
$params{'short'} || 15
$params{'short'}
Truth table0%0/2
A
A= $params{'short'}
| |||||||||||||||
| 47 | 0 | ▶ | my $medium = $params{medium} || 30; | ||||||||||||
|
Condition0%0/2
$params{'medium'} || 30
MC/DC0%0/1
$params{'medium'} || 30
$params{'medium'}
Truth table0%0/2
A
A= $params{'medium'}
| |||||||||||||||
| 48 | 0 | my $username = $params{user}; | |||||||||||||
| 49 | 0 | my $limit = $params{limit}; | |||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | my $schema = $self->result_source->schema; | |||||||||||||
| 52 | 0 | my $dbh = $schema->storage->dbh; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | my $query = <<" EOT"; | |||||||||||||
| 55 | SELECT test_files.filename, jobs.duration | ||||||||||||||
| 56 | FROM jobs | ||||||||||||||
| 57 | JOIN runs USING(run_id) | ||||||||||||||
| 58 | JOIN test_files USING(test_file_id) | ||||||||||||||
| 59 | JOIN users USING(user_id) | ||||||||||||||
| 60 | WHERE runs.project_id = ? | ||||||||||||||
| 61 | AND jobs.duration IS NOT NULL | ||||||||||||||
| 62 | AND test_files.filename IS NOT NULL | ||||||||||||||
| 63 | EOT | ||||||||||||||
| 64 | 0 | my @vals = (uuid_deflate($self->project_id)); | |||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | my ($user_append, @user_args) = $username ? ("users.username = ?", $username) : (); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | if ($username) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | 0 | $query .= "AND $user_append\n"; | |||||||||||||
| 70 | 0 | push @vals => @user_args; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | if ($limit) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | ▶ | my $where = $username ? "WHERE $user_append" : ""; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 0 | my $sth = $dbh->prepare(<<" EOT"); | |||||||||||||
| 76 | SELECT run_id | ||||||||||||||
| 77 | FROM runs | ||||||||||||||
| 78 | JOIN users USING(user_id) | ||||||||||||||
| 79 | $where | ||||||||||||||
| 80 | ORDER BY run_ord DESC | ||||||||||||||
| 81 | LIMIT ? | ||||||||||||||
| 82 | EOT | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 0 | ▶ | $sth->execute(@user_args, $limit) or die $sth->errstr; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | my @ids = map { $_->[0] } @{$sth->fetchall_arrayref}; | |||||||||||||
| 87 | |||||||||||||||
| 88 | 0 | ▶ | if (@ids) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 0 | $query .= "AND run_id IN (" . join(',', ('?') x scalar @ids) . ")\n"; | |||||||||||||
| 90 | 0 | push @vals => (@ids); | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | my $sth = $dbh->prepare($query); | |||||||||||||
| 95 | 0 | ▶ | $sth->execute(@vals) or die $sth->errstr; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 96 | 0 | my $rows = $sth->fetchall_arrayref; | |||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | my $data = {}; | |||||||||||||
| 99 | 0 | for my $row (@$rows) { | |||||||||||||
| 100 | 0 | my ($file, $time) = @$row; | |||||||||||||
| 101 | 0 | push @{$data->{$file}} => $time; | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 0 | for my $file (keys %$data) { | |||||||||||||
| 105 | 0 | ▶ | my $set = delete $data->{$file} or next; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | 0 | my $time = median($set); | |||||||||||||
| 107 | 0 | $data->{$file} = $time; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | ▶ | if ($median) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | 0 | my $sorted = [sort { $data->{$b} <=> $data->{$a} } keys %$data]; | |||||||||||||
| 112 | 0 | $data = {lookup => $data, sorted => $sorted}; | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | else { | ||||||||||||||
| 115 | 0 | for my $file (keys %$data) { | |||||||||||||
| 116 | 0 | my $time = $data->{$file}; | |||||||||||||
| 117 | 0 | my $summary; | |||||||||||||
| 118 | 0 | ▶ | if ($time < $short) { $summary = 'SHORT' } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 119 | 0 | elsif ($time < $medium) { $summary = 'MEDIUM' } | |||||||||||||
| 120 | 0 | else { $summary = 'LONG' } | |||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | $data->{$file} = $summary; | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 0 | return $data; | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | 2 | 1; | |||||||||||||