« blib/lib/App/RecordStream/Aggregator/UniqConcatenate.pm
↑ Summary
blib/lib/App/RecordStream/Aggregator/InjectInto.pm »
| 1 | package App::RecordStream::Aggregator::DistinctCount; | ||
| 2 | |||
| 3 | 7 | our $VERSION = "4.0.25"; | |
| 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; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 7 | ▶ | use App::RecordStream::DomainLanguage::Registry; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 7 | ▶ | use App::RecordStream::DomainLanguage::Valuation::KeySpec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 7 | ▶ | use base qw(App::RecordStream::Aggregator::Aggregation); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | sub new | ||
| 15 | 1 | ▶ | { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 16 | 1 | my $class = shift; | |
| 17 | 1 | my $field = shift; | |
| 18 | |||
| 19 | 1 | return new_from_valuation($class, App::RecordStream::DomainLanguage::Valuation::KeySpec->new($field)); | |
| 20 | } | ||
| 21 | |||
| 22 | sub new_from_valuation | ||
| 23 | 10 | ▶ | { |
|
Subroutine
new_from_valuation: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 24 | 10 | my $class = shift; | |
| 25 | 10 | my ($valuation) = @_; | |
| 26 | |||
| 27 | 10 | my $this = | |
| 28 | { | ||
| 29 | 'valuation' => $valuation, | ||
| 30 | }; | ||
| 31 | 10 | bless $this, $class; | |
| 32 | |||
| 33 | 10 | return $this; | |
| 34 | } | ||
| 35 | |||
| 36 | sub squish | ||
| 37 | 40 | ▶ | { |
|
Subroutine
squish: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 38 | 40 | my ($this, $cookie) = @_; | |
| 39 | |||
| 40 | 40 | return scalar(keys(%$cookie)); | |
| 41 | } | ||
| 42 | |||
| 43 | sub short_usage | ||
| 44 | 1 | ▶ | { |
|
Subroutine
short_usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 45 | 1 | return "count unique values from provided field"; | |
| 46 | } | ||
| 47 | |||
| 48 | sub long_usage | ||
| 49 | 0 | ▶ | { |
|
Subroutine
long_usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 50 | 0 | return <<EOF; | |
| 51 | Usage: dct,<field> | ||
| 52 | Finds the number of unique values for a field and returns it. Will load all | ||
| 53 | values into memory. | ||
| 54 | EOF | ||
| 55 | } | ||
| 56 | |||
| 57 | sub argct | ||
| 58 | 0 | ▶ | { |
|
Subroutine
argct: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 59 | 0 | return 1; | |
| 60 | } | ||
| 61 | |||
| 62 | sub initial | ||
| 63 | 40 | ▶ | { |
|
Subroutine
initial: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 64 | 40 | return {}; | |
| 65 | } | ||
| 66 | |||
| 67 | sub combine | ||
| 68 | 312 | ▶ | { |
|
Subroutine
combine: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 69 | 312 | my ($this, $cookie, $record) = @_; | |
| 70 | |||
| 71 | 312 | my $value = $this->{'valuation'}->evaluate_record($record); | |
| 72 | |||
| 73 | 312 | $cookie->{$value} = 1; | |
| 74 | |||
| 75 | 312 | return $cookie; | |
| 76 | } | ||
| 77 | |||
| 78 | 7 | App::RecordStream::Aggregator->register_implementation('dcount', __PACKAGE__); | |
| 79 | 7 | App::RecordStream::Aggregator->register_implementation('dct', __PACKAGE__); | |
| 80 | 7 | App::RecordStream::Aggregator->register_implementation('distinctcount', __PACKAGE__); | |
| 81 | 7 | App::RecordStream::Aggregator->register_implementation('distinctct', __PACKAGE__); | |
| 82 | |||
| 83 | 7 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'dcount', 'VALUATION'); | |
| 84 | 7 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'dct', 'VALUATION'); | |
| 85 | 7 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'distinctcount', 'VALUATION'); | |
| 86 | 7 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'distinctct', 'VALUATION'); | |
| 87 | |||
| 88 | 7 | 1; | |