Class: SimpleStatistics::DataSet::DataFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_statistics/data_set.rb

Defined Under Namespace

Classes: DataFinderError

Instance Method Summary collapse

Constructor Details

#initialize(probe, data_set) ⇒ DataFinder

Returns a new instance of DataFinder.



6
7
8
9
# File 'lib/simple_statistics/data_set.rb', line 6

def initialize(probe, data_set)
  @probe = probe.to_sym
  @data_set = data_set
end

Instance Method Details

#find(&block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/simple_statistics/data_set.rb', line 34

def find(&block)
  @data_set.datas.each do |key, value|
    p = value[@probe]
    p = if @probes_count 
      p.last_probes_by_count(@probes_count)
    elsif @probes_time
      p.last_probes_by_time(@probes_time)
    else
      raise DataFinderError, "Sample is not defined. Use :last_probes_by_count or :last_probes_by_time"
    end
    if AGGREGATE_FUNCTIONS.include?(@aggregate.to_sym)
      p = p.send(@aggregate)
    else
      raise DataFinderError, "Aggregate function is not define. User one of :mean, :count, :sum"
    end
    if @is_higher_then
      if p > @is_higher_then 
        block.call(key)
      end
    else
      raise DataFinderError, "Condition is not defined. Use :is_higher_then"
    end
  end
end

#is_higher_then(value, &block) ⇒ Object



11
12
13
14
15
# File 'lib/simple_statistics/data_set.rb', line 11

def is_higher_then(value, &block)
  @is_higher_then = value
  find(&block)
  self
end

#last_probes_by_count(count) ⇒ Object



24
25
26
27
# File 'lib/simple_statistics/data_set.rb', line 24

def last_probes_by_count(count)
  @probes_count = count
  self
end

#last_probes_by_time(time) ⇒ Object



29
30
31
32
# File 'lib/simple_statistics/data_set.rb', line 29

def last_probes_by_time(time)
  @probes_time = time
  self
end