helium-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +31 -0
- data/.csslintrc +2 -0
- data/.eslintignore +1 -0
- data/.eslintrc +213 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +1156 -0
- data/CONTRIBUTING.md +33 -0
- data/LICENSE.txt +23 -17
- data/README.md +58 -47
- data/Rakefile +14 -0
- data/bin/console +8 -0
- data/docs/Helium.html +131 -0
- data/docs/Helium/Client.html +493 -0
- data/docs/Helium/Client/Http.html +428 -0
- data/docs/Helium/Client/Organizations.html +251 -0
- data/docs/Helium/Client/Sensors.html +543 -0
- data/docs/Helium/Client/Users.html +185 -0
- data/docs/Helium/Cursor.html +305 -0
- data/docs/Helium/DataPoint.html +707 -0
- data/docs/Helium/Organization.html +632 -0
- data/docs/Helium/Sensor.html +820 -0
- data/docs/Helium/User.html +563 -0
- data/docs/Helium/Utils.html +183 -0
- data/docs/_index.html +226 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +474 -0
- data/docs/file.README.html +266 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +266 -0
- data/docs/js/app.js +243 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +475 -0
- data/docs/top-level-namespace.html +112 -0
- data/helium-ruby.gemspec +2 -0
- data/lib/helium.rb +1 -1
- data/lib/helium/client.rb +0 -16
- data/lib/helium/client/http.rb +50 -9
- data/lib/helium/client/sensors.rb +51 -28
- data/lib/helium/cursor.rb +54 -0
- data/lib/helium/data_point.rb +3 -3
- data/lib/helium/sensor.rb +9 -0
- data/lib/helium/version.rb +1 -1
- metadata +63 -3
- data/lib/helium/timeseries.rb +0 -35
@@ -0,0 +1,266 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.3
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<iframe id="search_frame" src="file_list.html"></iframe>
|
61
|
+
|
62
|
+
<div id="content"><div id='filecontents'><h1>helium-ruby</h1>
|
63
|
+
|
64
|
+
<p><a href="https://travis-ci.org/helium/helium-ruby"><img src="https://travis-ci.org/helium/helium-ruby.svg?branch=master" alt="Build Status"></a>
|
65
|
+
<a href="https://coveralls.io/github/helium/helium-ruby?branch=master"><img src="https://coveralls.io/repos/github/helium/helium-ruby/badge.svg?branch=master" alt="Coverage Status"></a>
|
66
|
+
<a href="https://codeclimate.com/github/helium/helium-ruby"><img src="https://codeclimate.com/github/helium/helium-ruby/badges/gpa.svg" alt="Code Climate"></a>
|
67
|
+
<a href="https://badge.fury.io/rb/helium-ruby"><img src="https://badge.fury.io/rb/helium-ruby.svg" alt="Gem Version"></a></p>
|
68
|
+
|
69
|
+
<p>A Ruby gem for building applications with the Helium API. <a href="https://www.helium.com/">Helium</a> 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 <a href="https://docs.helium.com/">the Helium docs</a>.</p>
|
70
|
+
|
71
|
+
<h2>Installation</h2>
|
72
|
+
|
73
|
+
<p>Add this line to your application's Gemfile:</p>
|
74
|
+
|
75
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>helium-ruby</span><span class='tstring_end'>'</span></span>
|
76
|
+
</code></pre>
|
77
|
+
|
78
|
+
<p>And then execute:</p>
|
79
|
+
|
80
|
+
<pre class="code ruby"><code class="ruby">$ bundle
|
81
|
+
</code></pre>
|
82
|
+
|
83
|
+
<p>Or install it yourself as:</p>
|
84
|
+
|
85
|
+
<pre class="code ruby"><code class="ruby">$ gem install helium-ruby
|
86
|
+
</code></pre>
|
87
|
+
|
88
|
+
<h2>Usage</h2>
|
89
|
+
|
90
|
+
<h3>Setup</h3>
|
91
|
+
|
92
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>helium</span><span class='tstring_end'>'</span></span>
|
93
|
+
|
94
|
+
<span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'>Helium</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>api_key:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'><Your API Key></span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
95
|
+
</code></pre>
|
96
|
+
|
97
|
+
<h3>Users</h3>
|
98
|
+
|
99
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_user'>user</span>
|
100
|
+
<span class='comment'># => #<Helium::User:0x007fd58198d9e8 @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
101
|
+
</span></code></pre>
|
102
|
+
|
103
|
+
<h3>Organizations</h3>
|
104
|
+
|
105
|
+
<h4>Get the current organization</h4>
|
106
|
+
|
107
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_organization'>organization</span>
|
108
|
+
<span class='comment'># => #<Helium::Organization:0x007fd3d94b1b08 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="dev-accounts@helium.co", @timezone="UTC", @created_at="2015-09-10T20:50:18.183896Z", @updated_at="2015-09-10T20:50:18.183896Z">
|
109
|
+
</span></code></pre>
|
110
|
+
|
111
|
+
<h4>Get all users associated with the current organization</h4>
|
112
|
+
|
113
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_organization'>organization</span><span class='period'>.</span><span class='id identifier rubyid_users'>users</span>
|
114
|
+
<span class='comment'># => [
|
115
|
+
</span><span class='comment'># [0] #<Helium::User:0x007fd3d9449490 @client=<Helium::Client @debug=true>, @id="tom@helium.com", @name="Tom Santero", @email="tom@helium.com", @created_at="2015-01-21T16:39:31.397048Z", @updated_at="2015-02-12T20:42:22.674452Z">,
|
116
|
+
</span><span class='comment'># [1] #<Helium::User:0x007fd3d94492d8 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
117
|
+
</span><span class='comment'># ]
|
118
|
+
</span></code></pre>
|
119
|
+
|
120
|
+
<h3>Sensors</h3>
|
121
|
+
|
122
|
+
<h4>Get all Sensors</h4>
|
123
|
+
|
124
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensors'>sensors</span>
|
125
|
+
<span class='comment'># => [#<Helium::Sensor:0x007f89acdd1318 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">, ...]
|
126
|
+
</span></code></pre>
|
127
|
+
|
128
|
+
<h4>Get a Sensor by id</h4>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
131
|
+
<span class='comment'># => #<Helium::Sensor:0x007f89acdb1b58 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">
|
132
|
+
</span></code></pre>
|
133
|
+
|
134
|
+
<h3>Timeseries</h3>
|
135
|
+
|
136
|
+
<h4>Get Timeseries data for a sensor</h4>
|
137
|
+
|
138
|
+
<p>Timeseries data is paginated by the Helium API which by default, returns pages of 1000 data points. When you call <code>.timeseries</code> on a sensor, you get back a <code>Helium::Cursor</code> object, which is an <code>Enumerable</code> object that handles paging through this data automatically.</p>
|
139
|
+
|
140
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
141
|
+
<span class='id identifier rubyid_timeseries'>timeseries</span> <span class='op'>=</span> <span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>start_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-08-01</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>end_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-08-16</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
142
|
+
<span class='comment'># => #<Helium::Cursor:0x007f9b02a25798 @path="/sensor/aba370be-837d-4b41-bee5-686b0069d874/timeseries", @klass=Helium::DataPoint, @options={"page[size]"=>1000, "filter[port]"=>"t", "filter[start]"=>"2016-08-01T00:00:00Z", "filter[end]"=>"2016-08-16T00:00:00Z"}, @collection=[], @next_link=nil, @is_last=false>
|
143
|
+
</span></code></pre>
|
144
|
+
|
145
|
+
<h4>Working with data points</h4>
|
146
|
+
|
147
|
+
<p>A <code>Helium::Cursor</code> is a collection of <code>Helium::DataPoint</code>s which can iterated over using the usual <code>Object#Enumerable</code> methods:</p>
|
148
|
+
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
150
|
+
|
151
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_data_point'>data_point</span><span class='op'>|</span>
|
152
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span>
|
153
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_timestamp'>timestamp</span>
|
154
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
155
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_port'>port</span>
|
156
|
+
<span class='kw'>end</span>
|
157
|
+
|
158
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
|
159
|
+
<span class='comment'># => #<Helium::DataPoint:0x007f9b0407f340 @id="6c115c10-323e-4756-ae1c-fc69982eb397", @timestamp="2016-08-15T23:55:42.2Z", @value=22.590084, @port="t">
|
160
|
+
</span></code></pre>
|
161
|
+
|
162
|
+
<p>Since pagination happens automatically, <strong>it's strongly recommended to define a start and end time,</strong> otherwise enumerating over the collection may take a very long time.</p>
|
163
|
+
|
164
|
+
<h4>Filtering Timeseries data</h4>
|
165
|
+
|
166
|
+
<p>Timeseries data can be filtered by port type and start/end time:</p>
|
167
|
+
|
168
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:port</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
|
169
|
+
<span class='comment'># => [
|
170
|
+
</span><span class='comment'># [0] "b",
|
171
|
+
</span><span class='comment'># [1] "l",
|
172
|
+
</span><span class='comment'># [2] "h",
|
173
|
+
</span><span class='comment'># [3] "p",
|
174
|
+
</span><span class='comment'># [4] "t",
|
175
|
+
</span><span class='comment'># [5] "_se",
|
176
|
+
</span><span class='comment'># [6] "m"
|
177
|
+
</span><span class='comment'># ]
|
178
|
+
</span>
|
179
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:port</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
|
180
|
+
<span class='comment'># => [
|
181
|
+
</span><span class='comment'># [0] "t"
|
182
|
+
</span><span class='comment'># ]
|
183
|
+
</span>
|
184
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>start_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-08-01</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>end_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-08-02</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:timestamp</span><span class='rparen'>)</span>
|
185
|
+
<span class='comment'># => [
|
186
|
+
</span><span class='comment'># [0] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,802000000n),+0s,2299161j)>,
|
187
|
+
</span><span class='comment'># [1] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,61000000n),+0s,2299161j)>,
|
188
|
+
</span><span class='comment'># [2] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,60000000n),+0s,2299161j)>,
|
189
|
+
</span><span class='comment'># [3] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,59000000n),+0s,2299161j)>,
|
190
|
+
</span><span class='comment'># [4] #<DateTime: 2016-08-01T23:54:45+00:00 ((2457602j,86085s,544000000n),+0s,2299161j)>,
|
191
|
+
</span></code></pre>
|
192
|
+
|
193
|
+
<h4>Timeseries Aggregations</h4>
|
194
|
+
|
195
|
+
<p>In addition to returning the raw data points, Helium can return timeseries data aggregated into buckets.</p>
|
196
|
+
|
197
|
+
<p>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:</p>
|
198
|
+
|
199
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data_points'>data_points</span> <span class='op'>=</span> <span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>aggtype:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>min,max,avg</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>aggsize:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1d</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
200
|
+
<span class='comment'># => #<Helium::Cursor:0x007f9b0413a708 @path="/sensor/aba370be-837d-4b41-bee5-686b0069d874/timeseries", @klass=Helium::DataPoint, @options={"page[size]"=>1000, "filter[port]"=>"t", "agg[type]"=>"min,max,avg", "agg[size]"=>"1d"}, @collection=[], @next_link=nil, @is_last=false>
|
201
|
+
</span>
|
202
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_min'>min</span>
|
203
|
+
<span class='comment'># => 21.47564
|
204
|
+
</span>
|
205
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span>
|
206
|
+
<span class='comment'># => 24.145264
|
207
|
+
</span>
|
208
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_avg'>avg</span>
|
209
|
+
<span class='comment'># => 22.2916633036437
|
210
|
+
</span></code></pre>
|
211
|
+
|
212
|
+
<p>A full list of aggregation types and sizes can be found here: <a href="https://docs.helium.com/docs/timeseries#aggregations">https://docs.helium.com/docs/timeseries#aggregations</a>.</p>
|
213
|
+
|
214
|
+
<h2>Development</h2>
|
215
|
+
|
216
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
217
|
+
|
218
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
219
|
+
|
220
|
+
<h3>Roadmap</h3>
|
221
|
+
|
222
|
+
<p>We're working toward a v1.0.0 release, which will represent a feature-complete implementation of the Helium API. You can check the progress here: <a href="https://github.com/helium/helium-ruby/milestone/1">https://github.com/helium/helium-ruby/milestone/1</a>.</p>
|
223
|
+
|
224
|
+
<p>Until the v1.0.0 release, the functionality of this gem is subject to change. To prevent breaking changes, you should use the pessimistic version constraint operator (<code>~></code>) in your Gemfile to lock your helium-ruby version to the current minor release. This will allow updates to patch versions.</p>
|
225
|
+
|
226
|
+
<h2>Contributing</h2>
|
227
|
+
|
228
|
+
<p>We value contributions from the community and will do everything we can go get them reviewed in a timely fashion. If you have code to send our way or a bug to report:</p>
|
229
|
+
|
230
|
+
<ul>
|
231
|
+
<li><p>Contributing Code: If you have new code or a bug fix, fork this repo, create a logically-named branch, and submit a PR against this repo. Include a write up of the PR with details on what it does.</p></li>
|
232
|
+
<li><p>Reporting Bugs: Open an issue against this repo with as much detail as you can. At the very least you'll include steps to reproduce the problem.</p></li>
|
233
|
+
</ul>
|
234
|
+
|
235
|
+
<p>This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="http://contributor-covenant.org">Contributor Covenant</a> Code of Conduct.</p>
|
236
|
+
|
237
|
+
<p>Above all, thank you for taking the time to be a part of the Helium community.</p>
|
238
|
+
|
239
|
+
<h3>Running specs with Guard</h3>
|
240
|
+
|
241
|
+
<p>To receive system notifications of test status, install <code>terminal-notifier</code>:</p>
|
242
|
+
|
243
|
+
<pre class="code ruby"><code class="ruby">$ brew install terminal-notifier
|
244
|
+
</code></pre>
|
245
|
+
|
246
|
+
<p>Then run Guard with:</p>
|
247
|
+
|
248
|
+
<pre class="code ruby"><code class="ruby">$ bundle exec guard
|
249
|
+
</code></pre>
|
250
|
+
|
251
|
+
<p>When you modify any of the files in <code>lib/</code>, all specs will run. When you modify a spec file, just that file will be run. You can press <code>Enter</code> at the guard prompt to run all tests as well.</p>
|
252
|
+
|
253
|
+
<h2>License</h2>
|
254
|
+
|
255
|
+
<p>The gem is available as open source under the terms of the <a href="https://github.com/helium/helium-ruby/blob/master/LICENSE.txt">BSD License</a>.</p>
|
256
|
+
</div></div>
|
257
|
+
|
258
|
+
<div id="footer">
|
259
|
+
Generated on Thu Aug 18 10:50:33 2016 by
|
260
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
261
|
+
0.9.3 (ruby-2.3.1).
|
262
|
+
</div>
|
263
|
+
|
264
|
+
</div>
|
265
|
+
</body>
|
266
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.3</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript" charset="utf-8">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,266 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.3
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<iframe id="search_frame" src="class_list.html"></iframe>
|
61
|
+
|
62
|
+
<div id="content"><div id='filecontents'><h1>helium-ruby</h1>
|
63
|
+
|
64
|
+
<p><a href="https://travis-ci.org/helium/helium-ruby"><img src="https://travis-ci.org/helium/helium-ruby.svg?branch=master" alt="Build Status"></a>
|
65
|
+
<a href="https://coveralls.io/github/helium/helium-ruby?branch=master"><img src="https://coveralls.io/repos/github/helium/helium-ruby/badge.svg?branch=master" alt="Coverage Status"></a>
|
66
|
+
<a href="https://codeclimate.com/github/helium/helium-ruby"><img src="https://codeclimate.com/github/helium/helium-ruby/badges/gpa.svg" alt="Code Climate"></a>
|
67
|
+
<a href="https://badge.fury.io/rb/helium-ruby"><img src="https://badge.fury.io/rb/helium-ruby.svg" alt="Gem Version"></a></p>
|
68
|
+
|
69
|
+
<p>A Ruby gem for building applications with the Helium API. <a href="https://www.helium.com/">Helium</a> 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 <a href="https://docs.helium.com/">the Helium docs</a>.</p>
|
70
|
+
|
71
|
+
<h2>Installation</h2>
|
72
|
+
|
73
|
+
<p>Add this line to your application's Gemfile:</p>
|
74
|
+
|
75
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>helium-ruby</span><span class='tstring_end'>'</span></span>
|
76
|
+
</code></pre>
|
77
|
+
|
78
|
+
<p>And then execute:</p>
|
79
|
+
|
80
|
+
<pre class="code ruby"><code class="ruby">$ bundle
|
81
|
+
</code></pre>
|
82
|
+
|
83
|
+
<p>Or install it yourself as:</p>
|
84
|
+
|
85
|
+
<pre class="code ruby"><code class="ruby">$ gem install helium-ruby
|
86
|
+
</code></pre>
|
87
|
+
|
88
|
+
<h2>Usage</h2>
|
89
|
+
|
90
|
+
<h3>Setup</h3>
|
91
|
+
|
92
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>helium</span><span class='tstring_end'>'</span></span>
|
93
|
+
|
94
|
+
<span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'>Helium</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>api_key:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'><Your API Key></span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
95
|
+
</code></pre>
|
96
|
+
|
97
|
+
<h3>Users</h3>
|
98
|
+
|
99
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_user'>user</span>
|
100
|
+
<span class='comment'># => #<Helium::User:0x007fd58198d9e8 @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
101
|
+
</span></code></pre>
|
102
|
+
|
103
|
+
<h3>Organizations</h3>
|
104
|
+
|
105
|
+
<h4>Get the current organization</h4>
|
106
|
+
|
107
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_organization'>organization</span>
|
108
|
+
<span class='comment'># => #<Helium::Organization:0x007fd3d94b1b08 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="dev-accounts@helium.co", @timezone="UTC", @created_at="2015-09-10T20:50:18.183896Z", @updated_at="2015-09-10T20:50:18.183896Z">
|
109
|
+
</span></code></pre>
|
110
|
+
|
111
|
+
<h4>Get all users associated with the current organization</h4>
|
112
|
+
|
113
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_organization'>organization</span><span class='period'>.</span><span class='id identifier rubyid_users'>users</span>
|
114
|
+
<span class='comment'># => [
|
115
|
+
</span><span class='comment'># [0] #<Helium::User:0x007fd3d9449490 @client=<Helium::Client @debug=true>, @id="tom@helium.com", @name="Tom Santero", @email="tom@helium.com", @created_at="2015-01-21T16:39:31.397048Z", @updated_at="2015-02-12T20:42:22.674452Z">,
|
116
|
+
</span><span class='comment'># [1] #<Helium::User:0x007fd3d94492d8 @client=<Helium::Client @debug=true>, @id="dev-accounts@helium.co", @name="HeliumDevAccount Demo", @email="dev-accounts@helium.co", @created_at="2014-10-29T21:38:52Z", @updated_at="2015-08-06T18:21:32.186374Z">
|
117
|
+
</span><span class='comment'># ]
|
118
|
+
</span></code></pre>
|
119
|
+
|
120
|
+
<h3>Sensors</h3>
|
121
|
+
|
122
|
+
<h4>Get all Sensors</h4>
|
123
|
+
|
124
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensors'>sensors</span>
|
125
|
+
<span class='comment'># => [#<Helium::Sensor:0x007f89acdd1318 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">, ...]
|
126
|
+
</span></code></pre>
|
127
|
+
|
128
|
+
<h4>Get a Sensor by id</h4>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
131
|
+
<span class='comment'># => #<Helium::Sensor:0x007f89acdb1b58 @id="08bab58b-d095-4c7c-912c-1f8024d91d95", @name="Marc's Isotope", @mac="6081f9fffe00019b", @ports=["t", "b"], @created_at="2015-08-06T17:28:11.614107Z", @updated_at="2016-05-30T22:36:50.810716Z">
|
132
|
+
</span></code></pre>
|
133
|
+
|
134
|
+
<h3>Timeseries</h3>
|
135
|
+
|
136
|
+
<h4>Get Timeseries data for a sensor</h4>
|
137
|
+
|
138
|
+
<p>Timeseries data is paginated by the Helium API which by default, returns pages of 1000 data points. When you call <code>.timeseries</code> on a sensor, you get back a <code>Helium::Cursor</code> object, which is an <code>Enumerable</code> object that handles paging through this data automatically.</p>
|
139
|
+
|
140
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
141
|
+
<span class='id identifier rubyid_timeseries'>timeseries</span> <span class='op'>=</span> <span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>start_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-08-01</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>end_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-08-16</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
142
|
+
<span class='comment'># => #<Helium::Cursor:0x007f9b02a25798 @path="/sensor/aba370be-837d-4b41-bee5-686b0069d874/timeseries", @klass=Helium::DataPoint, @options={"page[size]"=>1000, "filter[port]"=>"t", "filter[start]"=>"2016-08-01T00:00:00Z", "filter[end]"=>"2016-08-16T00:00:00Z"}, @collection=[], @next_link=nil, @is_last=false>
|
143
|
+
</span></code></pre>
|
144
|
+
|
145
|
+
<h4>Working with data points</h4>
|
146
|
+
|
147
|
+
<p>A <code>Helium::Cursor</code> is a collection of <code>Helium::DataPoint</code>s which can iterated over using the usual <code>Object#Enumerable</code> methods:</p>
|
148
|
+
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_sensor'>sensor</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>08bab58b-d095-4c7c-912c-1f8024d91d95</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
150
|
+
|
151
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_data_point'>data_point</span><span class='op'>|</span>
|
152
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span>
|
153
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_timestamp'>timestamp</span>
|
154
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
155
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_data_point'>data_point</span><span class='period'>.</span><span class='id identifier rubyid_port'>port</span>
|
156
|
+
<span class='kw'>end</span>
|
157
|
+
|
158
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
|
159
|
+
<span class='comment'># => #<Helium::DataPoint:0x007f9b0407f340 @id="6c115c10-323e-4756-ae1c-fc69982eb397", @timestamp="2016-08-15T23:55:42.2Z", @value=22.590084, @port="t">
|
160
|
+
</span></code></pre>
|
161
|
+
|
162
|
+
<p>Since pagination happens automatically, <strong>it's strongly recommended to define a start and end time,</strong> otherwise enumerating over the collection may take a very long time.</p>
|
163
|
+
|
164
|
+
<h4>Filtering Timeseries data</h4>
|
165
|
+
|
166
|
+
<p>Timeseries data can be filtered by port type and start/end time:</p>
|
167
|
+
|
168
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:port</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
|
169
|
+
<span class='comment'># => [
|
170
|
+
</span><span class='comment'># [0] "b",
|
171
|
+
</span><span class='comment'># [1] "l",
|
172
|
+
</span><span class='comment'># [2] "h",
|
173
|
+
</span><span class='comment'># [3] "p",
|
174
|
+
</span><span class='comment'># [4] "t",
|
175
|
+
</span><span class='comment'># [5] "_se",
|
176
|
+
</span><span class='comment'># [6] "m"
|
177
|
+
</span><span class='comment'># ]
|
178
|
+
</span>
|
179
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:port</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span>
|
180
|
+
<span class='comment'># => [
|
181
|
+
</span><span class='comment'># [0] "t"
|
182
|
+
</span><span class='comment'># ]
|
183
|
+
</span>
|
184
|
+
<span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>start_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-08-01</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>end_time:</span> <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-08-02</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='lparen'>(</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_collect'>collect</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:timestamp</span><span class='rparen'>)</span>
|
185
|
+
<span class='comment'># => [
|
186
|
+
</span><span class='comment'># [0] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,802000000n),+0s,2299161j)>,
|
187
|
+
</span><span class='comment'># [1] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,61000000n),+0s,2299161j)>,
|
188
|
+
</span><span class='comment'># [2] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,60000000n),+0s,2299161j)>,
|
189
|
+
</span><span class='comment'># [3] #<DateTime: 2016-08-01T23:55:29+00:00 ((2457602j,86129s,59000000n),+0s,2299161j)>,
|
190
|
+
</span><span class='comment'># [4] #<DateTime: 2016-08-01T23:54:45+00:00 ((2457602j,86085s,544000000n),+0s,2299161j)>,
|
191
|
+
</span></code></pre>
|
192
|
+
|
193
|
+
<h4>Timeseries Aggregations</h4>
|
194
|
+
|
195
|
+
<p>In addition to returning the raw data points, Helium can return timeseries data aggregated into buckets.</p>
|
196
|
+
|
197
|
+
<p>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:</p>
|
198
|
+
|
199
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data_points'>data_points</span> <span class='op'>=</span> <span class='id identifier rubyid_sensor'>sensor</span><span class='period'>.</span><span class='id identifier rubyid_timeseries'>timeseries</span><span class='lparen'>(</span><span class='label'>port:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>t</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>aggtype:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>min,max,avg</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>aggsize:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1d</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
200
|
+
<span class='comment'># => #<Helium::Cursor:0x007f9b0413a708 @path="/sensor/aba370be-837d-4b41-bee5-686b0069d874/timeseries", @klass=Helium::DataPoint, @options={"page[size]"=>1000, "filter[port]"=>"t", "agg[type]"=>"min,max,avg", "agg[size]"=>"1d"}, @collection=[], @next_link=nil, @is_last=false>
|
201
|
+
</span>
|
202
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_min'>min</span>
|
203
|
+
<span class='comment'># => 21.47564
|
204
|
+
</span>
|
205
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span>
|
206
|
+
<span class='comment'># => 24.145264
|
207
|
+
</span>
|
208
|
+
<span class='id identifier rubyid_data_points'>data_points</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_avg'>avg</span>
|
209
|
+
<span class='comment'># => 22.2916633036437
|
210
|
+
</span></code></pre>
|
211
|
+
|
212
|
+
<p>A full list of aggregation types and sizes can be found here: <a href="https://docs.helium.com/docs/timeseries#aggregations">https://docs.helium.com/docs/timeseries#aggregations</a>.</p>
|
213
|
+
|
214
|
+
<h2>Development</h2>
|
215
|
+
|
216
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
217
|
+
|
218
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
219
|
+
|
220
|
+
<h3>Roadmap</h3>
|
221
|
+
|
222
|
+
<p>We're working toward a v1.0.0 release, which will represent a feature-complete implementation of the Helium API. You can check the progress here: <a href="https://github.com/helium/helium-ruby/milestone/1">https://github.com/helium/helium-ruby/milestone/1</a>.</p>
|
223
|
+
|
224
|
+
<p>Until the v1.0.0 release, the functionality of this gem is subject to change. To prevent breaking changes, you should use the pessimistic version constraint operator (<code>~></code>) in your Gemfile to lock your helium-ruby version to the current minor release. This will allow updates to patch versions.</p>
|
225
|
+
|
226
|
+
<h2>Contributing</h2>
|
227
|
+
|
228
|
+
<p>We value contributions from the community and will do everything we can go get them reviewed in a timely fashion. If you have code to send our way or a bug to report:</p>
|
229
|
+
|
230
|
+
<ul>
|
231
|
+
<li><p>Contributing Code: If you have new code or a bug fix, fork this repo, create a logically-named branch, and submit a PR against this repo. Include a write up of the PR with details on what it does.</p></li>
|
232
|
+
<li><p>Reporting Bugs: Open an issue against this repo with as much detail as you can. At the very least you'll include steps to reproduce the problem.</p></li>
|
233
|
+
</ul>
|
234
|
+
|
235
|
+
<p>This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="http://contributor-covenant.org">Contributor Covenant</a> Code of Conduct.</p>
|
236
|
+
|
237
|
+
<p>Above all, thank you for taking the time to be a part of the Helium community.</p>
|
238
|
+
|
239
|
+
<h3>Running specs with Guard</h3>
|
240
|
+
|
241
|
+
<p>To receive system notifications of test status, install <code>terminal-notifier</code>:</p>
|
242
|
+
|
243
|
+
<pre class="code ruby"><code class="ruby">$ brew install terminal-notifier
|
244
|
+
</code></pre>
|
245
|
+
|
246
|
+
<p>Then run Guard with:</p>
|
247
|
+
|
248
|
+
<pre class="code ruby"><code class="ruby">$ bundle exec guard
|
249
|
+
</code></pre>
|
250
|
+
|
251
|
+
<p>When you modify any of the files in <code>lib/</code>, all specs will run. When you modify a spec file, just that file will be run. You can press <code>Enter</code> at the guard prompt to run all tests as well.</p>
|
252
|
+
|
253
|
+
<h2>License</h2>
|
254
|
+
|
255
|
+
<p>The gem is available as open source under the terms of the <a href="https://github.com/helium/helium-ruby/blob/master/LICENSE.txt">BSD License</a>.</p>
|
256
|
+
</div></div>
|
257
|
+
|
258
|
+
<div id="footer">
|
259
|
+
Generated on Thu Aug 18 10:50:33 2016 by
|
260
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
261
|
+
0.9.3 (ruby-2.3.1).
|
262
|
+
</div>
|
263
|
+
|
264
|
+
</div>
|
265
|
+
</body>
|
266
|
+
</html>
|