Class: QueueMetricTracker::StatCalculator
- Inherits:
-
Object
- Object
- QueueMetricTracker::StatCalculator
- Defined in:
- lib/worker_roulette/stat_calculator.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#granularity ⇒ Object
Returns the value of attribute granularity.
-
#sum ⇒ Object
Returns the value of attribute sum.
Instance Method Summary collapse
- #add(value) ⇒ Object
-
#initialize(granularity = 100) ⇒ StatCalculator
constructor
A new instance of StatCalculator.
Constructor Details
#initialize(granularity = 100) ⇒ StatCalculator
Returns a new instance of StatCalculator.
5 6 7 8 9 |
# File 'lib/worker_roulette/stat_calculator.rb', line 5 def initialize(granularity = 100) @granularity = granularity @sum = 0 @count = 0 end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'lib/worker_roulette/stat_calculator.rb', line 3 def count @count end |
#granularity ⇒ Object
Returns the value of attribute granularity.
3 4 5 |
# File 'lib/worker_roulette/stat_calculator.rb', line 3 def granularity @granularity end |
#sum ⇒ Object
Returns the value of attribute sum.
3 4 5 |
# File 'lib/worker_roulette/stat_calculator.rb', line 3 def sum @sum end |
Instance Method Details
#add(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/worker_roulette/stat_calculator.rb', line 11 def add(value) @sum += value @count += 1 if @count == granularity value = @sum / granularity @sum = @count = 0 return value end return nil end |