blib/lib/Langertha/Holmgang/Evaluation.pm

filter: Statementstmt 99.4% 352 / 354 Branchbran 92.2% 83 / 90 Conditioncond 74.2% 72 / 97 MC/DCmcdc 49.0% 26 / 53 Subroutinesub 100% 49 / 49 Podpod 42.8% 6 / 14 totaltotal 89.5% 588 / 657 CC 114 SCAR 22.8
CC
114
Cov
94%
_build_verdicts
26.1
_curves
13.7
_build__runs
11.3
CRAP 9.7
« 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 21 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use Langertha::Holmgang::Report ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 our $VERSION = '0.002';
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 348 ▶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 56 ▶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 55 ▶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 104 ▶sub hard_tags { qw( injection verbot ) }
Subroutine hard_tags: called CC=1 SCAR=0.0
Pod undocumented
32  
33 218 ▶sub report_class { 'Langertha::Holmgang::Report' }
Subroutine report_class: called CC=1 SCAR=0.0
Pod undocumented
34  
35 #### Attributes
36  
37 108 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
38 108 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 108 108
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
10800
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 108 ▶ $arg{reports} = [ delete $arg{report} ] if exists $arg{report};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg{"report"} 94 14 108
41 108 return $class->$orig(%arg);
42 21 };
43  
44 21 has reports => ( is => 'ro', required => 1 );
45  
46  
47 25 ▶has thresholds => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
48  
49  
50 108 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=21.0
Pod undocumented
51 108 my ( $self ) = @_;
52 108 my $reports = $self->reports;
53 108 ▶ croak __PACKAGE__.'->new needs reports (an array of '.$self->report_class.')'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reports eq "ARRAY" and @$reports 1 107 108
Condition66%2/3
ref $reports eq "ARRAY" and @$reports
!ll&&!rl&&r
01107
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 107 for my $r ( @$reports ) {
56 112 ▶ 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 111 112
defined $r ? : 1 0 1
Condition66%2/3
builtin::blessed($r) and $r->isa($self->report_class)
!ll&&!rl&&r
10111
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 106 ▶ croak __PACKAGE__.'->new: thresholds must be a hash of suite id to threshold'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->thresholds eq "HASH" 1 105 106
60 unless ref $self->thresholds eq 'HASH';
61 105 return;
62 }
63  
64 21 has _runs => ( is => 'ro', lazy_build => 1 );
65  
66 # The merged runs, flattened into what every view needs.
67 105 ▶sub _build__runs {
Subroutine _build__runs: called CC=11 SCAR=24.2
68 105 my ( $self ) = @_;
69 105 my $merged = $self->report_class->merge( @{ $self->reports } );
70 104 my $json = JSON::MaybeXS->new( canonical => 1 );
71 104 my %hard_tag = map { $_ => 1 } $self->hard_tags;
72 104 my @runs;
73 104 for my $run ( @{ $merged->runs } ) {
74 140 ▶ my $target = $run->{target} || {};
Condition50%1/2
$run->{'target'} || {}
l!l
1400
MC/DC0%0/1
$run->{'target'} || {}
$run->{'target'}
Truth table50%1/2
A
A= $run->{'target'}
Aresult
11
00
75 140 ▶ my $variant = $run->{variant} || {};
Condition50%1/2
$run->{'variant'} || {}
l!l
1400
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 246 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 scenario => $c->{scenario},
93 hard => defined $c->{hard} ? ( $c->{hard} ? 1 : 0 )
94 2 ▶ : ( grep { $hard_tag{$_} } @{ $c->{tags} || [] } ) ? 1 : 0,
Condition50%1/2
$c->{'tags'} || []
l!l
1570
MC/DC0%0/1
$c->{'tags'} || []
$c->{'tags'}
Truth table50%1/2
A
A= $c->{'tags'}
Aresult
11
00
95 repetitions => $c->{repetitions},
96 }
97 140 ▶ } @{ $run->{cases} } ],
Branch: 5 branches
BranchTrueFalseTotal
defined $run->{'suite'}{'topic'} && length $run->{'suite'}{'topic'} ? : 139 1 140
defined $c->{'weight'} ? : 246 0 246
defined $c->{'hard'} ? : 89 157 246
$c->{'hard'} ? : 6 83 89
grep({$hard_tag{$_};} @{$c->{'tags'} or [];}) ? : 2 155 157
Condition66%2/3
defined $run->{"suite"}{"topic"} and length $run->{"suite"}{"topic"}
!ll&&!rl&&r
10139
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
98 };
99 }
100 104 return \@runs;
101 }
102  
103 # Szenarien (AppWorld SGC): Faelle mit gleichem scenario sind Varianten einer Aufgabe; ein
104 # Szenario gilt als geloest, wenn jede Variante in allen k Wiederholungen bestanden hat. Ein Fall
105 # ohne scenario ist sein eigenes. undef, wenn kein Fall der Suite ein scenario traegt.
106 123 ▶sub _scenarios {
Subroutine _scenarios: called CC=7 SCAR=19.5
107 123 my ( $self, $cases, $k ) = @_;
108 123 ▶ return undef unless grep { defined $_->{_scenario} } @$cases;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_->{"_scenario"};} @$cases 121 2 123
109 2 my ( %ok, @order );
110 2 for my $c ( @$cases ) {
111 10 ▶ my $s = $c->{_scenario} // "\0".$c->{case_id};
Condition100%2/2
$c->{"_scenario"} // "\000" . $c->{"case_id"}
l!l
82
MC/DC100%1/1
$c->{"_scenario"} // "\000" . $c->{"case_id"}
$c->{"_scenario"}
Truth table100%2/2
A
A= $c->{"_scenario"}
Aresult
11
00
112 10 ▶ push @order, $s unless exists $ok{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ok{$s} 6 4 10
113 10 ▶ $ok{$s} //= 1;
Condition100%2/2
$ok{$s} //= 1
l!l
46
MC/DC100%1/1
$ok{$s} //= 1
$ok{$s}
Truth table100%2/2
A
A= $ok{$s}
Aresult
11
00
114 10 ▶ $ok{$s} = 0 unless $c->{passed} >= $k;
Branch: 1 branch
BranchTrueFalseTotal
unless $c->{"passed"} >= $k 2 8 10
115 }
116 2 my $solved = grep { $ok{$_} } @order;
117 return { total => scalar @order, solved => $solved, rate => $self->_round( $solved / @order ),
118 2 unsolved => [ map { s/\A\0//r } grep { !$ok{$_} } @order ] };
119 }
120  
121 140 ▶sub _target_label {
Subroutine _target_label: called CC=4 SCAR=16.9
122 140 my ( $self, $t ) = @_;
123 140 for my $k (qw( label model engine )) {
124 140 ▶ return $t->{$k} if defined $t->{$k} && length $t->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{$k} and length $t->{$k} 140 0 140
Condition33%1/3
defined $t->{$k} and length $t->{$k}
!ll&&!rl&&r
00140
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
125 }
126 0 return '?';
127 }
128  
129 #### Tallies
130  
131 216 ▶sub _tally {
Subroutine _tally: called CC=1 SCAR=0.0
132 216 my ( $self ) = @_;
133 216 return { results => 0, _weight => 0, _w => {}, counts => { map { $_ => 0 } $self->statuses } };
134 }
135  
136 519 ▶sub _add {
Subroutine _add: called CC=1 SCAR=0.0
137 519 my ( $self, $t, $rep, $weight ) = @_;
138 519 $t->{results}++;
139 519 $t->{_weight} += $weight;
140 519 $t->{counts}{ $rep->{status} }++;
141 519 $t->{_w}{ $rep->{status} } += $weight;
142 519 return;
143 }
144  
145 762 ▶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 ? : 762 0 762
146  
147 # Weighted share of one status among all results of a tally.
148 260 ▶sub _share {
Subroutine _share: called CC=3 SCAR=11.0
149 260 my ( $self, $t, $status ) = @_;
150 260 ▶ return undef unless $t->{_weight} > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $t->{"_weight"} > 0 10 250 260
151 250 ▶ return $self->_round( ( $t->{_w}{$status} // 0 ) / $t->{_weight} );
Condition100%2/2
$t->{"_w"}{$status} // 0
l!l
15199
MC/DC100%1/1
$t->{"_w"}{$status} // 0
$t->{"_w"}{$status}
Truth table100%2/2
A
A= $t->{"_w"}{$status}
Aresult
11
00
152 }
153  
154 # The public part of a tally.
155 216 ▶sub _counted {
Subroutine _counted: called CC=1 SCAR=0.0
156 216 my ( $self, $t ) = @_;
157 return (
158 results => $t->{results},
159 weight => $self->_round( $t->{_weight} ),
160 216 counts => { %{ $t->{counts} } },
161 rate => $self->_share( $t, 'passed' ),
162 );
163 }
164  
165 #### Topics
166  
167 21 has _topics => ( is => 'ro', lazy_build => 1 );
168  
169 16 ▶sub topics { my ( $self ) = @_; return $self->_public( $self->_topics ) }
Subroutine topics: called CC=1 SCAR=0.0
Pod documented
170  
171 58 ▶sub _build__topics {
Subroutine _build__topics: called CC=11 SCAR=24.0
172 58 my ( $self ) = @_;
173 58 my ( %agg, @rows );
174 58 for my $run ( @{ $self->_runs } ) {
175 90 ▶ 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
19710
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
176 71 push @rows, $run->{row};
177 { target => $run->{target}, variant => $run->{variant}, topic => $run->{topic},
178 71 suites => [], tally => $self->_tally, tokens => {} };
179 };
180 90 ▶ push @{ $a->{suites} }, $run->{suite} unless grep { $_ eq $run->{suite} } @{ $a->{suites} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $run->{"suite"};} @{$$a{"suites"};} 90 0 90
181 90 for my $c ( @{ $run->{cases} } ) {
182 139 for my $rep ( @{ $c->{repetitions} } ) {
183 167 $self->_add( $a->{tally}, $rep, $c->{weight} );
184 167 for my $f (qw( input output reasoning )) {
185 501 ▶ my $n = $rep->{tokens} && $rep->{tokens}{$f};
Condition66%2/3
$rep->{'tokens'} && $rep->{'tokens'}{$f}
!ll&&!rl&&r
04956
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
186 501 ▶ $a->{tokens}{$f} += $n if defined $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 6 495 501
187 }
188 }
189 }
190 }
191 58 my %seen;
192 58 @rows = grep { !$seen{$_}++ } @rows;
193 58 my @out;
194 58 for my $row ( @rows ) {
195 65 for my $topic ( sort keys %{ $agg{$row} } ) {
196 71 my $a = $agg{$row}{$topic};
197 push @out, {
198 target => $a->{target},
199 variant => $a->{variant},
200 topic => $topic,
201 71 suites => [ sort @{ $a->{suites} } ],
202 $self->_counted( $a->{tally} ),
203 71 tokens => { map { $_ => $a->{tokens}{$_} } qw( input output reasoning ) },
204 _row => $row,
205 };
206 }
207 }
208 58 return \@out;
209 }
210  
211  
212 21 has _overall => ( is => 'ro', lazy_build => 1 );
213  
214 14 ▶sub overall { my ( $self ) = @_; return $self->_public( $self->_overall ) }
Subroutine overall: called CC=1 SCAR=0.0
Pod documented
215  
216 56 ▶sub _build__overall {
Subroutine _build__overall: called CC=7 SCAR=19.5
217 56 my ( $self ) = @_;
218 56 my ( %o, @rows );
219 56 for my $t ( @{ $self->_topics } ) {
220 69 ▶ 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
6630
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
221 63 push @rows, $t->{_row};
222 { target => $t->{target}, variant => $t->{variant}, topics => 0, results => 0,
223 63 counts => { map { $_ => 0 } $self->statuses }, _rates => [] };
224 };
225 69 $o->{topics}++;
226 69 $o->{results} += $t->{results};
227 69 $o->{counts}{$_} += $t->{counts}{$_} for $self->statuses;
228 69 ▶ push @{ $o->{_rates} }, $t->{rate} if defined $t->{rate};
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{"rate"} 65 4 69
229 }
230 return [ map {
231 56 my $o = $o{$_};
232 63 my $rates = delete $o->{_rates};
233 63 my $sum = 0;
234 63 $sum += $_ for @$rates;
235 63 ▶ $o->{rate} = @$rates ? $self->_round( $sum / @$rates ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$rates ? : 60 3 63
236 63 $o->{_row} = $_;
237 63 $o;
238 } @rows ];
239 }
240  
241  
242 #### Length tiers
243  
244 21 has tier_curves => ( is => 'ro', lazy_build => 1, init_arg => undef );
245  
246 # Known values first in their order, any other after them by its number,
247 # then by text.
248 42 ▶sub _order {
Subroutine _order: called CC=3 SCAR=11.0
249 42 my ( $self, $known, $v ) = @_;
250 42 my ($i) = grep { $known->[$_] eq $v } 0 .. $#$known;
251 42 ▶ return defined $i ? ( 0, $i, 0, '' ) : ( 1, 0, ( $v =~ /\A([0-9]+)/ ? $1 : 0 ), $v );
Branch: 2 branches
BranchTrueFalseTotal
defined $i ? : 33 9 42
$v =~ /\A([0-9]+)/ ? : 6 3 9
252 }
253  
254 # One curve per row and topic over the values of a case field.
255 111 ▶sub _curves {
Subroutine _curves: called CC=13 SCAR=26.2
256 111 my ( $self, $field, @known ) = @_;
257 111 my ( %agg, @rows );
258 111 for my $run ( @{ $self->_runs } ) {
259 162 for my $c ( @{ $run->{cases} } ) {
260 240 ▶ next unless defined $c->{$field} && length $c->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c->{$field} and length $c->{$field} 200 40 240
Condition66%2/3
defined $c->{$field} and length $c->{$field}
!ll&&!rl&&r
200040
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
261 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
262 22 push @rows, $run->{row};
263 22 { target => $run->{target}, variant => $run->{variant}, tally => $self->_tally };
264 };
265 40 $self->_add( $a->{tally}, $_, $c->{weight} ) for @{ $c->{repetitions} };
266 }
267 }
268 111 my %seen;
269 my @out;
270 111 for my $row ( grep { !$seen{$_}++ } @rows ) {
271 9 for my $topic ( sort keys %{ $agg{$row} } ) {
272 9 my $by = $agg{$row}{$topic};
273 my @values = sort {
274 9 my @x = $self->_order( \@known, $a );
275 21 my @y = $self->_order( \@known, $b );
276 21 ▶ $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
2100
$x[0] <=> $y[0] or $x[1] <=> $y[1] or $x[2] <=> $y[2]
l!l&&r!l&&!r
2100
$x[0] <=> $y[0] or $x[1] <=> $y[1]
l!l&&r!l&&!r
9120
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
277 } keys %$by;
278 9 for my $v ( @values ) {
279 22 my $a = $by->{$v};
280 push @out, {
281 target => $a->{target},
282 variant => $a->{variant},
283 topic => $topic,
284 $field => $v,
285 $self->_counted( $a->{tally} ),
286 context_exceeded_rate => $self->_share( $a->{tally}, 'context_exceeded' ),
287 22 error_rate => $self->_share( $a->{tally}, 'error' ),
288 };
289 }
290 }
291 }
292 111 return \@out;
293 }
294  
295 56 ▶sub _build_tier_curves { my ( $self ) = @_; return $self->_curves( tier => $self->tiers ) }
Subroutine _build_tier_curves: called CC=1 SCAR=0.0
296  
297  
298 #### Difficulties
299  
300 21 has difficulty_curves => ( is => 'ro', lazy_build => 1, init_arg => undef );
301  
302 55 ▶sub _build_difficulty_curves { my ( $self ) = @_; return $self->_curves( difficulty => $self->difficulties ) }
Subroutine _build_difficulty_curves: called CC=1 SCAR=0.0
303  
304  
305 #### Verdicts
306  
307 21 has verdicts => ( is => 'ro', lazy_build => 1, init_arg => undef );
308  
309 96 ▶sub _build_verdicts {
Subroutine _build_verdicts: called CC=26 SCAR=32.6
310 96 my ( $self ) = @_;
311 96 my ( %v, @order );
312 96 for my $run ( @{ $self->_runs } ) {
313 123 my $key = $run->{row}."\0".$run->{suite};
314 croak __PACKAGE__.': suite '.$run->{suite}.' appears twice for target '.$run->{target}.' after merging'
315 123 ▶ if $v{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $v{$key} 0 123 123
316 123 push @order, $key;
317 my $v = $v{$key} = { target => $run->{target}, variant => $run->{variant}, suite_id => $run->{suite},
318 k => $run->{k}, tally => $self->_tally, cases => [], hard => {}, measured => {},
319 unfinished => defined $run->{status} && $run->{status} ne 'complete'
320 123 ▶ ? { status => $run->{status}, error => $run->{error} } : undef };
Branch: 1 branch
BranchTrueFalseTotal
defined $run->{'status'} && $run->{'status'} ne 'complete' ? : 8 115 123
Condition66%2/3
defined $run->{"status"} and $run->{"status"} ne "complete"
!ll&&!rl&&r
01158
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
321 123 for my $c ( @{ $run->{cases} } ) {
322 # a repetition with any result but error reached the target (cai-platform runs_error)
323 187 $v->{measured}{ $_->{repetition} } = 1 for grep { $_->{status} ne 'error' } @{ $c->{repetitions} };
324 187 my @reps = @{ $c->{repetitions} };
325 187 ▶ next unless @reps;
Branch: 1 branch
BranchTrueFalseTotal
unless @reps 7 180 187
326 180 my $passed = grep { $_->{status} eq 'passed' } @reps;
327 180 push @{ $v->{cases} }, { case_id => $c->{case_id}, passed => $passed, repetitions => scalar @reps, _w => $c->{weight},
328 180 _scenario => $c->{scenario} };
329 180 for my $rep ( @reps ) {
330 295 $self->_add( $v->{tally}, $rep, $c->{weight} );
331 295 ▶ my $n = $rep->{forbidden_calls} // 0;
Condition50%1/2
$rep->{"forbidden_calls"} // 0
l!l
2950
MC/DC0%0/1
$rep->{"forbidden_calls"} // 0
$rep->{"forbidden_calls"}
Truth table50%1/2
A
A= $rep->{"forbidden_calls"}
Aresult
11
00
332 295 ▶ next unless $n && $c->{hard};
Branch: 1 branch
BranchTrueFalseTotal
unless $n and $c->{"hard"} 290 5 295
Condition100%3/3
$n and $c->{"hard"}
!ll&&!rl&&r
28735
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
333 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
334 5 $h->{forbidden_calls} += $n;
335 5 $h->{repetitions}++;
336 }
337 }
338 }
339 95 my @out;
340 95 for my $key ( @order ) {
341 123 my $v = $v{$key};
342 123 ▶ my $th = $self->thresholds->{ $v->{suite_id} } || {};
Condition100%2/2
$self->thresholds->{$v->{'suite_id'}} || {}
l!l
3390
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
343 123 my $k = $v->{k};
344 123 my %c = $self->_counted( $v->{tally} );
345 123 my $wc = 0;
346 123 $wc += $_->{_w} for @{ $v->{cases} };
347 246 ▶ my $share = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
348 246 my ( $pick ) = @_;
349 246 ▶ return undef unless @{ $v->{cases} } && $wc > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$v->{"cases"};} and $wc > 0 12 234 246
Condition66%2/3
@{$v->{"cases"};} and $wc > 0
!ll&&!rl&&r
120234
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
350 234 my $w = 0;
351 234 $w += $_->{_w} for grep { $pick->($_) } @{ $v->{cases} };
352 234 return $self->_round( $w / $wc );
353 123 };
354 my $out = {
355 target => $v->{target},
356 variant => $v->{variant},
357 suite_id => $v->{suite_id},
358 results => $c{results},
359 counts => $c{counts},
360 passed => $c{counts}{passed},
361 rate => $c{rate},
362 pass_rate => $th->{pass_rate},
363 k => $k,
364 180 ▶ pass_k => $share->( sub { $_[0]{passed} >= $k } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
365 180 ▶ pass_any => $share->( sub { $_[0]{passed} > 0 } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
366 pass_k_min => $th->{pass_k},
367 scenarios => $self->_scenarios( $v->{cases}, $k ),
368 180 case_results => [ map { { case_id => $_->{case_id}, passed => $_->{passed}, repetitions => $_->{repetitions} } } @{ $v->{cases} } ],
369 5 hard_failed => [ map { $v->{hard}{$_} } sort keys %{ $v->{hard} } ],
370 181 repetitions_error => scalar( grep { !$v->{measured}{$_} } 1 .. $k ),
371 unfinished => $v->{unfinished},
372 123 };
373 123 ▶ delete $out->{scenarios} unless defined $out->{scenarios};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out->{"scenarios"} 121 2 123
374 my $below = ( defined $out->{pass_rate} && ( !defined $out->{rate} || $out->{rate} < $out->{pass_rate} ) )
375 123 ▶ || ( 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
142107
defined $out->{"pass_rate"} and !defined($out->{"rate"}) || $out->{"rate"} < $out->{"pass_rate"}
!ll&&!rl&&r
931614
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
10162
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
376 # a suite without any measured repetition is not ok; unmeasured repetitions
377 # next to a measured one are only reported -- ADR 0009 k42 (ADR 0008 k73 amendment)
378 123 ▶ $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 78 123
Condition100%9/9
$below or @{$out->{"hard_failed"};} or $out->{"unfinished"} or $self->_unmeasured($out)
l!l&&r!l&&!r
291678
$below or @{$out->{"hard_failed"};} or $out->{"unfinished"}
l!l&&r!l&&!r
21894
$below or @{$out->{"hard_failed"};}
l!l&&r!l&&!r
165102
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
379 ? JSON::MaybeXS::false() : JSON::MaybeXS::true();
380 123 push @out, $out;
381 }
382 95 return \@out;
383 }
384  
385 # a verdict whose suite measured nothing: no repetition reached the target (k73)
386 135 ▶sub _unmeasured { my ( $self, $v ) = @_; return $v->{repetitions_error} == $v->{k} }
Subroutine _unmeasured: called CC=1 SCAR=0.0
387  
388  
389 #### Comparison
390  
391 21 has comparison => ( is => 'ro', lazy_build => 1, init_arg => undef );
392  
393 53 ▶sub _build_comparison {
Subroutine _build_comparison: called CC=1 SCAR=0.0
394 53 my ( $self ) = @_;
395 53 my %topics = map { $_->{topic} => 1 } @{ $self->_topics };
396 my @rows = map {
397 59 my $o = $_;
398 {
399 target => $o->{target},
400 variant => $o->{variant},
401 61 rates => { map { $_->{topic} => $_->{rate} } grep { $_->{_row} eq $o->{_row} } @{ $self->_topics } },
402 overall => $o->{rate},
403 }
404 53 } @{ $self->_overall };
405 53 return { topics => [ sort keys %topics ], rows => \@rows };
406 }
407  
408  
409 #### Output
410  
411 30 ▶sub _public {
Subroutine _public: called CC=1 SCAR=0.0
412 30 my ( $self, $rows ) = @_;
413 30 return [ map { my %r = %$_; delete $r{_row}; \%r } @$rows ];
414 }
415  
416 8 ▶sub as_data {
Subroutine as_data: called CC=1 SCAR=0.0
Pod documented
417 8 my ( $self ) = @_;
418 return {
419 8 holmgang_evaluation => $self->format_version,
420 topics => $self->topics,
421 overall => $self->overall,
422 tier_curves => $self->tier_curves,
423 difficulty_curves => $self->difficulty_curves,
424 verdicts => $self->verdicts,
425 comparison => $self->comparison,
426 };
427 }
428  
429  
430 5 ▶sub to_json {
Subroutine to_json: called CC=1 SCAR=0.0
Pod documented
431 5 my ( $self ) = @_;
432 5 return JSON::MaybeXS->new( utf8 => 1, canonical => 1, pretty => 1 )->encode( $self->as_data );
433 }
434  
435  
436 426 ▶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 ? : 267 159 426
437  
438 154 ▶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 ? : 150 4 154
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
40150
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
439  
440 # a run's error for a note: on one line, cut to 200 characters with an ellipsis
441 # (as the CLI's notes, k44)
442 11 ▶sub _line {
Subroutine _line: called CC=2 SCAR=6.9
443 11 my ( $self, $t ) = @_;
444 11 $t = join ' ', split ' ', $t;
445 11 ▶ return $t if length $t <= 200;
Branch: 1 branch
BranchTrueFalseTotal
if length $t <= 200 10 1 11
446 1 return substr( $t, 0, 200 ) =~ s/\s+\z//r." \x{2026}";
447 }
448  
449 # The tables both text renderers draw: [ title, header, rows, notes per row ].
450 56 ▶sub _tables {
Subroutine _tables: called CC=11 SCAR=24.0
451 56 my ( $self ) = @_;
452 56 my $cmp = $self->comparison;
453 my @tables = ( [
454 'Comparison by topic (share passed; overall = mean of the topics)',
455 56 [ 'target', 'variant', @{ $cmp->{topics} }, 'overall' ],
456 [ map {
457 61 my $r = $_;
458 [ $r->{target}, $self->_cell( $r->{variant} ),
459 61 ( map { $self->_pct( $r->{rates}{$_} ) } @{ $cmp->{topics} } ), $self->_pct( $r->{overall} ) ]
460 56 } @{ $cmp->{rows} } ],
461 [],
462 ] );
463 56 my ( @vrows, @notes );
464 56 for my $v ( @{ $self->verdicts } ) {
465 push @vrows, [ $v->{target}, $self->_cell( $v->{variant} ), $v->{suite_id},
466 $v->{passed}.'/'.$v->{results}, $self->_pct( $v->{rate} ), $self->_pct( $v->{pass_rate} ),
467 $v->{k} > 1 ? $self->_pct( $v->{pass_k} ).' (k='.$v->{k}.')' : '-',
468 $self->_pct( $v->{pass_k_min} ),
469 86 ▶ $v->{ok} ? 'ok' : $self->_unmeasured($v) ? 'NOT MEASURED' : 'NOT PASSED' ];
Branch: 3 branches
BranchTrueFalseTotal
$v->{'k'} > 1 ? : 20 66 86
$v->{'ok'} ? : 45 41 86
$self->_unmeasured($v) ? : 20 21 41
470 push @notes, [
471 ( $v->{unfinished}
472 ? 'run '.$v->{unfinished}{status}.( defined $v->{unfinished}{error} ? ': '.$self->_line( $v->{unfinished}{error} ) : '' ) : () ),
473 ( $v->{repetitions_error}
474 ? 'no result but error in '.$v->{repetitions_error}.' of '.$v->{k}.' repetition(s): nothing measured' : () ),
475 ( $v->{scenarios}
476 ? 'scenarios: '.$v->{scenarios}{solved}.'/'.$v->{scenarios}{total}.' solved in every variant ('.$self->_pct( $v->{scenarios}{rate} ).')' : () ),
477 map {
478 'hard: '.$_->{case_id}.' - '.$_->{forbidden_calls}.' forbidden call(s) in '.$_->{repetitions}.' of '.$v->{k}
479 86 ▶ } @{ $v->{hard_failed} } ];
Branch: 4 branches
BranchTrueFalseTotal
$v->{'unfinished'} ? : 12 74 86
defined $v->{'unfinished'}{'error'} ? : 11 1 12
$v->{'repetitions_error'} ? : 24 62 86
$v->{'scenarios'} ? : 1 85 86
480 }
481 56 push @tables, [ 'Verdicts per suite',
482 [ 'target', 'variant', 'suite', 'passed', 'rate', 'threshold', 'pass^k', 'pass^k min', 'verdict' ],
483 \@vrows, \@notes ];
484 56 ▶ if ( @{ $self->tier_curves } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->tier_curves;}) 1 55 56
485 push @tables, [ 'Length tiers (shares of all results)',
486 [ 'target', 'variant', 'topic', 'tier', 'results', 'passed', 'context_exceeded', 'error' ],
487 [ map { [ $_->{target}, $self->_cell( $_->{variant} ), $_->{topic}, $_->{tier}, $_->{results},
488 1 $self->_pct( $_->{rate} ), $self->_pct( $_->{context_exceeded_rate} ), $self->_pct( $_->{error_rate} ) ] }
489 1 @{ $self->tier_curves } ],
490 [] ];
491 }
492 56 ▶ if ( @{ $self->difficulty_curves } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->difficulty_curves;}) 4 52 56
493 push @tables, [ 'Difficulty (shares of all results)',
494 [ 'target', 'variant', 'topic', 'difficulty', 'results', 'passed', 'context_exceeded', 'error' ],
495 [ map { [ $_->{target}, $self->_cell( $_->{variant} ), $_->{topic}, $_->{difficulty}, $_->{results},
496 6 $self->_pct( $_->{rate} ), $self->_pct( $_->{context_exceeded_rate} ), $self->_pct( $_->{error_rate} ) ] }
497 4 @{ $self->difficulty_curves } ],
498 [] ];
499 }
500 56 return @tables;
501 }
502  
503 49 ▶sub to_text {
Subroutine to_text: called CC=7 SCAR=19.5
Pod documented
504 49 my ( $self ) = @_;
505 49 my @out;
506 49 for my $t ( $self->_tables ) {
507 102 my ( $title, $head, $rows, $notes ) = @$t;
508 102 my @w = map { length } @$head;
509 102 for my $r ( @$rows ) {
510 132 ▶ $w[$_] = length $r->[$_] > $w[$_] ? length $r->[$_] : $w[$_] for 0 .. $#$r;
Branch: 1 branch
BranchTrueFalseTotal
length $r->[$_] > $w[$_] ? : 210 710 920
511 }
512 102 ▶ 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
513 102 push @out, $title, $line->($head);
514 102 for my $i ( 0 .. $#$rows ) {
515 132 push @out, $line->( $rows->[$i] );
516 132 ▶ push @out, map { ' '.$_ } @{ $notes->[$i] || [] };
Condition100%2/2
$notes->[$i] || []
l!l
7458
MC/DC100%1/1
$notes->[$i] || []
$notes->[$i]
Truth table100%2/2
A
A= $notes->[$i]
Aresult
11
00
517 }
518 102 push @out, '';
519 }
520 49 return join "\n", @out;
521 }
522  
523  
524 7 ▶sub to_markdown {
Subroutine to_markdown: called CC=4 SCAR=13.9
Pod documented
525 7 my ( $self ) = @_;
526 7 ▶ my $esc = sub { my ( $v ) = @_; return $v =~ s/([|\\])/\\$1/gr };
Subroutine __ANON__: called CC=1 SCAR=0.0
527 7 my @out;
528 7 for my $t ( $self->_tables ) {
529 15 my ( $title, $head, $rows, $notes ) = @$t;
530 100 push @out, '### '.$title, '', '| '.join( ' | ', map { $esc->($_) } @$head ).' |',
531 15 '|'.join( '|', map { '---' } @$head ).'|';
532 15 push @out, map { '| '.join( ' | ', map { $esc->($_) } @$_ ).' |' } @$rows;
533 # a note names its row, as the list stands apart from the table
534 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
535 15 ▶ push @out, '', map { '- '.$esc->($_) } @n if @n;
Branch: 1 branch
BranchTrueFalseTotal
if @n 5 10 15
536 15 push @out, '';
537 }
538 7 return join "\n", @out;
539 }
540  
541  
542 21 __PACKAGE__->meta->make_immutable;
543  
544 21 1;
545  
546 __END__
« blib/lib/Langertha/Holmgang/Sim/Schichtfehler.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Kueche.pm »