Class: Graphite::Tools::Regression
- Inherits:
-
Object
- Object
- Graphite::Tools::Regression
- Defined in:
- lib/graphite/tools/regression.rb
Overview
Regression analysis of graphite data
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #datapoints ⇒ Object
- #forecast(*args) ⇒ Object
-
#initialize(data) ⇒ Regression
constructor
A new instance of Regression.
- #linefit ⇒ Object
- #x_intercept(y_val = 0) ⇒ Object
Constructor Details
#initialize(data) ⇒ Regression
Returns a new instance of Regression.
9 10 11 |
# File 'lib/graphite/tools/regression.rb', line 9 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/graphite/tools/regression.rb', line 7 def data @data end |
Instance Method Details
#datapoints ⇒ Object
13 14 15 16 17 |
# File 'lib/graphite/tools/regression.rb', line 13 def datapoints d = @data['datapoints'].map { |(v, t)| [t, v] } .reject { |_k, v| v.nil? } Hash[*d.flatten] end |
#forecast(*args) ⇒ Object
27 28 29 |
# File 'lib/graphite/tools/regression.rb', line 27 def forecast(*args) linefit.forecast(*args) end |
#linefit ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/graphite/tools/regression.rb', line 19 def linefit @linefit ||= begin f = LineFit.new f.setData(datapoints.keys, datapoints.values) f end end |
#x_intercept(y_val = 0) ⇒ Object
31 32 33 34 |
# File 'lib/graphite/tools/regression.rb', line 31 def x_intercept(y_val = 0) intercept, slope = linefit.coefficients Time.at((y_val - intercept) / slope) if slope && slope < 0 end |