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.
-
#error ⇒ String
The measurement’s error string, if present.
- #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
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 |
#aggregation ⇒ Array
Returns The “aggregation” array, including expectedPoints and aggregatedPoints.
30 |
# File 'lib/amon/measurement.rb', line 30 field :aggregation |
#aggregation_period ⇒ Object
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?
46 47 48 |
# File 'lib/amon/measurement.rb', line 46 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 |
#error ⇒ String
Returns The measurement’s error string, if present.
33 |
# File 'lib/amon/measurement.rb', line 33 field :error |
#expected_points ⇒ Object
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.
39 40 41 |
# File 'lib/amon/measurement.rb', line 39 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.
60 61 62 63 64 65 66 |
# File 'lib/amon/measurement.rb', line 60 def if instantaneous? else start_date + (end_date - start_date) / 2 end end |
#reading ⇒ Reading
52 53 54 |
# File 'lib/amon/measurement.rb', line 52 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 |