helium-ruby 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -3
- data/helium-ruby.gemspec +1 -0
- data/lib/helium/client/http.rb +2 -1
- data/lib/helium/client/sensors.rb +6 -4
- data/lib/helium/data_point.rb +16 -0
- data/lib/helium/sensor.rb +4 -2
- data/lib/helium/timeseries.rb +10 -2
- data/lib/helium/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f6ff6d87571b6da6c446b1c0496ffa9dc47c68d
|
4
|
+
data.tar.gz: ef1feadb0d457c031d319592ff2e48b037da9938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e9dafbc98ae651fff679e89676048af1780a9a507f38305e2034955c623e58dcfe25a2af6c2cda41ab22e67934bc67278b96b5bd8ae1b3e932fb1d9f52bb93f
|
7
|
+
data.tar.gz: 56ba562ce5e1893c5faef95a8054b0464867309244bb2d71dcbbf2078a03120f0ebae5dc1f4b128d4a6ff9decc10ffb4365afd4d44fd4868ea43e68d94914e40
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/helium/helium-ruby)
|
4
4
|
[](https://coveralls.io/github/helium/helium-ruby?branch=master)
|
5
5
|
[](https://codeclimate.com/github/helium/helium-ruby)
|
6
|
+
[](https://badge.fury.io/rb/helium-ruby)
|
6
7
|
|
7
8
|
A Ruby gem for building applications with the Helium API. [Helium](https://www.helium.com/) is an integrated platform of smart sensors, communication, edge and cloud compute that enables numerous sensing applications. For more information about the underlying REST API, check out [the Helium docs](https://docs.helium.com/).
|
8
9
|
|
@@ -130,14 +131,17 @@ sensor.timeseries(size: 10_000).length
|
|
130
131
|
# => 10000
|
131
132
|
```
|
132
133
|
|
133
|
-
The data points are sorted from most recent, to least recent. The `.previous` method on a `Helium::Timeseries` object will return a new `Helium::Timeseries` object with the
|
134
|
+
The data points are sorted from most recent, to least recent. The `.previous` method on a `Helium::Timeseries` object will return a new `Helium::Timeseries` object with the previous page of Timeseries data. Similarly, the `.next` method on a `Helium::Timeseries` object will return the next page of timeseries data, if it exists. If not, it will return `false`.
|
134
135
|
|
135
136
|
```ruby
|
136
137
|
timeseries = sensor.timeseries
|
137
138
|
# => #<Helium::Timeseries:0x007ff9e10d2c48 @data_points=[#<Helium::DataPoint:0x007ff9e10d2568 @id="3595e562-c065-442e-a3af-c6f43ddb1500", @timestamp="2016-08-10T13:21:49.866Z", @value=27, @port="l">, ...
|
138
139
|
|
139
|
-
timeseries.previous
|
140
|
+
previous_timeseries = timeseries.previous
|
140
141
|
# => #<Helium::Timeseries:0x007ff9dc141008 @data_points=[#<Helium::DataPoint:0x007ff9dc140f68 @id="1e4062cf-361d-415e-8c05-cd04954424d1", @timestamp="2016-08-10T13:11:49.353Z", @value=99804.15, @port="p">, ...
|
142
|
+
|
143
|
+
previous_timeseries.next
|
144
|
+
# =>
|
141
145
|
```
|
142
146
|
|
143
147
|
If no previous data exists, the `.previous` method will return `false`.
|
@@ -147,6 +151,27 @@ sensor.timeseries.previous
|
|
147
151
|
# => false
|
148
152
|
```
|
149
153
|
|
154
|
+
#### Timeseries Aggregations
|
155
|
+
|
156
|
+
In addition to returning the raw data points, Helium can return timeseries data aggregated into buckets.
|
157
|
+
|
158
|
+
|
159
|
+
For example, if you wanted to display a graph of a sensor's temperature min, max and average readings grouped by day, you could do the following:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
data_points = sensor.timeseries(port: 't', aggtype: 'min,max,avg', aggsize: '1d')
|
163
|
+
# => #<Helium::Timeseries:0x007fe7038c2d18 @data_points=[#<Helium::DataPoint:0x007fe7038c2c00 @client=<Helium::Client @debug=true>, @id="a93e47f4-2fb2-4336-84c0-20f83ee2988e", @timestamp="2016-08-16T00:00:00Z", @value={"max"=>22.579952, "avg"=>22.1155383392857, "min"=>21.774511}, @port="agg(t)">, ...
|
164
|
+
|
165
|
+
data_points.first.min
|
166
|
+
# => 21.774511
|
167
|
+
|
168
|
+
data_points.first.max
|
169
|
+
# => 22.579952
|
170
|
+
|
171
|
+
data_points.first.avg
|
172
|
+
# => 22.1155383392857
|
173
|
+
```
|
174
|
+
|
150
175
|
|
151
176
|
## Development
|
152
177
|
|
@@ -155,7 +180,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
155
180
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
156
181
|
|
157
182
|
### Roadmap
|
158
|
-
- [
|
183
|
+
- [X] Timeseries Aggregations
|
159
184
|
- [ ] POST/PUT/DELETE users, orgs, sensors, timeseries
|
160
185
|
- [ ] Ports
|
161
186
|
- [ ] Labels
|
data/helium-ruby.gemspec
CHANGED
@@ -40,4 +40,5 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_development_dependency "guard-rspec", "~> 4.7.3"
|
41
41
|
spec.add_development_dependency "terminal-notifier-guard", "~> 1.7.0"
|
42
42
|
spec.add_development_dependency "simplecov", "~> 0.12.0"
|
43
|
+
spec.add_development_dependency "human_time", "~> 0.2.0"
|
43
44
|
end
|
data/lib/helium/client/http.rb
CHANGED
@@ -19,7 +19,8 @@ module Helium
|
|
19
19
|
request.run()
|
20
20
|
|
21
21
|
if debug?
|
22
|
-
|
22
|
+
# TODO print request method dynamically, won't always be GET
|
23
|
+
puts "GET #{request.url} #{request.response.code} #{request.response.total_time}"
|
23
24
|
# puts request.response.body
|
24
25
|
end
|
25
26
|
|
@@ -19,12 +19,14 @@ module Helium
|
|
19
19
|
return Sensor.new(client: self, params: sensor_data)
|
20
20
|
end
|
21
21
|
|
22
|
-
def sensor_timeseries(sensor, size: 1000, port: nil, start_time: nil, end_time: nil)
|
22
|
+
def sensor_timeseries(sensor, size: 1000, port: nil, start_time: nil, end_time: nil, aggtype: nil, aggsize: nil)
|
23
23
|
options = {
|
24
|
-
"page[size]"
|
25
|
-
"filter[port]"
|
24
|
+
"page[size]" => size,
|
25
|
+
"filter[port]" => port,
|
26
26
|
"filter[start]" => datetime_to_iso(start_time),
|
27
|
-
"filter[end]"
|
27
|
+
"filter[end]" => datetime_to_iso(end_time),
|
28
|
+
"agg[type]" => aggtype,
|
29
|
+
"agg[size]" => aggsize
|
28
30
|
}.delete_if { |key, value| value.to_s.empty? }
|
29
31
|
|
30
32
|
response = get("/sensor/#{sensor.id}/timeseries", options: options)
|
data/lib/helium/data_point.rb
CHANGED
@@ -13,5 +13,21 @@ module Helium
|
|
13
13
|
def timestamp
|
14
14
|
DateTime.parse(@timestamp)
|
15
15
|
end
|
16
|
+
|
17
|
+
def ==(other)
|
18
|
+
self.id == other.id
|
19
|
+
end
|
20
|
+
|
21
|
+
def max
|
22
|
+
@value["max"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def min
|
26
|
+
@value["min"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def avg
|
30
|
+
@value["avg"]
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
data/lib/helium/sensor.rb
CHANGED
@@ -20,12 +20,14 @@ module Helium
|
|
20
20
|
DateTime.parse(@updated_at)
|
21
21
|
end
|
22
22
|
|
23
|
-
def timeseries(size: 1000, port: nil, start_time: nil, end_time: nil)
|
23
|
+
def timeseries(size: 1000, port: nil, start_time: nil, end_time: nil, aggtype: nil, aggsize: nil)
|
24
24
|
@client.sensor_timeseries(self,
|
25
25
|
size: size,
|
26
26
|
port: port,
|
27
27
|
start_time: start_time,
|
28
|
-
end_time: end_time
|
28
|
+
end_time: end_time,
|
29
|
+
aggtype: aggtype,
|
30
|
+
aggsize: aggsize
|
29
31
|
)
|
30
32
|
end
|
31
33
|
end
|
data/lib/helium/timeseries.rb
CHANGED
@@ -5,14 +5,17 @@ module Helium
|
|
5
5
|
|
6
6
|
def_delegators :@data_points, :size, :length, :last
|
7
7
|
|
8
|
-
attr_accessor :data_points
|
8
|
+
attr_accessor :data_points
|
9
9
|
|
10
|
-
def initialize(client:, params
|
10
|
+
def initialize(client:, params: [], links: {})
|
11
11
|
@client = client
|
12
|
+
|
12
13
|
@data_points = params.map { |data_point_params|
|
13
14
|
DataPoint.new(client: client, params: data_point_params)
|
14
15
|
}
|
16
|
+
|
15
17
|
@previous_link = links["prev"]
|
18
|
+
@next_link = links["next"]
|
16
19
|
end
|
17
20
|
|
18
21
|
def each(&block)
|
@@ -23,5 +26,10 @@ module Helium
|
|
23
26
|
return false if @previous_link.nil?
|
24
27
|
@client.sensor_timeseries_by_link(@previous_link)
|
25
28
|
end
|
29
|
+
|
30
|
+
def next
|
31
|
+
return false if @next_link.nil?
|
32
|
+
@client.sensor_timeseries_by_link(@next_link)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/helium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helium-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 0.12.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: human_time
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 0.2.0
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 0.2.0
|
181
195
|
description: A Ruby gem for building applications with the Helium API
|
182
196
|
email:
|
183
197
|
- allenan@helium.com
|