amon 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/amon/measurement.rb +34 -3
- data/lib/amon/session.rb +3 -1
- data/lib/amon/version.rb +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Ruby Client for the AMEE AMON API
|
|
3
3
|
|
4
4
|
This is a Ruby client library for the [AMEE](http://www.amee.com/) <abbr title="AMEE Monitoring Object Notation">AMON</abbr> <abbr title="Application Programming Interface">API</abbr>. _More details and links to be inserted once information about the API is publicly available_.
|
5
5
|
|
6
|
-
This is version 0.
|
6
|
+
This is version 0.5.0 and is built to support AMON V3: https://github.com/AMEE/amon
|
7
7
|
|
8
8
|
## Installation ##
|
9
9
|
|
data/lib/amon/measurement.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module AMON
|
2
|
+
|
2
3
|
# A measurement corresponding to a {Reading} of a {Device}
|
3
4
|
class Measurement < DocumentPart
|
5
|
+
|
4
6
|
# @return [String] The measurement's name
|
5
7
|
field :type
|
6
8
|
alias :name :type
|
@@ -9,17 +11,24 @@ module AMON
|
|
9
11
|
field :value
|
10
12
|
|
11
13
|
# @return [Time] The measurement's timestamp, if provided
|
12
|
-
field :timestamp,
|
14
|
+
field :timestamp, :as => Time
|
13
15
|
|
14
16
|
# @return [Time] The measurement's start date, if provided
|
15
17
|
field :start_date, :name => 'startDate', :as => Time
|
16
18
|
|
17
19
|
# @return [Time] The measurement's end date, if provided
|
18
|
-
field :end_date,
|
20
|
+
field :end_date, :name => 'endDate', :as => Time
|
19
21
|
|
20
22
|
# @attr_reader [Device] device The device which took this measurement
|
21
23
|
alias_method :device, :parent
|
22
24
|
|
25
|
+
# @return [Boolean] Is the measurement an aggregated (i.e. non-raw) value?
|
26
|
+
field :aggregated
|
27
|
+
|
28
|
+
# @return [Array] The "aggregation" array, including expectedPoints and
|
29
|
+
# aggregatedPoints.
|
30
|
+
field :aggregation
|
31
|
+
|
23
32
|
# A measurement is instantaneous if it is given with a single timestamp. If, on the other hand,
|
24
33
|
# start and end dates are provided, it is durational.
|
25
34
|
# @return [Boolean]
|
@@ -52,5 +61,27 @@ module AMON
|
|
52
61
|
start_date + (end_date - start_date) / 2
|
53
62
|
end
|
54
63
|
end
|
64
|
+
|
65
|
+
def aggregated_points
|
66
|
+
if aggregated
|
67
|
+
if aggregation.nil?
|
68
|
+
0
|
69
|
+
else
|
70
|
+
aggregation['aggregatedPoints']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def expected_points
|
76
|
+
if aggregated
|
77
|
+
if aggregation.nil?
|
78
|
+
0
|
79
|
+
else
|
80
|
+
aggregation['expectedPoints']
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
55
85
|
end
|
56
|
-
|
86
|
+
|
87
|
+
end
|
data/lib/amon/session.rb
CHANGED
@@ -84,7 +84,9 @@ module AMON
|
|
84
84
|
cache(:measurements, [device_id, start_date, end_date, raw]) do
|
85
85
|
device = device(entity_id, device_id)
|
86
86
|
measurements = get(
|
87
|
-
"/entities/#{ URI.escape(entity_id) }/devices/#{ URI.escape(device.id) }/measurements
|
87
|
+
"/entities/#{ URI.escape(entity_id) }/devices/#{ URI.escape(device.id) }/measurements" +
|
88
|
+
";aggregation" +
|
89
|
+
"?" +
|
88
90
|
"raw=" + raw.to_s + "&" +
|
89
91
|
"startDate=" + start_date.utc.xmlschema + "&" +
|
90
92
|
"endDate=" + end_date.utc.xmlschema
|
data/lib/amon/version.rb
CHANGED
metadata
CHANGED