simple_time_series 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a54aaaa112d4b24219ab2b63613345dc9133d06
4
- data.tar.gz: cc68ebee7a5177d810c7bfa40b81b05bbc22e5be
3
+ metadata.gz: 6652cc5ac84fbe5b9a437ad9823a2b877f98eed5
4
+ data.tar.gz: 4e81af7f660737a23e230e575839ea2db4bfbc0a
5
5
  SHA512:
6
- metadata.gz: 08edd9f00dcab7cc725b205b465d2b24331dcca5f1015ecaca7616f2bd1c71a938c0c5d1cddfec86608165769a7436ebfa072e82eefa38acedaa438828c27b2b
7
- data.tar.gz: 4ddd445ea40a7d3b4758dfa48cf8bdf4ecdd5abad6500eeec4b831e0ca44a4e453d7b3d33d130a9a1eb4095cb54f47600cc58803edcb1a5c843b0306c8b623ef
6
+ metadata.gz: 44ba101165e85cd96a1b2868ccf1cbb2259158bfebed931a4ff1a31c23c55d559d77e698c18044e45684abc4dc1358f50ce212a0a78a14252b0ed159bd29844e
7
+ data.tar.gz: c194fe33b180a5baa8b7bc8b54a91178ec58ed1d1cc2b50e14019d9af28bba715971d5b62c563bb6e29c20e04cba1e8657b5dcc4451679cc2db4753bbc043b68
@@ -30,7 +30,7 @@ class SimpleTimeSeries
30
30
  end
31
31
  end
32
32
  arr = arr.transpose.map { |arr| arr.reduce(:+) }
33
- opts[:prepend_name] ? arr.unshift(opts[:prepend_name]) : arr
33
+ opts[:prepend_name] ? arr.dup.unshift(opts[:prepend_name]) : arr
34
34
  end
35
35
 
36
36
  def data_array(*data_var_names, opts)
@@ -41,11 +41,15 @@ class SimpleTimeSeries
41
41
  data_arr = []
42
42
  Array(data_var_names).each do |name|
43
43
  puts "Looping through data_var_names inside data_array with #{name}" if DEBUG
44
- if opts[:start] && opts[:end]
45
- puts "Calling find(#{name}, #{opts[:start]}, #{opts[:end]}, #{opts})" if DEBUG
46
- data_arr << find(name, opts[:start], opts[:end], opts)
44
+ puts "Calling find(#{name}, #{opts[:start]}, #{opts[:end]}, #{opts})" if DEBUG
45
+ data_arr << find(name, opts[:start], opts[:end], opts)
46
+ end
47
+
48
+ if opts[:prepend_names]
49
+ if opts[:prepend_names].is_a? Array
50
+ data_arr = data_arr.each_with_index.map { |var, idx| var.dup.unshift(opts[:prepend_names][idx]) }
47
51
  else
48
- data_arr << current(name, opts)
52
+ data_arr = data_arr.each_with_index.map { |var, idx| var.dup.unshift(data_var_names[idx]) }
49
53
  end
50
54
  end
51
55
  data_arr
@@ -53,8 +57,7 @@ class SimpleTimeSeries
53
57
 
54
58
  def current(what, opts={})
55
59
  puts "#current called with #{what} and #{opts}" if DEBUG
56
- vals = send(what.to_sym, opts)
57
- opts[:prepend_names] ? vals.dup.unshift(what) : vals
60
+ send(what.to_sym, opts)
58
61
  end
59
62
 
60
63
  def index_of_date_value(date)
@@ -133,8 +136,7 @@ class SimpleTimeSeries
133
136
  puts "Called with #{first}, #{last}, #{opts}" if DEBUG
134
137
  puts "start_idx = #{start_idx}; last_idx = #{last_idx}" if DEBUG
135
138
  if start_idx != last_idx
136
- arr = eval(var)[start_idx..last_idx]
137
- return (opts[:prepend_names] ? arr.dup.unshift(var) : arr)
139
+ return eval(var)[start_idx..last_idx]
138
140
  elsif start_idx
139
141
  return eval(var)[start_idx]
140
142
  else
@@ -1,3 +1,3 @@
1
1
  class SimpleTimeSeries
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -300,6 +300,18 @@ describe SimpleTimeSeries do
300
300
  ['pizzas', 0, 0, 1, 0, 0.5, 0, 2] ]
301
301
  end
302
302
 
303
+ it "builds an array of specified arrays with custom variable names prepended to each array" do
304
+ @my_data.data_array('tasks_done', {:prepend_names => ['Tasks Completed']}).
305
+ should == [ ['Tasks Completed', 2, 3, 0, 14, 3, 11, 0] ]
306
+ @my_data.data_array('miles', 'tasks_done', {:prepend_names => ['Miles Run', 'Tasks Completed']}).
307
+ should == [ ['Miles Run', 2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3],
308
+ ['Tasks Completed', 2, 3, 0, 14, 3, 11, 0] ]
309
+ @my_data.data_array('dates', 'tasks_done', 'pizzas', {:prepend_names => ['YYYY-MM-DD', 'Tasks Completed', 'Pizzas Consumed']}).
310
+ should == [ ['YYYY-MM-DD', '2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04', '2014-01-05', '2014-01-06', '2014-01-07'],
311
+ ['Tasks Completed', 2, 3, 0, 14, 3, 11, 0],
312
+ ['Pizzas Consumed', 0, 0, 1, 0, 0.5, 0, 2] ]
313
+ end
314
+
303
315
  it "builds an array of specified arrays subsetted correctly with variable names prepended to each array" do
304
316
  @my_data.data_array('tasks_done', 'pizzas', {:start => 'Monday', :end => 'Friday',
305
317
  :prepend_names => true}).
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.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lavin