Class: ApacheCrunch::LogDistribution
- Inherits:
-
ProcedureRoutine
- Object
- ProcedureRoutine
- ApacheCrunch::LogDistribution
- Defined in:
- lib/procedure_dsl.rb
Overview
Same as Distribution, but the buckets get expenentially wider
Instance Method Summary collapse
-
#_key_for(val, width_base) ⇒ Object
Determines the key for the distribution hash given the value and logarithmic base for the bucket width.
- #execute(width_base, &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, width_base) ⇒ Object
Determines the key for the distribution hash given the value and logarithmic base for the bucket width
195 196 197 198 |
# File 'lib/procedure_dsl.rb', line 195 def _key_for(val, width_base) exp = (Math.log(val) / Math.log(width_base)).to_i width_base ** exp end |
#execute(width_base, &blk) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/procedure_dsl.rb', line 171 def execute(width_base, &blk) dist = {} while @_current_entry = @_log_parser.next_entry val = instance_eval(&blk) k = _key_for(val, width_base) if dist.key?(k) dist[k] += 1 else dist[k] = 1 end end # Backfill keys for which we didn't find a value k = dist.keys.min max_key = dist.keys.max while k *= width_base and k < max_key dist[k] = 0 unless dist.key?(k) end dist end |