blib/lib/Langertha/Holmgang/Evaluation.pm

filter: Statementstmt 99.4% 337 / 339 Branchbran 91.2% 73 / 80 Conditioncond 73.1% 68 / 93 MC/DCmcdc 47.0% 24 / 51 Subroutinesub 100% 48 / 48 Podpod 42.8% 6 / 14 totaltotal 88.9% 556 / 625 CC 106 SCAR 22.5
CC
106
Cov
93%
_build_verdicts
25.1
_curves
13.7
_build__runs
11.3
CRAP 9.5
« blib/lib/Langertha/Holmgang/Sim/Schichtfehler.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Kueche.pm »
1 package Langertha::Holmgang::Evaluation;
2 # ABSTRACT: Per-topic evaluation of Holmgang reports: weights, length tiers, verdicts, comparison
3  
4 20 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use Langertha::Holmgang::Report ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 20 our $VERSION = '0.001';
12  
13 #### Constants
14  
15 # The format version of the evaluation document (ADR 0008).
16 8 ▶sub format_version { 1 }
Subroutine format_version: called CC=1 SCAR=0.0
Pod undocumented
17  
18 # The seven status wire names of ADR 0006, in its order.
19 342 ▶sub statuses { qw( no_vision context_exceeded error turn_limit passed uncertain failed ) }
Subroutine statuses: called CC=1 SCAR=0.0
Pod undocumented
20  
21 # The length tiers of CONTEXT.md, in curve order.
22 55 ▶sub tiers { qw( 16k 48k 96k 160k ) }
Subroutine tiers: called CC=1 SCAR=0.0
Pod undocumented
23  
24 # The difficulties of format 2, in curve order.
25 54 ▶sub difficulties { qw( leicht mittel schwer ) }
Subroutine difficulties: called CC=1 SCAR=0.0
Pod undocumented
26  
27 # The topic of a suite that names none (ADR 0005).
28 1 ▶sub default_topic { 'sonstiges' }
Subroutine default_topic: called CC=1 SCAR=0.0
Pod undocumented
29  
30 # The tags that make a hard case when the report's `hard` is null (ADR 0005).
31 101 ▶sub hard_tags { qw( injection verbot ) }
Subroutine hard_tags: called CC=1 SCAR=0.0
Pod undocumented
32  
33 212 ▶sub report_class { 'Langertha::Holmgang::Report' }
Subroutine report_class: called CC=1 SCAR=0.0
Pod undocumented
34  
35 #### Attributes
36  
37 105 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
38 105 my ( $orig, $class, @args ) = @_;
39 0 ▶ my %arg = @args == 1 && ref $args[0] eq 'HASH' ? %{ $args[0] } : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 && ref $args[0] eq 'HASH' ? : 0 105 105
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
10500
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
40 105 ▶ $arg{reports} = [ delete $arg{report} ] if exists $arg{report};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg{"report"} 91 14 105
41 105 return $class->$orig(%arg);
42 20 };
43  
44 20 has reports => ( is => 'ro', required => 1 );
45  
46  
47 22 ▶has thresholds => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
48  
49  
50 105 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=21.0
Pod undocumented
51 105 my ( $self ) = @_;
52 105 my $reports = $self->reports;
53 105 ▶ croak __PACKAGE__.'->new needs reports (an array of '.$self->report_class.')'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reports eq "ARRAY" and @$reports 1 104 105
Condition66%2/3
ref $reports eq "ARRAY" and @$reports
!ll&&!rl&&r
01104
MC/DC50%1/2
ref $reports eq "ARRAY" and @$reports
ref $reports eq "ARRAY" @$reports
Truth table66%2/3
A and B
A= ref $reports eq "ARRAY"B= @$reports
ABresult
0X0
100
111
54 unless ref $reports eq 'ARRAY' && @$reports;
55 104 for my $r ( @$reports ) {
56 109 ▶ croak __PACKAGE__.'->new: '.( defined $r ? $r : 'undef' ).' is not a '.$self->report_class
Branch: 2 branches
BranchTrueFalseTotal
unless builtin::blessed($r) and $r->isa($self->report_class) 1 108 109
defined $r ? : 1 0 1
Condition66%2/3
builtin::blessed($r) and $r->isa($self->report_class)
!ll&&!rl&&r
10108
MC/DC50%1/2
builtin::blessed($r) and $r->isa($self->report_class)
builtin::blessed($r) $r->isa($self->report_class)
Truth table66%2/3
A and B
A= builtin::blessed($r)B= $r->isa($self->report_class)
ABresult
0X0
100
111
57 unless blessed $r && $r->isa( $self->report_class );
58 }
59 103 ▶ croak __PACKAGE__.'->new: thresholds must be a hash of suite id to threshold'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->thresholds eq "HASH" 1 102 103
60 unless ref $self->thresholds eq 'HASH';
61 102 return;
62 }
63  
64 20 has _runs => ( is => 'ro', lazy_build => 1 );
65  
66 # The merged runs, flattened into what every view needs.
67 102 ▶sub _build__runs {
Subroutine _build__runs: called CC=11 SCAR=24.2
68 102 my ( $self ) = @_;
69 102 my $merged = $self->report_class->merge( @{ $self->reports } );
70 101 my $json = JSON::MaybeXS->new( canonical => 1 );
71 101 my %hard_tag = map { $_ => 1 } $self->hard_tags;
72 101 my @runs;
73 101 for my $run ( @{ $merged->runs } ) {
74 137 ▶ my $target = $run->{target} || {};
Condition50%1/2
$run->{'target'} || {}
l!l
1370
MC/DC0%0/1
$run->{'target'} || {}
$run->{'target'}
Truth table50%1/2
A
A= $run->{'target'}
Aresult
11
00
75 137 ▶ my $variant = $run->{variant} || {};
Condition50%1/2
$run->{'variant'} || {}
l!l
1370
MC/DC0%0/1
$run->{'variant'} || {}
$run->{'variant'}
Truth table50%1/2
A
A= $run->{'variant'}
Aresult
11
00
76 push @runs, {
77 row => $json->encode( { target => $target, variant => $variant } ),
78 target => $self->_target_label($target),
79 variant => $variant->{name},
80 suite => $run->{suite}{id},
81 topic => defined $run->{suite}{topic} && length $run->{suite}{topic} ? $run->{suite}{topic} : $self->default_topic,
82 k => $run->{repeat},
83 status => $run->{status},
84 error => $run->{error},
85 cases => [ map {
86 235 my $c = $_;
87 {
88 case_id => $c->{case_id},
89 weight => defined $c->{weight} ? $c->{weight} : 1,
90 tier => $c->{tier},
91 difficulty => $c->{difficulty},
92 hard => defined $c->{hard} ? ( $c->{hard} ? 1 : 0 )
93 2 ▶ : ( grep { $hard_tag{$_} } @{ $c->{tags} || [] } ) ? 1 : 0,
Condition50%1/2
$c->{'tags'} || []
l!l
1460
MC/DC0%0/1
$c->{'tags'} || []
$c->{'tags'}
Truth table50%1/2
A
A= $c->{'tags'}
Aresult
11
00
94 repetitions => $c->{repetitions},
95 }
96 137 ▶ } @{ $run->{cases} } ],
Branch: 5 branches
BranchTrueFalseTotal
defined $run->{'suite'}{'topic'} && length $run->{'suite'}{'topic'} ? : 136 1 137
defined $c->{'weight'} ? : 235 0 235
defined $c->{'hard'} ? : 89 146 235
$c->{'hard'} ? : 6 83 89
grep({$hard_tag{$_};} @{$c->{'tags'} or [];}) ? : 2 144 146
Condition66%2/3
defined $run->{"suite"}{"topic"} and length $run->{"suite"}{"topic"}
!ll&&!rl&&r
10136
MC/DC50%1/2
defined $run->{"suite"}{"topic"} and length $run->{"suite"}{"topic"}
defined $run->{"suite"}{"topic"} length $run->{"suite"}{"topic"}
Truth table66%2/3
A and B
A= defined $run->{"suite"}{"topic"}B= length $run->{"suite"}{"topic"}
ABresult
0X0
100
111
97 };
98 }
99 101 return \@runs;
100 }
101  
102 137 ▶sub _target_label {
Subroutine _target_label: called CC=4 SCAR=16.9
103 137 my ( $self, $t ) = @_;
104 137 for my $k (qw( label model engine )) {
105 137 ▶ return $t->{$k} if defined $t->{$k} && length $t->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{$k} and length $t->{$k} 137 0 137
Condition33%1/3
defined $t->{$k} and length $t->{$k}
!ll&&!rl&&r
00137
MC/DC0%0/2
defined $t->{$k} and length $t->{$k}
defined $t->{$k} length $t->{$k}
Truth table33%1/3
A and B
A= defined $t->{$k}B= length $t->{$k}
ABresult
0X0
100
111
106 }
107 0 return '?';
108 }
109  
110 #### Tallies
111  
112 212 ▶sub _tally {
Subroutine _tally: called CC=1 SCAR=0.0
113 212 my ( $self ) = @_;
114 212 return { results => 0, _weight => 0, _w => {}, counts => { map { $_ => 0 } $self->statuses } };
115 }
116  
117 488 ▶sub _add {
Subroutine _add: called CC=1 SCAR=0.0
118 488 my ( $self, $t, $rep, $weight ) = @_;
119 488 $t->{results}++;
120 488 $t->{_weight} += $weight;
121 488 $t->{counts}{ $rep->{status} }++;
122 488 $t->{_w}{ $rep->{status} } += $weight;
123 488 return;
124 }
125  
126 745 ▶sub _round { my ( $self, $n ) = @_; return defined $n ? 0 + sprintf( '%.4f', $n ) : undef }
Subroutine _round: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 745 0 745
127  
128 # Weighted share of one status among all results of a tally.
129 256 ▶sub _share {
Subroutine _share: called CC=3 SCAR=11.0
130 256 my ( $self, $t, $status ) = @_;
131 256 ▶ return undef unless $t->{_weight} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $t->{"_weight"} > 0 10 246 256
132 246 ▶ return $self->_round( ( $t->{_w}{$status} // 0 ) / $t->{_weight} );
Condition100%2/2
$t->{"_w"}{$status} // 0
l!l
14799
MC/DC100%1/1
$t->{"_w"}{$status} // 0
$t->{"_w"}{$status}
Truth table100%2/2
A
A= $t->{"_w"}{$status}
Aresult
11
00
133 }
134  
135 # The public part of a tally.
136 212 ▶sub _counted {
Subroutine _counted: called CC=1 SCAR=0.0
137 212 my ( $self, $t ) = @_;
138 return (
139 results => $t->{results},
140 weight => $self->_round( $t->{_weight} ),
141 212 counts => { %{ $t->{counts} } },
142 rate => $self->_share( $t, 'passed' ),
143 );
144 }
145  
146 #### Topics
147  
148 20 has _topics => ( is => 'ro', lazy_build => 1 );
149  
150 16 ▶sub topics { my ( $self ) = @_; return $self->_public( $self->_topics ) }
Subroutine topics: called CC=1 SCAR=0.0
Pod documented
151  
152 57 ▶sub _build__topics {
Subroutine _build__topics: called CC=11 SCAR=24.0
153 57 my ( $self ) = @_;
154 57 my ( %agg, @rows );
155 57 for my $run ( @{ $self->_runs } ) {
156 89 ▶ my $a = $agg{ $run->{row} }{ $run->{topic} } //= do {
Condition66%2/3
$agg{$run->{"row"}}{$run->{"topic"}} //= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "topic", $run->{"topic"}, "suites", [], "tally", $self->_tally, "tokens", {}} }
l!l&&r!l&&!r
19700
MC/DC0%0/2
$agg{$run->{"row"}}{$run->{"topic"}} //= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "topic", $run->{"topic"}, "suites", [], "tally", $self->_tally, "tokens", {}} }
$agg{$run->{"row"}}{$run->{"topic"}} do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "topic", $run->{"topic"}, "suites", [], "tally", $self->_tally, "tokens", {}} }
Truth table66%2/3
A //= B
A= $agg{$run->{"row"}}{$run->{"topic"}}B= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "topic", $run->{"topic"}, "suites", [], "tally", $self->_tally, "tokens", {}} }
ABresult
1X1
011
000
157 70 push @rows, $run->{row};
158 { target => $run->{target}, variant => $run->{variant}, topic => $run->{topic},
159 70 suites => [], tally => $self->_tally, tokens => {} };
160 };
161 89 ▶ push @{ $a->{suites} }, $run->{suite} unless grep { $_ eq $run->{suite} } @{ $a->{suites} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $run->{"suite"};} @{$$a{"suites"};} 89 0 89
162 89 for my $c ( @{ $run->{cases} } ) {
163 134 for my $rep ( @{ $c->{repetitions} } ) {
164 157 $self->_add( $a->{tally}, $rep, $c->{weight} );
165 157 for my $f (qw( input output reasoning )) {
166 471 ▶ my $n = $rep->{tokens} && $rep->{tokens}{$f};
Condition66%2/3
$rep->{'tokens'} && $rep->{'tokens'}{$f}
!ll&&!rl&&r
04656
MC/DC50%1/2
$rep->{'tokens'} && $rep->{'tokens'}{$f}
$rep->{'tokens'} $rep->{'tokens'}{$f}
Truth table66%2/3
A && B
A= $rep->{'tokens'}B= $rep->{'tokens'}{$f}
ABresult
0X0
100
111
167 471 ▶ $a->{tokens}{$f} += $n if defined $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 6 465 471
168 }
169 }
170 }
171 }
172 57 my %seen;
173 57 @rows = grep { !$seen{$_}++ } @rows;
174 57 my @out;
175 57 for my $row ( @rows ) {
176 64 for my $topic ( sort keys %{ $agg{$row} } ) {
177 70 my $a = $agg{$row}{$topic};
178 push @out, {
179 target => $a->{target},
180 variant => $a->{variant},
181 topic => $topic,
182 70 suites => [ sort @{ $a->{suites} } ],
183 $self->_counted( $a->{tally} ),
184 70 tokens => { map { $_ => $a->{tokens}{$_} } qw( input output reasoning ) },
185 _row => $row,
186 };
187 }
188 }
189 57 return \@out;
190 }
191  
192  
193 20 has _overall => ( is => 'ro', lazy_build => 1 );
194  
195 14 ▶sub overall { my ( $self ) = @_; return $self->_public( $self->_overall ) }
Subroutine overall: called CC=1 SCAR=0.0
Pod documented
196  
197 55 ▶sub _build__overall {
Subroutine _build__overall: called CC=7 SCAR=19.5
198 55 my ( $self ) = @_;
199 55 my ( %o, @rows );
200 55 for my $t ( @{ $self->_topics } ) {
201 68 ▶ my $o = $o{ $t->{_row} } //= do {
Condition66%2/3
$o{$t->{"_row"}} //= do { push @rows, $t->{"_row"}; +{"target", $t->{"target"}, "variant", $t->{"variant"}, "topics", 0, "results", 0, "counts", {map({$_, 0;} $self->statuses)}, "_rates", []} }
l!l&&r!l&&!r
6620
MC/DC0%0/2
$o{$t->{"_row"}} //= do { push @rows, $t->{"_row"}; +{"target", $t->{"target"}, "variant", $t->{"variant"}, "topics", 0, "results", 0, "counts", {map({$_, 0;} $self->statuses)}, "_rates", []} }
$o{$t->{"_row"}} do { push @rows, $t->{"_row"}; +{"target", $t->{"target"}, "variant", $t->{"variant"}, "topics", 0, "results", 0, "counts", {map({$_, 0;} $self->statuses)}, "_rates", []} }
Truth table66%2/3
A //= B
A= $o{$t->{"_row"}}B= do { push @rows, $t->{"_row"}; +{"target", $t->{"target"}, "variant", $t->{"variant"}, "topics", 0, "results", 0, "counts", {map({$_, 0;} $self->statuses)}, "_rates", []} }
ABresult
1X1
011
000
202 62 push @rows, $t->{_row};
203 { target => $t->{target}, variant => $t->{variant}, topics => 0, results => 0,
204 62 counts => { map { $_ => 0 } $self->statuses }, _rates => [] };
205 };
206 68 $o->{topics}++;
207 68 $o->{results} += $t->{results};
208 68 $o->{counts}{$_} += $t->{counts}{$_} for $self->statuses;
209 68 ▶ push @{ $o->{_rates} }, $t->{rate} if defined $t->{rate};
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{"rate"} 64 4 68
210 }
211 return [ map {
212 55 my $o = $o{$_};
213 62 my $rates = delete $o->{_rates};
214 62 my $sum = 0;
215 62 $sum += $_ for @$rates;
216 62 ▶ $o->{rate} = @$rates ? $self->_round( $sum / @$rates ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$rates ? : 59 3 62
217 62 $o->{_row} = $_;
218 62 $o;
219 } @rows ];
220 }
221  
222  
223 #### Length tiers
224  
225 20 has tier_curves => ( is => 'ro', lazy_build => 1, init_arg => undef );
226  
227 # Known values first in their order, any other after them by its number,
228 # then by text.
229 36 ▶sub _order {
Subroutine _order: called CC=3 SCAR=11.0
230 36 my ( $self, $known, $v ) = @_;
231 36 my ($i) = grep { $known->[$_] eq $v } 0 .. $#$known;
232 36 ▶ return defined $i ? ( 0, $i, 0, '' ) : ( 1, 0, ( $v =~ /\A([0-9]+)/ ? $1 : 0 ), $v );
Branch: 2 branches
BranchTrueFalseTotal
defined $i ? : 30 6 36
$v =~ /\A([0-9]+)/ ? : 3 3 6
233 }
234  
235 # One curve per row and topic over the values of a case field.
236 109 ▶sub _curves {
Subroutine _curves: called CC=13 SCAR=26.2
237 109 my ( $self, $field, @known ) = @_;
238 109 my ( %agg, @rows );
239 109 for my $run ( @{ $self->_runs } ) {
240 160 for my $c ( @{ $run->{cases} } ) {
241 230 ▶ next unless defined $c->{$field} && length $c->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c->{$field} and length $c->{$field} 190 40 230
Condition66%2/3
defined $c->{$field} and length $c->{$field}
!ll&&!rl&&r
190040
MC/DC50%1/2
defined $c->{$field} and length $c->{$field}
defined $c->{$field} length $c->{$field}
Truth table66%2/3
A and B
A= defined $c->{$field}B= length $c->{$field}
ABresult
0X0
100
111
242 40 ▶ my $a = $agg{ $run->{row} }{ $run->{topic} }{ $c->{$field} } //= do {
Condition66%2/3
$agg{$run->{"row"}}{$run->{"topic"}}{$c->{$field}} //= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "tally", $self->_tally} }
l!l&&r!l&&!r
18220
MC/DC0%0/2
$agg{$run->{"row"}}{$run->{"topic"}}{$c->{$field}} //= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "tally", $self->_tally} }
$agg{$run->{"row"}}{$run->{"topic"}}{$c->{$field}} do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "tally", $self->_tally} }
Truth table66%2/3
A //= B
A= $agg{$run->{"row"}}{$run->{"topic"}}{$c->{$field}}B= do { push @rows, $run->{"row"}; +{"target", $run->{"target"}, "variant", $run->{"variant"}, "tally", $self->_tally} }
ABresult
1X1
011
000
243 22 push @rows, $run->{row};
244 22 { target => $run->{target}, variant => $run->{variant}, tally => $self->_tally };
245 };
246 40 $self->_add( $a->{tally}, $_, $c->{weight} ) for @{ $c->{repetitions} };
247 }
248 }
249 109 my %seen;
250 my @out;
251 109 for my $row ( grep { !$seen{$_}++ } @rows ) {
252 9 for my $topic ( sort keys %{ $agg{$row} } ) {
253 9 my $by = $agg{$row}{$topic};
254 my @values = sort {
255 9 my @x = $self->_order( \@known, $a );
256 18 my @y = $self->_order( \@known, $b );
257 18 ▶ $x[0] <=> $y[0] || $x[1] <=> $y[1] || $x[2] <=> $y[2] || $x[3] cmp $y[3]
Condition44%4/9
$x[0] <=> $y[0] || $x[1] <=> $y[1] || $x[2] <=> $y[2] || $x[3] cmp $y[3]
l!l&&r!l&&!r
1800
$x[0] <=> $y[0] or $x[1] <=> $y[1] or $x[2] <=> $y[2]
l!l&&r!l&&!r
1800
$x[0] <=> $y[0] or $x[1] <=> $y[1]
l!l&&r!l&&!r
6120
MC/DC0%0/4
$x[0] <=> $y[0] || $x[1] <=> $y[1] || $x[2] <=> $y[2] || $x[3] cmp $y[3]
$x[0] <=> $y[0] $x[1] <=> $y[1] $x[2] <=> $y[2] $x[3] cmp $y[3]
Truth table40%2/5
A or B or C || D
A= $x[0] <=> $y[0]B= $x[1] <=> $y[1]C= $x[2] <=> $y[2]D= $x[3] cmp $y[3]
ABCDresult
1XXX1
01XX1
001X1
00011
00000
258 } keys %$by;
259 9 for my $v ( @values ) {
260 22 my $a = $by->{$v};
261 push @out, {
262 target => $a->{target},
263 variant => $a->{variant},
264 topic => $topic,
265 $field => $v,
266 $self->_counted( $a->{tally} ),
267 context_exceeded_rate => $self->_share( $a->{tally}, 'context_exceeded' ),
268 22 error_rate => $self->_share( $a->{tally}, 'error' ),
269 };
270 }
271 }
272 }
273 109 return \@out;
274 }
275  
276 55 ▶sub _build_tier_curves { my ( $self ) = @_; return $self->_curves( tier => $self->tiers ) }
Subroutine _build_tier_curves: called CC=1 SCAR=0.0
277  
278  
279 #### Difficulties
280  
281 20 has difficulty_curves => ( is => 'ro', lazy_build => 1, init_arg => undef );
282  
283 54 ▶sub _build_difficulty_curves { my ( $self ) = @_; return $self->_curves( difficulty => $self->difficulties ) }
Subroutine _build_difficulty_curves: called CC=1 SCAR=0.0
284  
285  
286 #### Verdicts
287  
288 20 has verdicts => ( is => 'ro', lazy_build => 1, init_arg => undef );
289  
290 93 ▶sub _build_verdicts {
Subroutine _build_verdicts: called CC=25 SCAR=32.2
291 93 my ( $self ) = @_;
292 93 my ( %v, @order );
293 93 for my $run ( @{ $self->_runs } ) {
294 120 my $key = $run->{row}."\0".$run->{suite};
295 croak __PACKAGE__.': suite '.$run->{suite}.' appears twice for target '.$run->{target}.' after merging'
296 120 ▶ if $v{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $v{$key} 0 120 120
297 120 push @order, $key;
298 my $v = $v{$key} = { target => $run->{target}, variant => $run->{variant}, suite_id => $run->{suite},
299 k => $run->{k}, tally => $self->_tally, cases => [], hard => {}, measured => {},
300 unfinished => defined $run->{status} && $run->{status} ne 'complete'
301 120 ▶ ? { status => $run->{status}, error => $run->{error} } : undef };
Branch: 1 branch
BranchTrueFalseTotal
defined $run->{'status'} && $run->{'status'} ne 'complete' ? : 8 112 120
Condition66%2/3
defined $run->{"status"} and $run->{"status"} ne "complete"
!ll&&!rl&&r
01128
MC/DC50%1/2
defined $run->{"status"} and $run->{"status"} ne "complete"
defined $run->{"status"} $run->{"status"} ne "complete"
Truth table66%2/3
A and B
A= defined $run->{"status"}B= $run->{"status"} ne "complete"
ABresult
0X0
100
111
302 120 for my $c ( @{ $run->{cases} } ) {
303 # a repetition with any result but error reached the target (cai-platform runs_error)
304 176 $v->{measured}{ $_->{repetition} } = 1 for grep { $_->{status} ne 'error' } @{ $c->{repetitions} };
305 176 my @reps = @{ $c->{repetitions} };
306 176 ▶ next unless @reps;
Branch: 1 branch
BranchTrueFalseTotal
unless @reps 7 169 176
307 169 my $passed = grep { $_->{status} eq 'passed' } @reps;
308 169 push @{ $v->{cases} }, { case_id => $c->{case_id}, passed => $passed, repetitions => scalar @reps, _w => $c->{weight} };
309 169 for my $rep ( @reps ) {
310 274 $self->_add( $v->{tally}, $rep, $c->{weight} );
311 274 ▶ my $n = $rep->{forbidden_calls} // 0;
Condition50%1/2
$rep->{"forbidden_calls"} // 0
l!l
2740
MC/DC0%0/1
$rep->{"forbidden_calls"} // 0
$rep->{"forbidden_calls"}
Truth table50%1/2
A
A= $rep->{"forbidden_calls"}
Aresult
11
00
312 274 ▶ next unless $n && $c->{hard};
Branch: 1 branch
BranchTrueFalseTotal
unless $n and $c->{"hard"} 269 5 274
Condition100%3/3
$n and $c->{"hard"}
!ll&&!rl&&r
26635
MC/DC100%2/2
$n and $c->{"hard"}
$n $c->{"hard"}
Truth table100%3/3
A and B
A= $nB= $c->{"hard"}
ABresult
0X0
100
111
313 5 ▶ my $h = $v->{hard}{ $c->{case_id} } //= { case_id => $c->{case_id}, forbidden_calls => 0, repetitions => 0 };
Condition50%1/2
$v->{"hard"}{$c->{"case_id"}} //= {"case_id", $c->{"case_id"}, "forbidden_calls", 0, "repetitions", 0}
l!l
05
MC/DC0%0/1
$v->{"hard"}{$c->{"case_id"}} //= {"case_id", $c->{"case_id"}, "forbidden_calls", 0, "repetitions", 0}
$v->{"hard"}{$c->{"case_id"}}
Truth table50%1/2
A
A= $v->{"hard"}{$c->{"case_id"}}
Aresult
11
00
314 5 $h->{forbidden_calls} += $n;
315 5 $h->{repetitions}++;
316 }
317 }
318 }
319 92 my @out;
320 92 for my $key ( @order ) {
321 120 my $v = $v{$key};
322 120 ▶ my $th = $self->thresholds->{ $v->{suite_id} } || {};
Condition100%2/2
$self->thresholds->{$v->{'suite_id'}} || {}
l!l
3387
MC/DC100%1/1
$self->thresholds->{$v->{'suite_id'}} || {}
$self->thresholds->{$v->{'suite_id'}}
Truth table100%2/2
A
A= $self->thresholds->{$v->{'suite_id'}}
Aresult
11
00
323 120 my $k = $v->{k};
324 120 my %c = $self->_counted( $v->{tally} );
325 120 my $wc = 0;
326 120 $wc += $_->{_w} for @{ $v->{cases} };
327 240 ▶ my $share = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
328 240 my ( $pick ) = @_;
329 240 ▶ return undef unless @{ $v->{cases} } && $wc > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$v->{"cases"};} and $wc > 0 12 228 240
Condition66%2/3
@{$v->{"cases"};} and $wc > 0
!ll&&!rl&&r
120228
MC/DC50%1/2
@{$v->{"cases"};} and $wc > 0
@{$v->{"cases"};} $wc > 0
Truth table66%2/3
A and B
A= @{$v->{"cases"};}B= $wc > 0
ABresult
0X0
100
111
330 228 my $w = 0;
331 228 $w += $_->{_w} for grep { $pick->($_) } @{ $v->{cases} };
332 228 return $self->_round( $w / $wc );
333 120 };
334 my $out = {
335 target => $v->{target},
336 variant => $v->{variant},
337 suite_id => $v->{suite_id},
338 results => $c{results},
339 counts => $c{counts},
340 passed => $c{counts}{passed},
341 rate => $c{rate},
342 pass_rate => $th->{pass_rate},
343 k => $k,
344 169 ▶ pass_k => $share->( sub { $_[0]{passed} >= $k } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
345 169 ▶ pass_any => $share->( sub { $_[0]{passed} > 0 } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
346 pass_k_min => $th->{pass_k},
347 169 case_results => [ map { { case_id => $_->{case_id}, passed => $_->{passed}, repetitions => $_->{repetitions} } } @{ $v->{cases} } ],
348 5 hard_failed => [ map { $v->{hard}{$_} } sort keys %{ $v->{hard} } ],
349 176 repetitions_error => scalar( grep { !$v->{measured}{$_} } 1 .. $k ),
350 unfinished => $v->{unfinished},
351 120 };
352 my $below = ( defined $out->{pass_rate} && ( !defined $out->{rate} || $out->{rate} < $out->{pass_rate} ) )
353 120 ▶ || ( defined $out->{pass_k_min} && ( !defined $out->{pass_k} || $out->{pass_k} < $out->{pass_k_min} ) );
Condition100%15/15
defined $out->{'pass_rate'} && (!defined($out->{'rate'}) || $out->{'rate'} < $out->{'pass_rate'}) || defined $out->{'pass_k_min'} && (!defined($out->{'pass_k'}) || $out->{'pass_k'} < $out->{'pass_k_min'})
l!l&&r!l&&!r
142104
defined $out->{"pass_rate"} and !defined($out->{"rate"}) || $out->{"rate"} < $out->{"pass_rate"}
!ll&&!rl&&r
901614
not defined $out->{"rate"} or $out->{"rate"} < $out->{"pass_rate"}
l!l&&r!l&&!r
11316
defined $out->{"pass_k_min"} and !defined($out->{"pass_k"}) || $out->{"pass_k"} < $out->{"pass_k_min"}
!ll&&!rl&&r
9862
not defined $out->{"pass_k"} or $out->{"pass_k"} < $out->{"pass_k_min"}
l!l&&r!l&&!r
116
MC/DC100%6/6
defined $out->{'pass_rate'} && (!defined($out->{'rate'}) || $out->{'rate'} < $out->{'pass_rate'}) || defined $out->{'pass_k_min'} && (!defined($out->{'pass_k'}) || $out->{'pass_k'} < $out->{'pass_k_min'})
defined $out->{"pass_rate"} not defined $out->{"rate"} $out->{"rate"} < $out->{"pass_rate"} defined $out->{"pass_k_min"} not defined $out->{"pass_k"} $out->{"pass_k"} < $out->{"pass_k_min"}
Truth table80%8/10
A and not(B) or C || D and not(E) or F
A= defined $out->{"pass_rate"}B= not defined $out->{"rate"}C= $out->{"rate"} < $out->{"pass_rate"}D= defined $out->{"pass_k_min"}E= not defined $out->{"pass_k"}F= $out->{"pass_k"} < $out->{"pass_k_min"}
ABCDEFresult
11XXXX1
101XXX1
0XX11X1
0XX1011
10011X1
1001011
0XX0XX0
0XX1000
1000XX0
1001000
354 # a suite without any measured repetition is not ok; unmeasured repetitions
355 # next to a measured one are only reported -- ADR 0009 k42 (ADR 0008 k73 amendment)
356 120 ▶ $out->{ok} = $below || @{ $out->{hard_failed} } || $out->{unfinished} || $self->_unmeasured($out)
Branch: 1 branch
BranchTrueFalseTotal
$below || @{$out->{'hard_failed'};} || $out->{'unfinished'} || $self->_unmeasured($out) ? : 45 75 120
Condition100%9/9
$below or @{$out->{"hard_failed"};} or $out->{"unfinished"} or $self->_unmeasured($out)
l!l&&r!l&&!r
291675
$below or @{$out->{"hard_failed"};} or $out->{"unfinished"}
l!l&&r!l&&!r
21891
$below or @{$out->{"hard_failed"};}
l!l&&r!l&&!r
16599
MC/DC100%4/4
$below or @{$out->{"hard_failed"};} or $out->{"unfinished"} or $self->_unmeasured($out)
$below @{$out->{"hard_failed"};} $out->{"unfinished"} $self->_unmeasured($out)
Truth table100%5/5
A or B or C or D
A= $belowB= @{$out->{"hard_failed"};}C= $out->{"unfinished"}D= $self->_unmeasured($out)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
357 ? JSON::MaybeXS::false() : JSON::MaybeXS::true();
358 120 push @out, $out;
359 }
360 92 return \@out;
361 }
362  
363 # a verdict whose suite measured nothing: no repetition reached the target (k73)
364 132 ▶sub _unmeasured { my ( $self, $v ) = @_; return $v->{repetitions_error} == $v->{k} }
Subroutine _unmeasured: called CC=1 SCAR=0.0
365  
366  
367 #### Comparison
368  
369 20 has comparison => ( is => 'ro', lazy_build => 1, init_arg => undef );
370  
371 52 ▶sub _build_comparison {
Subroutine _build_comparison: called CC=1 SCAR=0.0
372 52 my ( $self ) = @_;
373 52 my %topics = map { $_->{topic} => 1 } @{ $self->_topics };
374 my @rows = map {
375 58 my $o = $_;
376 {
377 target => $o->{target},
378 variant => $o->{variant},
379 60 rates => { map { $_->{topic} => $_->{rate} } grep { $_->{_row} eq $o->{_row} } @{ $self->_topics } },
380 overall => $o->{rate},
381 }
382 52 } @{ $self->_overall };
383 52 return { topics => [ sort keys %topics ], rows => \@rows };
384 }
385  
386  
387 #### Output
388  
389 30 ▶sub _public {
Subroutine _public: called CC=1 SCAR=0.0
390 30 my ( $self, $rows ) = @_;
391 30 return [ map { my %r = %$_; delete $r{_row}; \%r } @$rows ];
392 }
393  
394 8 ▶sub as_data {
Subroutine as_data: called CC=1 SCAR=0.0
Pod documented
395 8 my ( $self ) = @_;
396 return {
397 8 holmgang_evaluation => $self->format_version,
398 topics => $self->topics,
399 overall => $self->overall,
400 tier_curves => $self->tier_curves,
401 difficulty_curves => $self->difficulty_curves,
402 verdicts => $self->verdicts,
403 comparison => $self->comparison,
404 };
405 }
406  
407  
408 5 ▶sub to_json {
Subroutine to_json: called CC=1 SCAR=0.0
Pod documented
409 5 my ( $self ) = @_;
410 5 return JSON::MaybeXS->new( utf8 => 1, canonical => 1, pretty => 1 )->encode( $self->as_data );
411 }
412  
413  
414 419 ▶sub _pct { my ( $self, $r ) = @_; return defined $r ? sprintf( '%.1f%%', 100 * $r ) : '-' }
Subroutine _pct: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $r ? : 262 157 419
415  
416 152 ▶sub _cell { my ( $self, $v ) = @_; return defined $v && length $v ? $v : '-' }
Subroutine _cell: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
defined $v && length $v ? : 148 4 152
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
40148
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
417  
418 # a run's error for a note: on one line, cut to 200 characters with an ellipsis
419 # (as the CLI's notes, k44)
420 11 ▶sub _line {
Subroutine _line: called CC=2 SCAR=6.9
421 11 my ( $self, $t ) = @_;
422 11 $t = join ' ', split ' ', $t;
423 11 ▶ return $t if length $t <= 200;
Branch: 1 branch
BranchTrueFalseTotal
if length $t <= 200 10 1 11
424 1 return substr( $t, 0, 200 ) =~ s/\s+\z//r." \x{2026}";
425 }
426  
427 # The tables both text renderers draw: [ title, header, rows, notes per row ].
428 55 ▶sub _tables {
Subroutine _tables: called CC=10 SCAR=23.0
429 55 my ( $self ) = @_;
430 55 my $cmp = $self->comparison;
431 my @tables = ( [
432 'Comparison by topic (share passed; overall = mean of the topics)',
433 55 [ 'target', 'variant', @{ $cmp->{topics} }, 'overall' ],
434 [ map {
435 60 my $r = $_;
436 [ $r->{target}, $self->_cell( $r->{variant} ),
437 60 ( map { $self->_pct( $r->{rates}{$_} ) } @{ $cmp->{topics} } ), $self->_pct( $r->{overall} ) ]
438 55 } @{ $cmp->{rows} } ],
439 [],
440 ] );
441 55 my ( @vrows, @notes );
442 55 for my $v ( @{ $self->verdicts } ) {
443 push @vrows, [ $v->{target}, $self->_cell( $v->{variant} ), $v->{suite_id},
444 $v->{passed}.'/'.$v->{results}, $self->_pct( $v->{rate} ), $self->_pct( $v->{pass_rate} ),
445 $v->{k} > 1 ? $self->_pct( $v->{pass_k} ).' (k='.$v->{k}.')' : '-',
446 $self->_pct( $v->{pass_k_min} ),
447 85 ▶ $v->{ok} ? 'ok' : $self->_unmeasured($v) ? 'NOT MEASURED' : 'NOT PASSED' ];
Branch: 3 branches
BranchTrueFalseTotal
$v->{'k'} > 1 ? : 19 66 85
$v->{'ok'} ? : 44 41 85
$self->_unmeasured($v) ? : 20 21 41
448 push @notes, [
449 ( $v->{unfinished}
450 ? 'run '.$v->{unfinished}{status}.( defined $v->{unfinished}{error} ? ': '.$self->_line( $v->{unfinished}{error} ) : '' ) : () ),
451 ( $v->{repetitions_error}
452 ? 'no result but error in '.$v->{repetitions_error}.' of '.$v->{k}.' repetition(s): nothing measured' : () ),
453 map {
454 'hard: '.$_->{case_id}.' - '.$_->{forbidden_calls}.' forbidden call(s) in '.$_->{repetitions}.' of '.$v->{k}
455 85 ▶ } @{ $v->{hard_failed} } ];
Branch: 3 branches
BranchTrueFalseTotal
$v->{'unfinished'} ? : 12 73 85
defined $v->{'unfinished'}{'error'} ? : 11 1 12
$v->{'repetitions_error'} ? : 24 61 85
456 }
457 55 push @tables, [ 'Verdicts per suite',
458 [ 'target', 'variant', 'suite', 'passed', 'rate', 'threshold', 'pass^k', 'pass^k min', 'verdict' ],
459 \@vrows, \@notes ];
460 55 ▶ if ( @{ $self->tier_curves } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->tier_curves;}) 1 54 55
461 push @tables, [ 'Length tiers (shares of all results)',
462 [ 'target', 'variant', 'topic', 'tier', 'results', 'passed', 'context_exceeded', 'error' ],
463 [ map { [ $_->{target}, $self->_cell( $_->{variant} ), $_->{topic}, $_->{tier}, $_->{results},
464 1 $self->_pct( $_->{rate} ), $self->_pct( $_->{context_exceeded_rate} ), $self->_pct( $_->{error_rate} ) ] }
465 1 @{ $self->tier_curves } ],
466 [] ];
467 }
468 55 ▶ if ( @{ $self->difficulty_curves } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->difficulty_curves;}) 4 51 55
469 push @tables, [ 'Difficulty (shares of all results)',
470 [ 'target', 'variant', 'topic', 'difficulty', 'results', 'passed', 'context_exceeded', 'error' ],
471 [ map { [ $_->{target}, $self->_cell( $_->{variant} ), $_->{topic}, $_->{difficulty}, $_->{results},
472 6 $self->_pct( $_->{rate} ), $self->_pct( $_->{context_exceeded_rate} ), $self->_pct( $_->{error_rate} ) ] }
473 4 @{ $self->difficulty_curves } ],
474 [] ];
475 }
476 55 return @tables;
477 }
478  
479 48 ▶sub to_text {
Subroutine to_text: called CC=7 SCAR=19.5
Pod documented
480 48 my ( $self ) = @_;
481 48 my @out;
482 48 for my $t ( $self->_tables ) {
483 100 my ( $title, $head, $rows, $notes ) = @$t;
484 100 my @w = map { length } @$head;
485 100 for my $r ( @$rows ) {
486 130 ▶ $w[$_] = length $r->[$_] > $w[$_] ? length $r->[$_] : $w[$_] for 0 .. $#$r;
Branch: 1 branch
BranchTrueFalseTotal
length $r->[$_] > $w[$_] ? : 207 700 907
487 }
488 100 ▶ my $line = sub { my ( $cells ) = @_; return join( ' ', map { sprintf '%-'.$w[$_].'s', $cells->[$_] } 0 .. $#$cells ) =~ s/\s+\z//r };
Subroutine __ANON__: called CC=1 SCAR=0.0
489 100 push @out, $title, $line->($head);
490 100 for my $i ( 0 .. $#$rows ) {
491 130 push @out, $line->( $rows->[$i] );
492 130 ▶ push @out, map { ' '.$_ } @{ $notes->[$i] || [] };
Condition100%2/2
$notes->[$i] || []
l!l
7357
MC/DC100%1/1
$notes->[$i] || []
$notes->[$i]
Truth table100%2/2
A
A= $notes->[$i]
Aresult
11
00
493 }
494 100 push @out, '';
495 }
496 48 return join "\n", @out;
497 }
498  
499  
500 7 ▶sub to_markdown {
Subroutine to_markdown: called CC=4 SCAR=13.9
Pod documented
501 7 my ( $self ) = @_;
502 7 ▶ my $esc = sub { my ( $v ) = @_; return $v =~ s/([|\\])/\\$1/gr };
Subroutine __ANON__: called CC=1 SCAR=0.0
503 7 my @out;
504 7 for my $t ( $self->_tables ) {
505 15 my ( $title, $head, $rows, $notes ) = @$t;
506 100 push @out, '### '.$title, '', '| '.join( ' | ', map { $esc->($_) } @$head ).' |',
507 15 '|'.join( '|', map { '---' } @$head ).'|';
508 15 push @out, map { '| '.join( ' | ', map { $esc->($_) } @$_ ).' |' } @$rows;
509 # a note names its row, as the list stands apart from the table
510 15 ▶ my @n = map { my $r = $rows->[$_]; map { $r->[0].' / '.$r->[1].' / '.$r->[2].': '.$_ } @{ $notes->[$_] || [] } } 0 .. $#$rows;
Condition100%2/2
$notes->[$_] || []
l!l
1210
MC/DC100%1/1
$notes->[$_] || []
$notes->[$_]
Truth table100%2/2
A
A= $notes->[$_]
Aresult
11
00
511 15 ▶ push @out, '', map { '- '.$esc->($_) } @n if @n;
Branch: 1 branch
BranchTrueFalseTotal
if @n 5 10 15
512 15 push @out, '';
513 }
514 7 return join "\n", @out;
515 }
516  
517  
518 20 __PACKAGE__->meta->make_immutable;
519  
520 20 1;
521  
522 __END__
« blib/lib/Langertha/Holmgang/Sim/Schichtfehler.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Kueche.pm »