blib/lib/App/RecordStream/Aggregator/Percentile.pm

filter: Statementstmt 84.3% 43 / 51 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 10 / 13 Podpod 0.0% 0 / 8 totaltotal 74.3% 55 / 74 CC 2 SCAR 3.1
CC
2
Cov
85%
new_from_valuation
2.0
squish
2.0
long_usage
2.0
CRAP 1.4
« blib/lib/App/RecordStream/Test/UniqConcatHelper.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/LastRecord.pm »
1 package App::RecordStream::Aggregator::Percentile;
2  
3 7 our $VERSION = "4.0.23";
4  
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use App::RecordStream::Aggregator::InjectInto::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use App::RecordStream::DomainLanguage::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use base qw(App::RecordStream::Aggregator::InjectInto::Field);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new
14 {
15 2 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
16 2 my $percentile = shift;
17 2 my $field = shift;
18  
19 2 my $this = $class->SUPER::new($field);
20 2 $this->{'percentile'} = $percentile;
21  
22 2 return $this;
23 }
24  
25 sub new_from_valuation
26 {
27 0 ▶ my $class = shift;
Subroutine new_from_valuation: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $percentile = shift;
29 0 my $valuation = shift;
30  
31 0 my $this = $class->SUPER::new_from_valuation($valuation);
32 0 $this->{'percentile'} = $percentile;
33  
34 0 return $this;
35 }
36  
37 sub initial {
38 2 ▶ return [];
Subroutine initial: called CC=1 SCAR=0.0
Pod undocumented
39 }
40  
41 sub combine_field
42 {
43 200 ▶ my $this = shift;
Subroutine combine_field: called CC=1 SCAR=0.0
Pod undocumented
44 200 my $cookie = shift;
45 200 my $value = shift;
46  
47 200 push @$cookie, $value;
48 200 return $cookie;
49 }
50  
51 sub squish
52 {
53 2 ▶ my $this = shift;
Subroutine squish: called CC=2 SCAR=6.9
Pod undocumented
54 2 my $cookie = shift;
55  
56 2 my $percentile = $this->{'percentile'};
57  
58 2 my @sorted = sort { $a <=> $b } @$cookie;
59  
60 2 my $index = int( (scalar @sorted) * ($percentile / 100));
61  
62 2 ▶ if ( $index == scalar @sorted )
Branch: 1 branch
BranchTrueFalseTotal
if ($index == scalar @sorted) 1 1 2
63 {
64 1 $index--;
65 }
66  
67 2 return $sorted[$index];
68 }
69  
70 sub short_usage
71 {
72 1 ▶ return "value of pXX for field";
Subroutine short_usage: called CC=1 SCAR=0.0
Pod undocumented
73 }
74  
75 sub long_usage
76 {
77 0 ▶ print <<EOF;
Subroutine long_usage: not called CC=1 SCAR=6.9
Pod undocumented
78 Usage: per,<percentile>,<field>
79 Finds the field value which <percentile> percent of values are less than.
80  
81 This is computed by creating an array of all values, sorting, and indexing into it at the
82 floor((percentile / 100) * length) point
83 EOF
84 }
85  
86 sub argct
87 {
88 0 ▶ return 2;
Subroutine argct: not called CC=1 SCAR=6.9
Pod undocumented
89 }
90  
91 7 App::RecordStream::Aggregator->register_implementation('percentile', __PACKAGE__);
92 7 App::RecordStream::Aggregator->register_implementation('perc', __PACKAGE__);
93  
94 7 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'percentile', 'SCALAR', 'VALUATION');
95 7 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'perc', 'SCALAR', 'VALUATION');
96  
97 7 1;
« blib/lib/App/RecordStream/Test/UniqConcatHelper.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/LastRecord.pm »