Class: PulseMeter::Visualize::Sensor

Inherits:
Base
  • Object
show all
Defined in:
lib/pulse-meter/visualize/sensor.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #method_missing

Constructor Details

This class inherits a constructor from PulseMeter::Visualize::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PulseMeter::Visualize::Base

Instance Method Details

#annotationObject



33
34
35
# File 'lib/pulse-meter/visualize/sensor.rb', line 33

def annotation
  real_sensor.annotation || real_sensor.name
end

#extractorObject



49
50
51
# File 'lib/pulse-meter/visualize/sensor.rb', line 49

def extractor
  PulseMeter::Visualize.extractor(self)
end

#intervalObject



41
42
43
# File 'lib/pulse-meter/visualize/sensor.rb', line 41

def interval
  real_sensor.interval
end

#last_point_data(now, need_incomplete = false) ⇒ Object



22
23
24
# File 'lib/pulse-meter/visualize/sensor.rb', line 22

def last_point_data(now, need_incomplete=false)
  extractor.point_data(last_value(now, need_incomplete))
end

#last_value(now, need_incomplete = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pulse-meter/visualize/sensor.rb', line 6

def last_value(now, need_incomplete=false)
  sensor = real_sensor

  sensor_data = if need_incomplete
    sensor.timeline_within(now - sensor.interval, now).first
  else
    sensor.timeline_within(now - sensor.interval * 2, now).first
  end

  if sensor_data.is_a?(PulseMeter::SensorData)
    sensor_data.value
  else
    nil
  end
end

#timeline_data(now, time_span, need_incomplete = false) ⇒ Object



26
27
28
29
30
31
# File 'lib/pulse-meter/visualize/sensor.rb', line 26

def timeline_data(now, time_span, need_incomplete = false)
  sensor = real_sensor
  timeline_data = sensor.timeline_within(now - time_span, now)
  timeline_data.pop unless need_incomplete
  extractor.series_data(timeline_data)
end

#typeObject



37
38
39
# File 'lib/pulse-meter/visualize/sensor.rb', line 37

def type
  real_sensor.class
end

#valueObject



45
46
47
# File 'lib/pulse-meter/visualize/sensor.rb', line 45

def value
  real_sensor.value
end