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



76
77
78
79
80
81
82
83
84
# File 'lib/amon/measurement.rb', line 76

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



68
69
70
71
72
73
74
# File 'lib/amon/measurement.rb', line 68

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

#durational?Boolean

The opposite of instantaneous?

Returns:

  • (Boolean)

See Also:



46
47
48
# File 'lib/amon/measurement.rb', line 46

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

#errorString

Returns The measurement’s error string, if present.

Returns:

  • (String)

    The measurement’s error string, if present



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

field :error

#expected_pointsObject



86
87
88
89
90
91
92
93
94
# File 'lib/amon/measurement.rb', line 86

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:



39
40
41
# File 'lib/amon/measurement.rb', line 39

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.



60
61
62
63
64
65
66
# File 'lib/amon/measurement.rb', line 60

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:



52
53
54
# File 'lib/amon/measurement.rb', line 52

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