Class: Spout::Models::OutlierResult

Inherits:
Object
  • Object
show all
Defined in:
lib/spout/models/outlier_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subjects, method, csv_files) ⇒ OutlierResult

Returns a new instance of OutlierResult.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spout/models/outlier_result.rb', line 13

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

Instance Attribute Details

#csv_filesObject (readonly)

Returns the value of attribute csv_files.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def csv_files
  @csv_files
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def display_name
  @display_name
end

#major_outliersObject (readonly)

Returns the value of attribute major_outliers.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def major_outliers
  @major_outliers
end

#medianObject (readonly)

Returns the value of attribute median.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def median
  @median
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def method
  @method
end

#minor_outliersObject (readonly)

Returns the value of attribute minor_outliers.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def minor_outliers
  @minor_outliers
end

#outliersObject (readonly)

Returns the value of attribute outliers.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def outliers
  @outliers
end

#unitsObject (readonly)

Returns the value of attribute units.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def units
  @units
end

#variable_typeObject (readonly)

Returns the value of attribute variable_type.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def variable_type
  @variable_type
end

#weightObject (readonly)

Returns the value of attribute weight.



9
10
11
# File 'lib/spout/models/outlier_result.rb', line 9

def weight
  @weight
end

Instance Method Details

#calculate_outliers!Object



33
34
35
36
37
# File 'lib/spout/models/outlier_result.rb', line 33

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