Class: ApacheCrunch::Percentile

Inherits:
ProcedureRoutine show all
Defined in:
lib/procedure_dsl.rb

Overview

DSL routine that determines the nth percentile for the values to which the block evaluates

This routine returns a float, and the block must always evaluate to something with a to_f method.

Instance Method Summary collapse

Methods inherited from ProcedureRoutine

#finish, #initialize, #method_missing

Constructor Details

This class inherits a constructor from ApacheCrunch::ProcedureRoutine

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ApacheCrunch::ProcedureRoutine

Instance Method Details

#execute(n, &blk) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/procedure_dsl.rb', line 238

def execute(n, &blk)
    # Build a list of all the values found
    values = []
    while @_current_entry = @_log_parser.next_entry
        values << instance_eval(&blk).to_f
    end
    values.sort!

    puts "values.length: #{values.length}"
    puts "n/100.0*values.length: #{n/100.0*values.length}"
    return values[((n/100.0)*values.length).to_i]
end