diff --git a/Changelog b/Changelog index 3aef116..f81b4fe 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ Revision history for st +1.1.4 Mon Jun 26 13:57:00 2017 +0200 + Percentile between 0 and 100 + 1.1.3 Mon Jun 26 12:58:00 2017 +0200 Fixed --percentile and --quartile options diff --git a/lib/App/St.pm b/lib/App/St.pm index 87c0556..2a2deb6 100644 --- a/lib/App/St.pm +++ b/lib/App/St.pm @@ -109,12 +109,12 @@ sub quartile { if ($q !~ /^[01234]$/) { die "Invalid quartile '$q'\n"; } - return $self->percentile($q/4, %opt); + return $self->percentile($q / 4 * 100, %opt); } sub median { my ($self,%opt) = @_; - return $self->percentile(0.5, %opt); + return $self->percentile(50, %opt); } sub variance { @@ -161,7 +161,7 @@ sub percentile { die "Can't get percentile from empty dataset\n"; } - if ($p < 0 or $p > 1) { + if ($p < 0 or $p > 100) { die "Invalid percentile '$p'\n"; } @@ -172,7 +172,7 @@ sub percentile { } my $N = $self->N(); - my $idx = ($N - 1) * $p; + my $idx = ($N - 1) * $p / 100; my $percentile = int($idx) == $idx ? $data->[$idx] @@ -277,7 +277,7 @@ App::St provides the core functionality of the L application. =head2 stderr -=head2 percentile=<0..1> +=head2 percentile=<0..100> =head2 quartile=<0..4> diff --git a/script/st b/script/st index 84e0e81..e3ea463 100755 --- a/script/st +++ b/script/st @@ -197,7 +197,7 @@ memory, which can be problematic for huge datasets: --q1 # first quartile --median|q2 # second quartile, or median --q3 # third quartile - --percentile=f # percentile=<0..1> + --percentile=f # percentile=<0..100> --quartile=i # quartile=<1..4> If no functions are selected, C will print the default output: diff --git a/t/06-percentile.t b/t/06-percentile.t index a198e2d..607af4c 100644 --- a/t/06-percentile.t +++ b/t/06-percentile.t @@ -15,9 +15,9 @@ for my $num (reverse 1..10) { my %percentiles = ( 0 => 1, - 0.5 => 5.5, - 0.9 => 9.5, - 1 => 10, + 50 => 5.5, + 90 => 9.5, + 100 => 10, ); plan tests => scalar keys %percentiles;