Class: FlatKit::StatType::OrdinalStats

Inherits:
NominalStats show all
Defined in:
lib/flat_kit/stat_type/ordinal_stats.rb

Overview

Internal: Same as NominalStats and also collects min and max

Instance Attribute Summary collapse

Attributes inherited from NominalStats

#count

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NominalStats

#collected_stats, #frequencies, #mode, #unique_count, #unique_values

Methods inherited from FlatKit::StatType

#collected_stats, for, nominal_types, numerical_types, ordinal_types, #to_hash, #to_json

Constructor Details

#initialize(collecting_frequencies: false) ⇒ OrdinalStats

Returns a new instance of OrdinalStats.



18
19
20
21
22
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 18

def initialize(collecting_frequencies: false)
  super
  @min = nil
  @max = nil
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



8
9
10
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 8

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



8
9
10
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 8

def min
  @min
end

Class Method Details

.all_statsObject



14
15
16
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 14

def self.all_stats
  @all_stats ||= %w[count max min unique_count unique_values mode]
end

.default_statsObject



10
11
12
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 10

def self.default_stats
  @default_stats ||= %w[count max min]
end

Instance Method Details

#update(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flat_kit/stat_type/ordinal_stats.rb', line 24

def update(value)
  @mutex.synchronize do
    @min = value if @min.nil? || (value < @min)

    @max = value if @max.nil? || (value > @max)

    @count += 1

    @frequencies[value] += 1 if @collecting_frequencies
  end
end