Class: AMON::Measurement
- Inherits:
-
DocumentPart
- Object
- DocumentPart
- AMON::Measurement
- Defined in:
- lib/amon/measurement.rb
Overview
Instance Attribute Summary
Attributes inherited from DocumentPart
Attributes included from JSONHelper
Instance Method Summary collapse
-
#aggregated ⇒ Boolean
Is the measurement an aggregated (i.e. non-raw) value?.
- #aggregated_points ⇒ Object
-
#aggregation ⇒ Array
The “aggregation” array, including expectedPoints and aggregatedPoints.
- #aggregation_period ⇒ Object
-
#durational? ⇒ Boolean
The opposite of instantaneous?.
-
#end_date ⇒ Time
The measurement’s end date, if provided.
- #expected_points ⇒ Object
-
#instantaneous? ⇒ Boolean
A measurement is instantaneous if it is given with a single timestamp.
-
#mid_timestamp ⇒ Object
A single timestamp in the ‘middle’ of this measurement.
- #reading ⇒ Reading
-
#start_date ⇒ Time
The measurement’s start date, if provided.
-
#timestamp ⇒ Time
The measurement’s timestamp, if provided.
-
#type ⇒ String
(also: #name)
The measurement’s name.
-
#value ⇒ Numeric
The measurement’s value.
Methods inherited from DocumentPart
Constructor Details
This class inherits a constructor from AMON::DocumentPart
Instance Method Details
#aggregated ⇒ Boolean
Returns Is the measurement an aggregated (i.e. non-raw) value?.
26 |
# File 'lib/amon/measurement.rb', line 26 field :aggregated |
#aggregated_points ⇒ Object
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 |
#aggregation ⇒ Array
Returns The “aggregation” array, including expectedPoints and aggregatedPoints.
30 |
# File 'lib/amon/measurement.rb', line 30 field :aggregation |
#aggregation_period ⇒ Object
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?
43 44 45 |
# File 'lib/amon/measurement.rb', line 43 def durational? !instantaneous? end |
#end_date ⇒ Time
Returns The measurement’s end date, if provided.
20 |
# File 'lib/amon/measurement.rb', line 20 field :end_date, :name => 'endDate', :as => Time |
#expected_points ⇒ Object
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.
36 37 38 |
# File 'lib/amon/measurement.rb', line 36 def instantaneous? !.nil? end |
#mid_timestamp ⇒ Object
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 if instantaneous? else start_date + (end_date - start_date) / 2 end end |
#reading ⇒ Reading
49 50 51 |
# File 'lib/amon/measurement.rb', line 49 def reading device.readings_by_type[name] end |
#start_date ⇒ Time
Returns The measurement’s start date, if provided.
17 |
# File 'lib/amon/measurement.rb', line 17 field :start_date, :name => 'startDate', :as => Time |
#timestamp ⇒ Time
Returns The measurement’s timestamp, if provided.
14 |
# File 'lib/amon/measurement.rb', line 14 field :timestamp, :as => Time |
#type ⇒ String Also known as: name
Returns The measurement’s name.
7 |
# File 'lib/amon/measurement.rb', line 7 field :type |
#value ⇒ Numeric
Returns The measurement’s value.
11 |
# File 'lib/amon/measurement.rb', line 11 field :value |