Class: AMON::Device

Inherits:
Document show all
Defined in:
lib/amon/device.rb

Overview

An AMON device, containing any number of readings, and measurements for those readings.

Instance Attribute Summary

Attributes inherited from Document

#session

Attributes included from JSONHelper

#json

Instance Method Summary collapse

Methods inherited from Document

#==, #initialize

Constructor Details

This class inherits a constructor from AMON::Document

Instance Method Details

#completenessNumeric

Returns The all time completeness ratio (0 to 1) for the device.

Returns:

  • (Numeric)

    The all time completeness ratio (0 to 1) for the device



62
63
64
# File 'lib/amon/device.rb', line 62

def completeness
  @completeness ||= get_completeness
end

#completeness_30dNumeric

Returns The 30 day completeness ratio (0 to 1) for the device.

Returns:

  • (Numeric)

    The 30 day completeness ratio (0 to 1) for the device



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

def completeness_30d
  @completeness_30d ||= get_completeness_30d
end

#completeness_6mNumeric

Returns The 6 month completeness ratio (0 to 1) for the device.

Returns:

  • (Numeric)

    The 6 month completeness ratio (0 to 1) for the device



57
58
59
# File 'lib/amon/device.rb', line 57

def completeness_6m
  @completeness_6m ||= get_completeness_6m
end

#customer_refString

Returns The metadata “customer_ref” field; convenience method.

Returns:

  • (String)

    The metadata “customer_ref” field; convenience method



42
43
44
# File 'lib/amon/device.rb', line 42

def customer_ref
  @customer_ref ||= .customer_ref
end

#descriptionString

Returns The description for the device.

Returns:

  • (String)

    The description for the device



27
28
29
# File 'lib/amon/device.rb', line 27

def description
  @description ||= json['description']
end

#earliest_measurementTime

Returns The latest measurement start date, if provided.

Returns:

  • (Time)

    The latest measurement start date, if provided



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

field :earliest_measurement, :name => 'earliestMeasurement', :as => Time

#idString

Returns The id of the device.

Returns:

  • (String)

    The id of the device



8
# File 'lib/amon/device.rb', line 8

field :id, :name => 'deviceId'

#latest_measurementTime

Returns The latest measurement start date, if provided.

Returns:

  • (Time)

    The latest measurement start date, if provided



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

field :latest_measurement, :name => 'latestMeasurement', :as => Time

#location_nameString

Returns The location for the device.

Returns:

  • (String)

    The location for the device



32
33
34
# File 'lib/amon/device.rb', line 32

def location_name
  @location_name ||= json['location']['name']
end

#measurements(entity_id, start_date, end_date, raw = false) ⇒ Array<Measurement>

Returns Measurements for this device.

Returns:

  • (Array<Measurement>)

    Measurements for this device

See Also:



77
78
79
# File 'lib/amon/device.rb', line 77

def measurements(entity_id, start_date, end_date, raw = false)
  session.measurements(entity_id, id, start_date, end_date, raw)
end

#measurements_by_name(entity_id, start_date, end_date, raw = false) ⇒ Hash<String => Measurement>

Returns A hash allowing #measurements to be retrieved by their Measurement#name.

Returns:

See Also:



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

def measurements_by_name(entity_id, start_date, end_date, raw = false)
  measurements(entity_id, start_date, end_date, raw).inject({}) do |measurements_by_name, measurement|
    measurements_by_name[measurement.name] ||= []
    measurements_by_name[measurement.name] << measurement
    measurements_by_name
  end
end

#metadataMetadata

Returns The metadata for the device.

Returns:

  • (Metadata)

    The metadata for the device



37
38
39
# File 'lib/amon/device.rb', line 37

def 
  @metadata ||= Metadata.new(self, json['metadata'])
end

#parent_uuidString

Returns The deviceId for the device’s parent device.

Returns:

  • (String)

    The deviceId for the device’s parent device



22
23
24
# File 'lib/amon/device.rb', line 22

def parent_uuid
  @parent_uuid ||= json['parentId']
end

#readingsArray<Reading>

Returns The readings for the device.

Returns:

  • (Array<Reading>)

    The readings for the device



47
48
49
# File 'lib/amon/device.rb', line 47

def readings
  @readings ||= json['readings'].map { |reading| Reading.new(self, reading) }
end

#readings_by_typeHash<String => Reading>

Returns A hash allowing #readings to be retrieved by their Reading#type.

Returns:



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

def readings_by_type
  readings.inject({}) do |readings_by_type, reading|
    readings_by_type[reading.type] = reading
    readings_by_type
  end
end

#uuidString

Returns The deviceId for the device.

Returns:

  • (String)

    The deviceId for the device



17
18
19
# File 'lib/amon/device.rb', line 17

def uuid
  @uuid ||= json['deviceId']
end