Class: PostRunner::Percentiles

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/Percentiles.rb

Overview

This class can be used to partition sets according to a given percentile.

Instance Method Summary collapse

Constructor Details

#initialize(set) ⇒ Percentiles

Create a Percentiles object for the given data set.

Parameters:

  • set (Array)

    It must be an Array of tuples (2 element Array). The first element is the actual value, the second does not matter for the computation. It is usually a reference to the context of the value.



23
24
25
# File 'lib/postrunner/Percentiles.rb', line 23

def initialize(set)
  @set = set.sort { |e1, e2| e1[0] <=> e2[0] }
end

Instance Method Details

#not_tp_x(x) ⇒ Array

Return the tuples that are not within the given percentile.

Parameters:

  • x (Float)

    Percentage value

Returns:

  • (Array)

    Return the tuples that are not within the given percentile.



37
38
39
40
# File 'lib/postrunner/Percentiles.rb', line 37

def not_tp_x(x)
  split_idx = (x / 100.0 * @set.size).to_i
  @set[split_idx..-1]
end

#tp_x(x) ⇒ Array

Return the tuples that are within the given percentile.

Parameters:

  • x (Float)

    Percentage value

Returns:

  • (Array)

    Return the tuples that are within the given percentile.



29
30
31
32
# File 'lib/postrunner/Percentiles.rb', line 29

def tp_x(x)
  split_idx = (x / 100.0 * @set.size).to_i
  @set[0..split_idx]
end