Class: SystemMetrics::Metric

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/system_metrics/metric.rb

Instance Method Summary collapse

Instance Method Details

#ancestorsObject



10
11
12
13
14
15
16
17
18
# File 'app/models/system_metrics/metric.rb', line 10

def ancestors
  ancestors = []
  metric = self
  while parent = metric.parent
    ancestors << parent
    metric = parent
  end
  ancestors
end

#child_of?(metric) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/system_metrics/metric.rb', line 33

def child_of?(metric)
  metric.parent_of?(self)
end

#parent_of?(metric) ⇒ Boolean

Returns if the current node is the parent of the given node. If this is a new record, we can use started_at values to detect parenting. However, if it was already saved, we lose microseconds information from timestamps and we must rely solely in id and parent_id information.

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'app/models/system_metrics/metric.rb', line 24

def parent_of?(metric)
  if new_record?
    start = (started_at - metric.started_at) * 1000.0
    start <= 0 && (start + duration >= metric.duration)
  else
    self.id == metric.parent_id
  end
end