Class: AMON::Measurement

Inherits:
DocumentPart show all
Defined in:
lib/amon/measurement.rb

Overview

A measurement corresponding to a Reading of a Device

Instance Attribute Summary

Attributes inherited from DocumentPart

#parent

Attributes included from JSONHelper

#json

Instance Method Summary collapse

Methods inherited from DocumentPart

#initialize

Constructor Details

This class inherits a constructor from AMON::DocumentPart

Instance Method Details

#aggregatedBoolean

Returns Is the measurement an aggregated (i.e. non-raw) value?.

Returns:

  • (Boolean)

    Is the measurement an aggregated (i.e. non-raw) value?



26
# File 'lib/amon/measurement.rb', line 26

field :aggregated

#aggregated_pointsObject



73
74
75
76
77
78
79
80
81
# File 'lib/amon/measurement.rb', line 73

def aggregated_points
  if aggregated
    if aggregation.nil?
      0
    else
      aggregation['aggregatedPoints']
    end
  end
end

#aggregationArray

Returns The “aggregation” array, including expectedPoints and aggregatedPoints.

Returns:

  • (Array)

    The “aggregation” array, including expectedPoints and aggregatedPoints.



30
# File 'lib/amon/measurement.rb', line 30

field :aggregation

#aggregation_periodObject



65
66
67
68
69
70
71
# File 'lib/amon/measurement.rb', line 65

def aggregation_period
  if aggregated
    unless aggregation.nil?
      aggregation['period']
    end
  end
end

#durational?Boolean

The opposite of instantaneous?

Returns:

  • (Boolean)

See Also:



43
44
45
# File 'lib/amon/measurement.rb', line 43

def durational?
  !instantaneous?
end

#end_dateTime

Returns The measurement’s end date, if provided.

Returns:

  • (Time)

    The measurement’s end date, if provided



20
# File 'lib/amon/measurement.rb', line 20

field :end_date, :name => 'endDate', :as => Time

#expected_pointsObject



83
84
85
86
87
88
89
90
91
# File 'lib/amon/measurement.rb', line 83

def expected_points
  if aggregated
    if aggregation.nil?
      0
    else
      aggregation['expectedPoints']
    end
  end
end

#instantaneous?Boolean

A measurement is instantaneous if it is given with a single timestamp. If, on the other hand, start and end dates are provided, it is durational.

Returns:

  • (Boolean)

See Also:



36
37
38
# File 'lib/amon/measurement.rb', line 36

def instantaneous?
  !timestamp.nil?
end

#mid_timestampObject

A single timestamp in the ‘middle’ of this measurement. If the measurement is instantaneous, then the mid timestamp is identical to the timestamp. However, if it is durational then the mid timestamp is the halfway point between the #start_date and the #end_date.



57
58
59
60
61
62
63
# File 'lib/amon/measurement.rb', line 57

def mid_timestamp
  if instantaneous?
    timestamp
  else
    start_date + (end_date - start_date) / 2
  end
end

#readingReading

The device reading associated with this measurement.

Returns:



49
50
51
# File 'lib/amon/measurement.rb', line 49

def reading
  device.readings_by_type[name]
end

#start_dateTime

Returns The measurement’s start date, if provided.

Returns:

  • (Time)

    The measurement’s start date, if provided



17
# File 'lib/amon/measurement.rb', line 17

field :start_date, :name => 'startDate', :as => Time

#timestampTime

Returns The measurement’s timestamp, if provided.

Returns:

  • (Time)

    The measurement’s timestamp, if provided



14
# File 'lib/amon/measurement.rb', line 14

field :timestamp, :as => Time

#typeString Also known as: name

Returns The measurement’s name.

Returns:

  • (String)

    The measurement’s name



7
# File 'lib/amon/measurement.rb', line 7

field :type

#valueNumeric

Returns The measurement’s value.

Returns:

  • (Numeric)

    The measurement’s value



11
# File 'lib/amon/measurement.rb', line 11

field :value