Class: FlexStationData::Presenters::SampleRegressionHash

Inherits:
Object
  • Object
show all
Includes:
Callable[:present]
Defined in:
lib/flex_station_data/presenters/sample_regression_hash.rb

Constant Summary collapse

PRODUCTS =
{
  slope:     "slope",
  intercept: "intercept",
  r_squared: "",
  quality:   "quality"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(times, *sample_values, min_r_squared: nil, **options) ⇒ SampleRegressionHash

Returns a new instance of SampleRegressionHash.



20
21
22
23
24
25
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 20

def initialize(times, *sample_values, min_r_squared: nil, **options)
  @times = times
  @sample_values = sample_values
  @min_r_squared = min_r_squared
  @options = options
end

Instance Attribute Details

#min_r_squaredObject (readonly)

Returns the value of attribute min_r_squared.



18
19
20
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 18

def min_r_squared
  @min_r_squared
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 18

def options
  @options
end

#sample_valuesObject (readonly)

Returns the value of attribute sample_values.



18
19
20
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 18

def sample_values
  @sample_values
end

#timesObject (readonly)

Returns the value of attribute times.



18
19
20
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 18

def times
  @times
end

Class Method Details

.headersObject



39
40
41
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 39

def self.headers
  PRODUCTS.values
end

Instance Method Details

#presentObject



33
34
35
36
37
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 33

def present
  PRODUCTS.each_with_object({}) do |(method, label), memo|
    memo[label] = sample_regressions.map(&method)
  end
end

#sample_regressionsObject



27
28
29
30
31
# File 'lib/flex_station_data/presenters/sample_regression_hash.rb', line 27

def sample_regressions
  @sample_regressions ||= sample_values.map do |values|
    FlexStationData::LinearRegression.new(times, values, min_r_squared: min_r_squared)
  end
end