class PostRunner::Percentiles

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

Public Class Methods

new(set) click to toggle source

Create a Percentiles object for the given data set. @param 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.
# File lib/postrunner/Percentiles.rb, line 23
def initialize(set)
  @set = set.sort { |e1, e2| e1[0] <=> e2[0] }
end

Public Instance Methods

not_tp_x(x) click to toggle source

@return [Array] Return the tuples that are not within the given

percentile.

@param x [Float] Percentage value

# 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) click to toggle source

@return [Array] Return the tuples that are within the given percentile. @param x [Float] Percentage value

# 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