Class: AMON::Device
Overview
An AMON device, containing any number of readings, and measurements for those readings.
Instance Attribute Summary
Attributes inherited from Document
Attributes included from JSONHelper
Instance Method Summary collapse
-
#completeness ⇒ Numeric
The all time completeness ratio (0 to 1) for the device.
-
#completeness_30d ⇒ Numeric
The 30 day completeness ratio (0 to 1) for the device.
-
#completeness_6m ⇒ Numeric
The 6 month completeness ratio (0 to 1) for the device.
-
#customer_ref ⇒ String
The metadata “customer_ref” field; convenience method.
-
#description ⇒ String
The description for the device.
-
#earliest_measurement ⇒ Time
The latest measurement start date, if provided.
-
#id ⇒ String
The id of the device.
-
#latest_measurement ⇒ Time
The latest measurement start date, if provided.
-
#location_name ⇒ String
The location for the device.
-
#measurements(entity_id, start_date, end_date, raw = false) ⇒ Array<Measurement>
Measurements for this device.
-
#measurements_by_name(entity_id, start_date, end_date, raw = false) ⇒ Hash<String => Measurement>
A hash allowing #measurements to be retrieved by their Measurement#name.
-
#metadata ⇒ Metadata
The metadata for the device.
-
#parent_uuid ⇒ String
The deviceId for the device’s parent device.
-
#readings ⇒ Array<Reading>
The readings for the device.
-
#readings_by_type ⇒ Hash<String => Reading>
A hash allowing #readings to be retrieved by their Reading#type.
-
#uuid ⇒ String
The deviceId for the device.
Methods inherited from Document
Constructor Details
This class inherits a constructor from AMON::Document
Instance Method Details
#completeness ⇒ Numeric
Returns 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_30d ⇒ Numeric
Returns 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_6m ⇒ Numeric
Returns 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_ref ⇒ String
Returns 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 |
#description ⇒ String
Returns The description for the device.
27 28 29 |
# File 'lib/amon/device.rb', line 27 def description @description ||= json['description'] end |
#earliest_measurement ⇒ Time
Returns The latest measurement start date, if provided.
11 |
# File 'lib/amon/device.rb', line 11 field :earliest_measurement, :name => 'earliestMeasurement', :as => Time |
#id ⇒ String
Returns The id of the device.
8 |
# File 'lib/amon/device.rb', line 8 field :id, :name => 'deviceId' |
#latest_measurement ⇒ Time
Returns The latest measurement start date, if provided.
14 |
# File 'lib/amon/device.rb', line 14 field :latest_measurement, :name => 'latestMeasurement', :as => Time |
#location_name ⇒ String
Returns 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.
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.
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 |
#metadata ⇒ Metadata
Returns The metadata for the device.
37 38 39 |
# File 'lib/amon/device.rb', line 37 def @metadata ||= Metadata.new(self, json['metadata']) end |
#parent_uuid ⇒ String
Returns 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 |
#readings ⇒ Array<Reading>
Returns 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_type ⇒ Hash<String => Reading>
Returns A hash allowing #readings to be retrieved by their Reading#type.
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 |
#uuid ⇒ String
Returns The deviceId for the device.
17 18 19 |
# File 'lib/amon/device.rb', line 17 def uuid @uuid ||= json['deviceId'] end |