Class: Ecoportal::API::Common::Client::Throughput::Stats
- Inherits:
-
Object
- Object
- Ecoportal::API::Common::Client::Throughput::Stats
- Defined in:
- lib/ecoportal/api/common/client/throughput/stats.rb
Constant Summary collapse
- DEFAULT_SD =
1.0- DUMMY_DIFF =
0.001
- CONFIDENCE =
{ _90: 1645, _95: 1.96, _98: 2.326, _99: 2.576, _995: 2.807 }.freeze
- DEFAULT_CONFI =
:_99
Instance Attribute Summary collapse
-
#average ⇒ Object
readonly
Returns the value of attribute average.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#default_margin_error ⇒ Object
readonly
Returns the value of attribute default_margin_error.
-
#standard_deviation ⇒ Object
readonly
Returns the value of attribute standard_deviation.
Instance Method Summary collapse
- #confidence_interval(value = default_margin_error) ⇒ Interval
- #empty? ⇒ Boolean
-
#initialize(average, margin: DEFAULT_CONFI) ⇒ Stats
constructor
A new instance of Stats.
- #max(value = default_margin_error) ⇒ Object
- #min(value = default_margin_error) ⇒ Object
- #record!(value) ⇒ Object (also: #<<)
Constructor Details
#initialize(average, margin: DEFAULT_CONFI) ⇒ Stats
Returns a new instance of Stats.
21 22 23 24 25 26 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 21 def initialize(average, margin: DEFAULT_CONFI) @average = average.to_f @standard_deviation = default_sd @count = 1 @default_margin_error = margin || DEFAULT_CONFI end |
Instance Attribute Details
#average ⇒ Object (readonly)
Returns the value of attribute average.
18 19 20 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 18 def average @average end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
18 19 20 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 18 def count @count end |
#default_margin_error ⇒ Object (readonly)
Returns the value of attribute default_margin_error.
19 20 21 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 19 def default_margin_error @default_margin_error end |
#standard_deviation ⇒ Object (readonly)
Returns the value of attribute standard_deviation.
18 19 20 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 18 def standard_deviation @standard_deviation end |
Instance Method Details
#confidence_interval(value = default_margin_error) ⇒ Interval
55 56 57 58 59 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 55 def confidence_interval(value = default_margin_error) me = margin_error(value) pair = [me * -1, me].map {|err| average + err} (pair.first..pair.last) end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 28 def empty? count <= 1 end |
#max(value = default_margin_error) ⇒ Object
32 33 34 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 32 def max(value = default_margin_error) confidence_interval(value).max end |
#min(value = default_margin_error) ⇒ Object
36 37 38 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 36 def min(value = default_margin_error) confidence_interval(value).min end |
#record!(value) ⇒ Object Also known as: <<
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ecoportal/api/common/client/throughput/stats.rb', line 40 def record!(value) if count == 1 @average = value else @average = ((average * count) + value) / (count + 1) end @standard_deviation = new_sd(value) @count += 1 average end |