Class: SimpleMetric::DataSet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_points) ⇒ DataSet

Returns a new instance of DataSet.



63
64
65
# File 'lib/simple_metric.rb', line 63

def initialize(data_points)
  @data_points = data_points.sort_by { |point| point.x }
end

Instance Attribute Details

#data_pointsObject (readonly)

Returns the value of attribute data_points.



61
62
63
# File 'lib/simple_metric.rb', line 61

def data_points
  @data_points
end

Instance Method Details

#get_value(x) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/simple_metric.rb', line 67

def get_value(x)
  x = x.to_f
  value = @data_points.find { |point| point.x == x }.try(:y)

  if value.blank?
    points = [points_before(x, 2), points_after(x, 2)].flatten

    spliner = Spliner::Spliner.new(points.map(&:x), points.map(&:y))
    value = spliner[x]
  end

  value
end