Skip to content

Commit

Permalink
Percentile between 0 and 100
Browse files Browse the repository at this point in the history
  • Loading branch information
nelson-ferraz committed Jun 26, 2017
1 parent 2add1e6 commit 915674e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions lib/App/St.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
}

Expand All @@ -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]
Expand Down Expand Up @@ -277,7 +277,7 @@ App::St provides the core functionality of the L<st> application.
=head2 stderr
=head2 percentile=<0..1>
=head2 percentile=<0..100>
=head2 quartile=<0..4>
Expand Down
2 changes: 1 addition & 1 deletion script/st
Original file line number Diff line number Diff line change
Expand Up @@ -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<st> will print the default output:
Expand Down
6 changes: 3 additions & 3 deletions t/06-percentile.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 915674e

Please sign in to comment.