Sha256: 78c15737542d21948e083fb52b3bd569aa563b1f6b9ff152034107859e1df1ec

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require "flex_station_data/concerns/presenter"
require "flex_station_data/linear_regression"

module FlexStationData
  module Presenters
    class SampleRegressionHash
      include Concerns::Presenter

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

      attr_reader :times, :sample_values, :min_r_squared, :options

      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

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

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

      def self.headers
        PRODUCTS.values
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flex-station-data-1.0.1 lib/flex_station_data/presenters/sample_regression_hash.rb
flex-station-data-1.0.0 lib/flex_station_data/presenters/sample_regression_hash.rb