Class: ApacheCrunch::Distribution
- Inherits:
-
ProcedureRoutine
- Object
- ProcedureRoutine
- ApacheCrunch::Distribution
- Defined in:
- lib/procedure_dsl.rb
Overview
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.
Instance Method Summary collapse
-
#_key_for(val, bucket_width) ⇒ Object
Determines the key for the distribution hash given the value and step.
- #execute(bucket_width, &blk) ⇒ Object
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
#_key_for(val, bucket_width) ⇒ Object
Determines the key for the distribution hash given the value and step
163 164 165 |
# 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) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# 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 |