class ApacheCrunch::Distribution
DSL routine that finds the distribution of (numeric) values to which the given block evaluates
For example,
distribution 100 do bytes_sent end
would return a hash with keys from 0 up by multiples of 100, the value of each being the number of entries for which bytes_sent is between that key and the next key.
Public Instance Methods
_key_for(val, bucket_width)
click to toggle source
Determines the key for the distribution hash given the value and step
# File lib/procedure_dsl.rb, line 163 def _key_for(val, bucket_width) (val.to_i / bucket_width) * bucket_width end
execute(bucket_width, &blk)
click to toggle source
# File lib/procedure_dsl.rb, line 142 def execute(bucket_width, &blk) dist = {} while @_current_entry = @_log_parser.next_entry val = instance_eval(&blk) k = _key_for(val, bucket_width) if dist.key?(k) dist[k] += 1 else dist[k] = 1 end end # Backfill keys for which we didn't find a value 0.step(dist.keys.max, bucket_width).each do |k| dist[k] = 0 unless dist.key?(k) end dist end