amon 0.9.0 → 0.10.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/device.rb +55 -1
- data/lib/amon/entity.rb +56 -2
- data/lib/amon/session.rb +2 -1
- data/lib/amon/version.rb +1 -1
- 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.10.0 and is built to support AMON V3: https://github.com/AMEE/amon
|
7
7
|
|
8
8
|
## Installation ##
|
9
9
|
|
data/lib/amon/device.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module AMON
|
2
|
+
|
2
3
|
# An AMON device, containing any number of {Reading readings}, and
|
3
4
|
# {Measurement measurements} for those readings.
|
4
5
|
class Device < Document
|
6
|
+
|
5
7
|
# @return [String] The id of the device
|
6
8
|
field :id, :name => 'deviceId'
|
7
9
|
|
@@ -46,6 +48,21 @@ module AMON
|
|
46
48
|
@readings ||= json['readings'].map { |reading| Reading.new(self, reading) }
|
47
49
|
end
|
48
50
|
|
51
|
+
# @return [Numeric] The 30 day completeness ratio (0 to 1) for the device
|
52
|
+
def completeness_30d
|
53
|
+
@completeness_30d ||= get_completeness_30d
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Numeric] The 6 month completeness ratio (0 to 1) for the device
|
57
|
+
def completeness_6m
|
58
|
+
@completeness_6m ||= get_completeness_6m
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Numeric] The all time completeness ratio (0 to 1) for the device
|
62
|
+
def completeness
|
63
|
+
@completeness ||= get_completeness
|
64
|
+
end
|
65
|
+
|
49
66
|
# @return [Hash<String => Reading>] A hash allowing {Device#readings} to
|
50
67
|
# be retrieved by their {Reading#type}
|
51
68
|
def readings_by_type
|
@@ -73,5 +90,42 @@ module AMON
|
|
73
90
|
measurements_by_name
|
74
91
|
end
|
75
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def get_completeness_30d
|
97
|
+
unless json['completenessRatios'].nil?
|
98
|
+
json['completenessRatios'].each do |completeness_info|
|
99
|
+
if completeness_info['period'] == 'thirty_days'
|
100
|
+
return completeness_info['ratio']
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
return 0
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_completeness_6m
|
108
|
+
unless json['completenessRatios'].nil?
|
109
|
+
json['completenessRatios'].each do |completeness_info|
|
110
|
+
if completeness_info['period'] == 'six_months'
|
111
|
+
return completeness_info['ratio']
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return 0
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_completeness
|
119
|
+
unless json['completenessRatios'].nil?
|
120
|
+
json['completenessRatios'].each do |completeness_info|
|
121
|
+
if completeness_info['period'] == 'full_history'
|
122
|
+
return completeness_info['ratio']
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
return 0
|
127
|
+
end
|
128
|
+
|
76
129
|
end
|
77
|
-
|
130
|
+
|
131
|
+
end
|
data/lib/amon/entity.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module AMON
|
2
|
+
|
2
3
|
# An AMON entity, such as a house, business park, or building floor
|
3
4
|
class Entity < Document
|
5
|
+
|
4
6
|
# @return [String] The id for this entity
|
5
7
|
field :id, :name => 'entityId'
|
6
8
|
|
@@ -16,9 +18,61 @@ module AMON
|
|
16
18
|
@devices ||= device_ids.map { |device_id| session.device(id, device_id) }
|
17
19
|
end
|
18
20
|
|
19
|
-
# @return [Array<MeteringPoint>] The metering points associated with
|
21
|
+
# @return [Array<MeteringPoint>] The metering points associated with the entity
|
20
22
|
def metering_points
|
21
23
|
@metering_points ||= metering_point_ids.map { |id| session.metering_point(id) }
|
22
24
|
end
|
25
|
+
|
26
|
+
# @return [Numeric] The 30 day completeness ratio (0 to 1) for the entity
|
27
|
+
def completeness_30d
|
28
|
+
@completeness_30d ||= get_completeness_30d
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Numeric] The 6 month completeness ratio (0 to 1) for the entity
|
32
|
+
def completeness_6m
|
33
|
+
@completeness_6m ||= get_completeness_6m
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Numeric] The all time completeness ratio (0 to 1) for the entity
|
37
|
+
def completeness
|
38
|
+
@completeness ||= get_completeness
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_completeness_30d
|
44
|
+
unless json['completenessRatios'].nil?
|
45
|
+
json['completenessRatios'].each do |completeness_info|
|
46
|
+
if completeness_info['period'] == 'thirty_days'
|
47
|
+
return completeness_info['ratio']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
return 0
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_completeness_6m
|
55
|
+
unless json['completenessRatios'].nil?
|
56
|
+
json['completenessRatios'].each do |completeness_info|
|
57
|
+
if completeness_info['period'] == 'six_months'
|
58
|
+
return completeness_info['ratio']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
return 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_completeness
|
66
|
+
unless json['completenessRatios'].nil?
|
67
|
+
json['completenessRatios'].each do |completeness_info|
|
68
|
+
if completeness_info['period'] == 'full_history'
|
69
|
+
return completeness_info['ratio']
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
return 0
|
74
|
+
end
|
75
|
+
|
23
76
|
end
|
24
|
-
|
77
|
+
|
78
|
+
end
|
data/lib/amon/session.rb
CHANGED
data/lib/amon/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 10
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.10.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- AMEE
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-11-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|