Sha256: 47a9cfdaf628bf5c8192ab850f8d2b908ad7fa982196893379055c4152ee7117

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'spout/helpers/array_statistics'
require 'spout/helpers/json_loader'

module Spout
  module Models
    class OutlierResult
      attr_reader :csv_files, :method, :major_outliers, :minor_outliers, :outliers, :weight, :units, :display_name, :median, :variable_type

      def initialize(subjects, method, csv_files)
        @values = subjects.collect(&method.to_sym)
        @csv_files = csv_files
        @method = method


        calculate_outliers!

        @weight = if @major_outliers.count > 0
          0
        elsif @minor_outliers.count > 0
          1
        else
          2
        end
        variable = Spout::Helpers::JsonLoader::get_variable(method)
        @units = (variable.is_a?(Hash) ? variable['units'] : nil)
        @display_name = (variable.is_a?(Hash) ? variable['display_name'] : nil)
        @variable_type = (variable.is_a?(Hash) ? variable['type'] : nil)
        @median = @values.median
      end

      def calculate_outliers!
        @major_outliers = @values.major_outliers.uniq
        @minor_outliers = @values.minor_outliers.uniq
        @outliers = @values.outliers.uniq
      end

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spout-0.12.1 lib/spout/models/outlier_result.rb
spout-0.12.0 lib/spout/models/outlier_result.rb
spout-0.12.0.rc2 lib/spout/models/outlier_result.rb
spout-0.12.0.rc lib/spout/models/outlier_result.rb
spout-0.12.0.beta2 lib/spout/models/outlier_result.rb
spout-0.12.0.beta1 lib/spout/models/outlier_result.rb
spout-0.11.1 lib/spout/models/outlier_result.rb