simple_time_series 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07a3e14fd7eff38cbdbb58579d7bebbc7e3899da
|
4
|
+
data.tar.gz: 023551817a829f9bea6da942a8f627ad844796cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5062c774092d7ae6b36c8cb0af664c2b41796dc073bef4c99630946dd2df91e032cd3c30063aa570843e9aee3c5f85177b640ffd1e2e0e4acf44d3a575376817
|
7
|
+
data.tar.gz: ca7130e239cf7cc6dcf6dcf83c84207983728a07827d0e04d86399db99f07b9073aeb1241b4b46327a3ffca6176275add7ab3f30080cb6d020ee395d6a10e0b3
|
@@ -17,7 +17,7 @@ class SimpleTimeSeries
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def find_plus_label(what, date, end_date=nil)
|
20
|
-
find(what, date, end_date).unshift(what)
|
20
|
+
find(what, date, end_date).dup.unshift(what)
|
21
21
|
end
|
22
22
|
|
23
23
|
def data_array(*data_var_names, opts)
|
@@ -27,6 +27,7 @@ class SimpleTimeSeries
|
|
27
27
|
raise err_msg unless opts
|
28
28
|
data_arr = []
|
29
29
|
Array(data_var_names).each do |name|
|
30
|
+
puts "Looping through data_var_names inside data_array with #{name}" if DEBUG
|
30
31
|
if opts[:start] && opts[:end]
|
31
32
|
puts "Calling find(#{name}, #{opts[:start]}, #{opts[:end]}, #{opts})" if DEBUG
|
32
33
|
data_arr << find(name, opts[:start], opts[:end], opts)
|
@@ -38,7 +39,9 @@ class SimpleTimeSeries
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def current(what, opts={})
|
41
|
-
|
42
|
+
puts "#current called with #{what} and #{opts}" if DEBUG
|
43
|
+
vals = send(what.to_sym, opts)
|
44
|
+
opts[:prepend_names] ? vals.dup.unshift(what) : vals
|
42
45
|
end
|
43
46
|
|
44
47
|
def index_of_date_value(date)
|
@@ -82,7 +85,7 @@ class SimpleTimeSeries
|
|
82
85
|
time_vars.each do |tv_key, tv_val|
|
83
86
|
start_idx = index_of_date_value(first) || 0
|
84
87
|
last_idx = index_of_date_value(last) || (first.nil? ? -1 : start_idx)
|
85
|
-
answer = (eval(var).each_cons(2).map { |val1, val2| val2 - val1 }.unshift(nil))[start_idx..last_idx]
|
88
|
+
answer = (eval(var).each_cons(2).map { |val1, val2| val2 - val1 }.dup.unshift(nil))[start_idx..last_idx]
|
86
89
|
return answer.length == 1 ? answer[0] : answer
|
87
90
|
end
|
88
91
|
end
|
@@ -93,7 +96,7 @@ class SimpleTimeSeries
|
|
93
96
|
start_idx = index_of_date_value(first) || 0
|
94
97
|
last_idx = index_of_date_value(last) || (first.nil? ? -1 : start_idx)
|
95
98
|
sum = eval(var)[0]
|
96
|
-
answer = (eval(var).each_cons(2).map { |val1, val2| sum += val2 }.unshift(eval(var)[start_idx]))[start_idx..last_idx]
|
99
|
+
answer = (eval(var).each_cons(2).map { |val1, val2| sum += val2 }.dup.unshift(eval(var)[start_idx]))[start_idx..last_idx]
|
97
100
|
return answer.length == 1 ? answer[0] : answer
|
98
101
|
end
|
99
102
|
end
|
@@ -107,7 +110,7 @@ class SimpleTimeSeries
|
|
107
110
|
puts "start_idx = #{start_idx}; last_idx = #{last_idx}" if DEBUG
|
108
111
|
if start_idx != last_idx
|
109
112
|
arr = eval(var)[start_idx..last_idx]
|
110
|
-
return (opts[:prepend_names] ? arr.unshift(var) : arr)
|
113
|
+
return (opts[:prepend_names] ? arr.dup.unshift(var) : arr)
|
111
114
|
elsif start_idx
|
112
115
|
return eval(var)[start_idx]
|
113
116
|
else
|
@@ -289,21 +289,22 @@ describe SimpleTimeSeries do
|
|
289
289
|
end
|
290
290
|
|
291
291
|
it "builds an array of specified arrays with variable names prepended to each array" do
|
292
|
-
@my_data.data_array('tasks_done', {:prepend_names => true}).
|
293
|
-
should == [ @my_data.current('tasks_done').unshift('tasks_done') ]
|
294
292
|
@my_data.data_array('tasks_done', {:prepend_names => true}).
|
295
293
|
should == [ ['tasks_done', 2, 3, 0, 14, 3, 11, 0] ]
|
294
|
+
@my_data.data_array('miles', 'tasks_done', {:prepend_names => true}).
|
295
|
+
should == [ ['miles', 2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3],
|
296
|
+
['tasks_done', 2, 3, 0, 14, 3, 11, 0] ]
|
296
297
|
@my_data.data_array('dates', 'tasks_done', 'pizzas', {:prepend_names => true}).
|
297
|
-
should == [
|
298
|
-
|
299
|
-
|
298
|
+
should == [ ['dates', '2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04', '2014-01-05', '2014-01-06', '2014-01-07'],
|
299
|
+
['tasks_done', 2, 3, 0, 14, 3, 11, 0],
|
300
|
+
['pizzas', 0, 0, 1, 0, 0.5, 0, 2] ]
|
300
301
|
end
|
301
302
|
|
302
303
|
it "builds an array of specified arrays subsetted correctly with variable names prepended to each array" do
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
304
|
+
@my_data.data_array('tasks_done', 'pizzas', {:start => 'Monday', :end => 'Friday',
|
305
|
+
:prepend_names => true}).
|
306
|
+
should == [ ['tasks_done', 3, 0, 14, 3, 11],
|
307
|
+
['pizzas', 0, 1, 0, 0.5, 0] ]
|
307
308
|
#should == [ ['tasks_done', 3, 0, 14, 3, 11], ['pizzas', 0, 1, 0, 0.5, 0] ]
|
308
309
|
#should == [ ['tasks_done', 3, 0, 14, 3, 11], ['pizzas', 0, 1, 0, 0.5, 0] ]
|
309
310
|
#should == [ @my_data.find('tasks_done','Tuesday','Thursday'),
|