Class: SISFC::Statistics
- Inherits:
-
Object
- Object
- SISFC::Statistics
- Defined in:
- lib/sisfc/statistics.rb
Instance Attribute Summary collapse
-
#longer_than ⇒ Object
readonly
Returns the value of attribute longer_than.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#n ⇒ Object
(also: #closed)
readonly
Returns the value of attribute n.
-
#received ⇒ Object
readonly
Returns the value of attribute received.
Instance Method Summary collapse
- #initialize(opts = {}) ⇒ Statistics constructor
- #record_request(req) ⇒ Object
- #request_received ⇒ Object
- #to_s ⇒ Object
- #variance ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Statistics
13 14 15 16 17 18 19 |
# File 'lib/sisfc/statistics.rb', line 13 def initialize(opts={}) @n = 0 # number of requests @mean = 0.0 @m_2 = 0.0 @longer_than = init_counters_for_longer_than_stats(opts) @received = 0 end |
Instance Attribute Details
#longer_than ⇒ Object (readonly)
Returns the value of attribute longer_than.
8 9 10 |
# File 'lib/sisfc/statistics.rb', line 8 def longer_than @longer_than end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
8 9 10 |
# File 'lib/sisfc/statistics.rb', line 8 def mean @mean end |
#n ⇒ Object (readonly) Also known as: closed
Returns the value of attribute n.
8 9 10 |
# File 'lib/sisfc/statistics.rb', line 8 def n @n end |
#received ⇒ Object (readonly)
Returns the value of attribute received.
8 9 10 |
# File 'lib/sisfc/statistics.rb', line 8 def received @received end |
Instance Method Details
#record_request(req) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sisfc/statistics.rb', line 25 def record_request(req) # get new sample x = req.ttr raise "TTR #{x} for request #{req.rid} invalid!" unless x > 0.0 @longer_than.each_key do |k| @longer_than[k] += 1 if x > k end # update counters @n += 1 delta = x - @mean @mean += delta / @n @m_2 += delta * (x - @mean) end |
#request_received ⇒ Object
21 22 23 |
# File 'lib/sisfc/statistics.rb', line 21 def request_received @received += 1 end |
#to_s ⇒ Object
45 46 47 48 |
# File 'lib/sisfc/statistics.rb', line 45 def to_s "received: #{@received}, closed: #{@n}, " + "(mean: #{@mean}, variance: #{variance}, longer_than: #{@longer_than.to_s})" end |
#variance ⇒ Object
41 42 43 |
# File 'lib/sisfc/statistics.rb', line 41 def variance @m_2 / (@n - 1) end |