« blib/lib/App/RecordStream/Operation/fromjsonarray.pm
↑ Summary
blib/lib/App/RecordStream/Operation/stream2table.pm »
| 1 | package App::RecordStream::Operation::delta; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = "4.0.23"; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use base qw(App::RecordStream::Operation); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub init | ||||||||||||||||||||||||||||
| 10 | { | ||||||||||||||||||||||||||||
| 11 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 3 | my $args = shift; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | my $key_groups = App::RecordStream::KeyGroups->new(); | |||||||||||||||||||||||||||
| 15 | my $spec = { | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | "key|k=s" => sub { $key_groups->add_groups($_[1]); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | }; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | $this->parse_options($args, $spec); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | die "Must specify --key\n" unless $key_groups->has_any_group(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | $this->{'KEY_GROUPS'} = $key_groups; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub accept_record | ||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 10 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
accept_record: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 10 | my $record = shift; | |||||||||||||||||||||||||||
| 30 | 10 | my $last_record = $this->{'LAST_RECORD'}; | |||||||||||||||||||||||||||
| 31 | 10 | ▶ | if ( $last_record ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 8 | foreach my $key (@{$this->{'KEY_GROUPS'}->get_keyspecs($last_record)}) | |||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 8 | ▶ | if ( ${$record->guess_key_from_spec($key)} and ${$last_record->guess_key_from_spec($key)} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
${$record->guess_key_from_spec($key);} and ${$last_record->guess_key_from_spec($key);}
MC/DC0%0/2
${$record->guess_key_from_spec($key);} and ${$last_record->guess_key_from_spec($key);}
${$record->guess_key_from_spec($key);}
${$last_record->guess_key_from_spec($key);}
Truth table33%1/3
A and B
A= ${$record->guess_key_from_spec($key);}B= ${$last_record->guess_key_from_spec($key);}
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 8 | ${$last_record->guess_key_from_spec($key)} = ${$record->guess_key_from_spec($key)} - ${$last_record->guess_key_from_spec($key)}; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | ${$last_record->guess_key_from_spec($key)} = undef; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 8 | $this->push_record($last_record); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 10 | $this->{'LAST_RECORD'} = $record; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | return 1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub add_help_types { | ||||||||||||||||||||||||||||
| 52 | 3 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
add_help_types: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 3 | $this->use_help_type('keyspecs'); | |||||||||||||||||||||||||||
| 54 | 3 | $this->use_help_type('keygroups'); | |||||||||||||||||||||||||||
| 55 | 3 | $this->use_help_type('keys'); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub usage | ||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 1 | ▶ | my $this = shift; | ||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | my $options = [ | |||||||||||||||||||||||||||
| 63 | [ 'key|-k <keys>', 'Comma separated list of the fields that should be transformed. Fields not in this list will be passed through unchanged, using the *first* record of each delta pair. This may be a keyspec or a keygroup, see "--help-keyspecs" for more information'], | ||||||||||||||||||||||||||||
| 64 | ]; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $args_string = $this->options_string($options); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | return <<USAGE; | |||||||||||||||||||||||||||
| 69 | Usage: recs-delta <args> [<files>] | ||||||||||||||||||||||||||||
| 70 | __FORMAT_TEXT__ | ||||||||||||||||||||||||||||
| 71 | Transforms absolute values into deltas between adjacent records. | ||||||||||||||||||||||||||||
| 72 | __FORMAT_TEXT__ | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Arguments: | ||||||||||||||||||||||||||||
| 75 | $args_string | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Examples: | ||||||||||||||||||||||||||||
| 78 | Transforms a cumulative counter of errors into a count of errors per record. | ||||||||||||||||||||||||||||
| 79 | recs-delta --key=errors | ||||||||||||||||||||||||||||
| 80 | USAGE | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||