simple_time_series 0.1.5 → 0.1.6
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 +25 -1
- data/lib/core_ext/array.rb +22 -0
- data/lib/simple_time_series.rb +1 -0
- data/lib/simple_time_series/version.rb +1 -1
- data/spec/lib/simple_time_series_spec.rb +30 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96fc69681d3c929e6f16e8f162be2fc246128eed
|
4
|
+
data.tar.gz: 2737be6e56ae082830a0273e76b09663ac94d713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b3d87226d74112ebf4c4a2650f57e9340a3a27e1a1de61347be8096606009e5b70610d74f17ec72f5fa072dd86901c6d5031c58a115e41507d659e4e19f4f03
|
7
|
+
data.tar.gz: 01753f203de51d3b6f321cd1c010a931f4764fd657986ecff98c5c4b05c487c1f5bc738f84234e8b2bba103301549347b3c35dae06254d5b98aa3b2d657c4b11
|
data/README.md
CHANGED
@@ -42,6 +42,13 @@ This is sufficient to package up your data into a SimpleTimeSeries object:
|
|
42
42
|
'miles' => miles,
|
43
43
|
'tasks_done' => tasks_done})
|
44
44
|
|
45
|
+
If your input data is strings but should be converted into numeric, you can call #to_num on it and it will be converted to an array of integers (where possible) or floats:
|
46
|
+
|
47
|
+
donuts = ["6", "0", "2", "4.5", "1.5", "0", "9"]
|
48
|
+
new_data = SimpleTimeSeries.new(:time_vars => {'dates' => dates},
|
49
|
+
:data_vars => {'donuts' => donuts.to_num})
|
50
|
+
new_data.current('donuts') #returns [6, 0, 2, 4.5, 1.5, 0, 9]
|
51
|
+
|
45
52
|
You can now easily access the value of any data variable for any value of one of your time variables via xxx_on methods created for each of your data_vars (here called 'pizzas_on,' 'miles_on' and 'tasks_done_on'):
|
46
53
|
|
47
54
|
puts "Pizzas eaten on Tuesday: #{my_data.pizzas_on('Tuesday')}" # prints 1
|
@@ -247,7 +254,7 @@ You can extract subsets of your data into arrays of arrays with #data_array:
|
|
247
254
|
[2, 3, 0, 14, 3, 11, 0],
|
248
255
|
[0, 0, 1, 0, 0.5, 0, 2] ]
|
249
256
|
|
250
|
-
You can tell it to prepend
|
257
|
+
You can tell it to prepend each variable's name to its array:
|
251
258
|
|
252
259
|
my_data.data_array('tasks_done', {:prepend_names => true})
|
253
260
|
=>
|
@@ -308,6 +315,23 @@ You can tell it to prepend the variable name to each array:
|
|
308
315
|
['tasks_done', 3, 0, 14, 3, 11, 0],
|
309
316
|
['pizzas', 0, 1, 0, 0.5, 0, 2] ]
|
310
317
|
|
318
|
+
You can also pass an array of custom names to prepend to each data_var array:
|
319
|
+
|
320
|
+
my_data.data_array('tasks_done', {:prepend_names => ['Tasks Completed']})
|
321
|
+
=>
|
322
|
+
[ ['Tasks Completed', 2, 3, 0, 14, 3, 11, 0] ]
|
323
|
+
|
324
|
+
my_data.data_array('miles', 'tasks_done', {:prepend_names => ['Miles Run', 'Tasks Completed']})
|
325
|
+
=>
|
326
|
+
[ ['Miles Run', 2.2, 3.1, 0.0, 4.3, 1.2, 12.2, 2.3],
|
327
|
+
['Tasks Completed', 2, 3, 0, 14, 3, 11, 0] ]
|
328
|
+
|
329
|
+
my_data.data_array('dates', 'tasks_done', 'pizzas', {:prepend_names => ['YYYY-MM-DD', 'Tasks Completed', 'Pizzas Consumed']})
|
330
|
+
=>
|
331
|
+
[ ['YYYY-MM-DD', '2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04', '2014-01-05', '2014-01-06', '2014-01-07'],
|
332
|
+
['Tasks Completed', 2, 3, 0, 14, 3, 11, 0],
|
333
|
+
['Pizzas Consumed', 0, 0, 1, 0, 0.5, 0, 2] ]
|
334
|
+
|
311
335
|
Currently, SimpleTimeSeries assumes all variable arrays have equal lengths and represent the same sequence of observations. Though the gem says "time series," it should work with any kind of sequential data.
|
312
336
|
|
313
337
|
## Disclaimer
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
def to_i
|
4
|
+
map { |str| str.to_i }
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_f
|
8
|
+
map { |str| str.to_f }
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_num
|
12
|
+
begin
|
13
|
+
to_i
|
14
|
+
rescue
|
15
|
+
begin
|
16
|
+
to_f
|
17
|
+
rescue
|
18
|
+
raise "Unable to convert #{self} #to_num"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/simple_time_series.rb
CHANGED
@@ -21,6 +21,36 @@ describe SimpleTimeSeries do
|
|
21
21
|
@my_data.should be_a(SimpleTimeSeries)
|
22
22
|
end
|
23
23
|
|
24
|
+
it "can convert (via #to_f) an input array of strings to an array of floats" do
|
25
|
+
@donuts = ["6", "0", "2", "4.5", "1.5", "0", "9"]
|
26
|
+
new_data = SimpleTimeSeries.new(:time_vars => {'dates' => @dates},
|
27
|
+
:data_vars => {'donuts' => @donuts.to_f})
|
28
|
+
new_data.current('donuts').should == [6, 0, 2, 4.5, 1.5, 0, 9]
|
29
|
+
new_data.current('donuts')[0].should_not == "6"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can convert (via #to_num) an input array of strings to an array of floats" do
|
33
|
+
@donuts = ["6", "0", "2", "4.5", "1.5", "0", "9"]
|
34
|
+
new_data = SimpleTimeSeries.new(:time_vars => {'dates' => @dates},
|
35
|
+
:data_vars => {'donuts' => @donuts.to_f})
|
36
|
+
new_data.current('donuts').should == [6, 0, 2, 4.5, 1.5, 0, 9]
|
37
|
+
new_data.current('donuts')[0].should_not == "6"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can convert (via #to_i) an input array of strings to an array of integers" do
|
41
|
+
@donuts = ["6", "0", "2", "4", "1", "0", "9"]
|
42
|
+
new_data = SimpleTimeSeries.new(:time_vars => {'dates' => @dates},
|
43
|
+
:data_vars => {'donuts' => @donuts.to_i})
|
44
|
+
new_data.current('donuts').should == [6, 0, 2, 4, 1, 0, 9]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can convert (via #to_num) an input array of strings to an array of integers" do
|
48
|
+
@donuts = ["6", "0", "2", "4", "1", "0", "9"]
|
49
|
+
new_data = SimpleTimeSeries.new(:time_vars => {'dates' => @dates},
|
50
|
+
:data_vars => {'donuts' => @donuts.to_num})
|
51
|
+
new_data.current('donuts').should == [6, 0, 2, 4, 1, 0, 9]
|
52
|
+
end
|
53
|
+
|
24
54
|
it "sets #time_vars correctly" do
|
25
55
|
@my_data.time_vars["dates"].should == @dates
|
26
56
|
@my_data.time_vars["dows"].should == @dows
|
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
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Lavin
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
|
+
- lib/core_ext/array.rb
|
68
69
|
- lib/simple_time_series.rb
|
69
70
|
- lib/simple_time_series/simple_time_series.rb
|
70
71
|
- lib/simple_time_series/version.rb
|