simple_time_series 0.1.3 → 0.1.4
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 +32 -15
- data/lib/simple_time_series/simple_time_series.rb +2 -1
- data/lib/simple_time_series/version.rb +1 -1
- data/spec/lib/simple_time_series_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a54aaaa112d4b24219ab2b63613345dc9133d06
|
4
|
+
data.tar.gz: cc68ebee7a5177d810c7bfa40b81b05bbc22e5be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08edd9f00dcab7cc725b205b465d2b24331dcca5f1015ecaca7616f2bd1c71a938c0c5d1cddfec86608165769a7436ebfa072e82eefa38acedaa438828c27b2b
|
7
|
+
data.tar.gz: 4ddd445ea40a7d3b4758dfa48cf8bdf4ecdd5abad6500eeec4b831e0ca44a4e453d7b3d33d130a9a1eb4095cb54f47600cc58803edcb1a5c843b0306c8b623ef
|
data/README.md
CHANGED
@@ -203,21 +203,38 @@ It also calculates cumulative sums for any data_var:
|
|
203
203
|
|
204
204
|
You can sum data_vars across time observations for all time values or a subset of time values:
|
205
205
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
206
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {})
|
207
|
+
=>
|
208
|
+
[0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
209
|
+
|
210
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => 'Monday', :end => 'Saturday'})
|
211
|
+
=>
|
212
|
+
[0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
213
|
+
|
214
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-01', :end => 'Jan 7, 2014'})
|
215
|
+
=>
|
216
|
+
[0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
217
|
+
|
218
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-03', :end => 'Jan 6, 2014'})
|
219
|
+
=>
|
220
|
+
[1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
|
221
|
+
|
222
|
+
You can name your new variable with :prepend_name, as follows:
|
223
|
+
|
224
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => 'Monday', :end => 'Saturday',
|
225
|
+
:prepend_name => 'total'})
|
226
|
+
=>
|
227
|
+
['total', 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
228
|
+
|
229
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-01', :end => 'Jan 7, 2014',
|
230
|
+
:prepend_name => 'all the things!'})
|
231
|
+
=>
|
232
|
+
['all the things!', 0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
233
|
+
|
234
|
+
my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-03', :end => 'Jan 6, 2014',
|
235
|
+
:prepend_name => "Jeff's fancy pants data variable"})
|
236
|
+
=>
|
237
|
+
["Jeff's fancy pants data variable", 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
|
221
238
|
|
222
239
|
You can extract subsets of your data into arrays of arrays with #data_array:
|
223
240
|
|
@@ -29,7 +29,8 @@ class SimpleTimeSeries
|
|
29
29
|
arr << current(name, opts)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
arr.transpose.map { |arr| arr.reduce(:+) }
|
32
|
+
arr = arr.transpose.map { |arr| arr.reduce(:+) }
|
33
|
+
opts[:prepend_name] ? arr.unshift(opts[:prepend_name]) : arr
|
33
34
|
end
|
34
35
|
|
35
36
|
def data_array(*data_var_names, opts)
|
@@ -329,6 +329,20 @@ describe SimpleTimeSeries do
|
|
329
329
|
[1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
|
330
330
|
end
|
331
331
|
|
332
|
+
it "sums a set of data_vars across time observations for a subset of time values and lets you specify the name of the new data row" do
|
333
|
+
@my_data.sum_by_date('pizzas','miles','tasks_done', {:start => 'Monday', :end => 'Saturday',
|
334
|
+
:prepend_name => 'total'}).should ==
|
335
|
+
['total', 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
336
|
+
|
337
|
+
@my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-01', :end => 'Jan 7, 2014',
|
338
|
+
:prepend_name => 'all the things!'}).should ==
|
339
|
+
['all the things!', 0 + 2.2 + 2, 0 + 3.1 + 3, 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11, 2 + 2.3 + 0]
|
340
|
+
|
341
|
+
@my_data.sum_by_date('pizzas','miles','tasks_done', {:start => '2014-01-03', :end => 'Jan 6, 2014',
|
342
|
+
:prepend_name => "Jeff's fancy pants data variable"}).should ==
|
343
|
+
["Jeff's fancy pants data variable", 1 + 0.0 + 0, 0 + 4.3 + 14, 0.5 + 1.2 + 3, 0 + 12.2 + 11]
|
344
|
+
end
|
345
|
+
|
332
346
|
end
|
333
347
|
|
334
348
|
end
|