quandl_operation 0.3.0 → 0.3.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 +4 -4
- data/UPGRADE.md +7 -0
- data/lib/quandl/operation.rb +1 -1
- data/lib/quandl/operation/collapse.rb +1 -1
- data/lib/quandl/operation/transform.rb +1 -0
- data/lib/quandl/operation/value.rb +23 -0
- data/lib/quandl/operation/version.rb +1 -1
- data/spec/lib/quandl/operation/collapse_spec.rb +18 -21
- metadata +3 -3
- data/lib/quandl/operation/errors.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c559d7ed18c8dddde1f5352550130757528fdc
|
4
|
+
data.tar.gz: 0429a2d1a38572303d6a467c0aa6a0d5d5da2136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9b53980012b941a69dd214d8c2ec136b263d53d26a5cfadf96be3dc89619c035a508040f34225eb323bf55ca86418b7416dbc16374a4acba87e07d647a625a2
|
7
|
+
data.tar.gz: eebbdb3d554170e4951b53ce5a10e287385bac53a002302fa4b1137c154a9f9be28ec0a3faa1519b261fa819b79ceabf58b96718353d024a59ce1b749d02d1ef
|
data/UPGRADE.md
CHANGED
data/lib/quandl/operation.rb
CHANGED
@@ -13,8 +13,8 @@ require 'quandl/operation/core_ext'
|
|
13
13
|
require 'quandl/operation/collapse'
|
14
14
|
require 'quandl/operation/transform'
|
15
15
|
require 'quandl/operation/sort'
|
16
|
-
require 'quandl/operation/errors'
|
17
16
|
require 'quandl/operation/qdate'
|
17
|
+
require 'quandl/operation/value'
|
18
18
|
|
19
19
|
module Quandl
|
20
20
|
module Operation
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Operation
|
3
|
+
class Value
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def precision(data, prec=14)
|
8
|
+
r = []
|
9
|
+
data.each do |row|
|
10
|
+
new_row = [row[0]]
|
11
|
+
row[1..-1].each do |v|
|
12
|
+
new_row << (v.nil? ? v : Float("%.#{prec}g" % v))
|
13
|
+
end
|
14
|
+
r << new_row
|
15
|
+
end
|
16
|
+
r
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -36,7 +36,7 @@ describe Quandl::Operation::Collapse do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def table_range(from, to, columns = 1)
|
39
|
-
days = to - from
|
39
|
+
days = (to - from).to_i
|
40
40
|
r = days.times.collect do |i|
|
41
41
|
[ from + i ] + columns.times.collect{(rand(1000) * 0.7) + i}
|
42
42
|
end
|
@@ -46,17 +46,14 @@ describe Quandl::Operation::Collapse do
|
|
46
46
|
describe ".perform" do
|
47
47
|
|
48
48
|
let(:data){
|
49
|
-
[[
|
50
|
-
[
|
51
|
-
[
|
49
|
+
[[Date.parse("2013-09-01"), 56.2, nil, nil], [Date.parse("2013-08-13"), 55.7, nil, nil],
|
50
|
+
[Date.parse("2013-08-01"), nil, 136133.0, nil], [Date.parse("2013-07-13"), 55.4, nil, nil],
|
51
|
+
[Date.parse("2013-07-01"), nil, 135964.0, nil], [Date.parse("2013-06-13"), 50.9, nil, nil], [Date.parse("2013-06-01"), nil, 135860.0, nil]]
|
52
52
|
}
|
53
53
|
|
54
54
|
it "should collapse data with nils" do
|
55
|
-
subject.perform(data, :monthly).should eq [
|
56
|
-
|
57
|
-
[2456536, 55.7, 136133.0, nil],
|
58
|
-
[2456505, 55.4, 135964.0, nil],
|
59
|
-
[2456474, 50.9, 135860.0, nil]]
|
55
|
+
subject.perform(data, :monthly).should eq [[Date.parse("2013-09-30"), 56.2, nil, nil], [Date.parse("2013-08-31"), 55.7, 136133.0, nil],
|
56
|
+
[Date.parse("2013-07-31"), 55.4, 135964.0, nil], [Date.parse("2013-06-30"), 50.9, 135860.0, nil]]
|
60
57
|
end
|
61
58
|
|
62
59
|
it "should handle empty data" do
|
@@ -73,29 +70,29 @@ describe Quandl::Operation::Collapse do
|
|
73
70
|
|
74
71
|
it 'should handle data sets with one data point only' do
|
75
72
|
|
76
|
-
data = [[
|
77
|
-
subject.collapse( data, :daily).should eq [[
|
78
|
-
subject.collapse( data, :weekly).should eq [[
|
79
|
-
subject.collapse( data, :monthly).should eq [[
|
80
|
-
subject.collapse( data, :quarterly).should eq [[
|
81
|
-
subject.collapse( data, :annual).should eq [[
|
73
|
+
data = [[ Date.parse('2011-11-09'), 42 ]]
|
74
|
+
subject.collapse( data, :daily).should eq [[Date.parse('2011-11-09'), 42]]
|
75
|
+
subject.collapse( data, :weekly).should eq [[Date.parse('2011-11-13'), 42]]
|
76
|
+
subject.collapse( data, :monthly).should eq [[Date.parse('2011-11-30'), 42]]
|
77
|
+
subject.collapse( data, :quarterly).should eq [[Date.parse('2011-12-31'), 42]]
|
78
|
+
subject.collapse( data, :annual).should eq [[Date.parse('2011-12-31'), 42]]
|
82
79
|
|
83
80
|
end
|
84
81
|
|
85
82
|
it 'should handle data sets with only two data points, 1 day apart' do
|
86
83
|
|
87
|
-
data = [[ Date.parse('2011-11-09')
|
84
|
+
data = [[ Date.parse('2011-11-09'), 20111109 ],[ Date.parse('2011-11-10'), 20111110 ]]
|
88
85
|
|
89
86
|
subject.collapse(data, :daily).should eq data
|
90
|
-
subject.collapse(data, :weekly).should eq [[
|
91
|
-
subject.collapse(data, :monthly).should eq [[
|
92
|
-
subject.collapse(data, :quarterly).should eq [[
|
93
|
-
subject.collapse(data, :annual).should eq [[
|
87
|
+
subject.collapse(data, :weekly).should eq [[ Date.parse('2011-11-13'), 20111110 ]]
|
88
|
+
subject.collapse(data, :monthly).should eq [[ Date.parse('2011-11-30'), 20111110 ]]
|
89
|
+
subject.collapse(data, :quarterly).should eq [[ Date.parse('2011-12-31'), 20111110 ]]
|
90
|
+
subject.collapse(data, :annual).should eq [[ Date.parse('2011-12-31'), 20111110 ]]
|
94
91
|
|
95
92
|
end
|
96
93
|
|
97
94
|
it 'should handle data sets one year of daily data' do
|
98
|
-
data = table_range Date.parse('Jan 1, 2011')
|
95
|
+
data = table_range Date.parse('Jan 1, 2011'), Date.parse('Dec 31, 2011'), 2
|
99
96
|
data.count.should eq 364
|
100
97
|
subject.collapse( data, :daily ).count.should eq 364
|
101
98
|
subject.collapse( data, :weekly ).count.should eq 53
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: quandl_logger
|
@@ -176,10 +176,10 @@ files:
|
|
176
176
|
- lib/quandl/operation/core_ext/float.rb
|
177
177
|
- lib/quandl/operation/core_ext/string.rb
|
178
178
|
- lib/quandl/operation/core_ext/time.rb
|
179
|
-
- lib/quandl/operation/errors.rb
|
180
179
|
- lib/quandl/operation/qdate.rb
|
181
180
|
- lib/quandl/operation/sort.rb
|
182
181
|
- lib/quandl/operation/transform.rb
|
182
|
+
- lib/quandl/operation/value.rb
|
183
183
|
- lib/quandl/operation/version.rb
|
184
184
|
- quandl_operation.gemspec
|
185
185
|
- spec/lib/quandl/operation/collapse_spec.rb
|