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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6652cc5ac84fbe5b9a437ad9823a2b877f98eed5
|
4
|
+
data.tar.gz: 4e81af7f660737a23e230e575839ea2db4bfbc0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
@@ -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}).
|