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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: debfc06f4c0f3325f0d5d8b204b9f32fa0add2e8
4
- data.tar.gz: 279ca288cbe91c7a87a05e72394cb5ef5b44d29d
3
+ metadata.gz: 3a54aaaa112d4b24219ab2b63613345dc9133d06
4
+ data.tar.gz: cc68ebee7a5177d810c7bfa40b81b05bbc22e5be
5
5
  SHA512:
6
- metadata.gz: bdaab97c059ad97c01a1a1ac3d4237327a45de83feeb4f3b3a34b9847867ae951c5614eeb186c0d08a72318a0cecfe99d7557562679060e617963384aa8df7b5
7
- data.tar.gz: 87b2262af37d5a400d57aa99d43355bbf5bdc0b299765cfe9c4e1e2f24dc2806c8989e902cffbc8ddf80be5e439625a3c630368c60978e32a0fdbc005dcaa3cb
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
- 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]
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)
@@ -1,3 +1,3 @@
1
1
  class SimpleTimeSeries
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_time_series
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lavin