Class: PostRunner::Percentiles
- Inherits:
-
Object
- Object
- PostRunner::Percentiles
- Defined in:
- lib/postrunner/Percentiles.rb
Overview
This class can be used to partition sets according to a given percentile.
Instance Method Summary collapse
-
#initialize(set) ⇒ Percentiles
constructor
Create a Percentiles object for the given data set.
-
#not_tp_x(x) ⇒ Array
Return the tuples that are not within the given percentile.
-
#tp_x(x) ⇒ Array
Return the tuples that are within the given percentile.
Constructor Details
#initialize(set) ⇒ Percentiles
Create a Percentiles object for the given data set.
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.
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.
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 |