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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74609f6b618b1b78066b6882c6c71479f41c023d
4
- data.tar.gz: 966ac5e1642141dd2d332032afdba05b3aa21ce9
3
+ metadata.gz: 93c559d7ed18c8dddde1f5352550130757528fdc
4
+ data.tar.gz: 0429a2d1a38572303d6a467c0aa6a0d5d5da2136
5
5
  SHA512:
6
- metadata.gz: 8cfbb02a260e6bd7bd001690216e3ffe15cecb00d3821a2cf7ad5ace8d02c731b87afbb6b1f7f0b37f65a831f5728db6200e2066a46d8fa0a4c0149c793aad78
7
- data.tar.gz: eb57623a02f7ee34fd5aa7229e7df1d327b2a138d4c2fd40f06f83eaa7f53eed2942f56e10bab15f8833541d94eab9029608ed300f59056d59f0169651858d49
6
+ metadata.gz: d9b53980012b941a69dd214d8c2ec136b263d53d26a5cfadf96be3dc89619c035a508040f34225eb323bf55ca86418b7416dbc16374a4acba87e07d647a625a2
7
+ data.tar.gz: eebbdb3d554170e4951b53ce5a10e287385bac53a002302fa4b1137c154a9f9be28ec0a3faa1519b261fa819b79ceabf58b96718353d024a59ce1b749d02d1ef
data/UPGRADE.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.1
2
+
3
+ * value precision should ignore nils
4
+ * add Operation::Value with Value.precision for setting data value precision
5
+ * refactor collapse operation to expect Date
6
+
7
+
1
8
  ## 0.3.0
2
9
 
3
10
  * extract Parse to Quandl::Data. Add Sort
@@ -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
@@ -105,7 +105,7 @@ class Collapse
105
105
  end
106
106
 
107
107
  def find_end_of_range(date, frequency)
108
- Date.jd(date).end_of_frequency(frequency).jd
108
+ date.end_of_frequency(frequency)
109
109
  end
110
110
 
111
111
  def find_each_index(array, find)
@@ -18,6 +18,7 @@ class Transform
18
18
  # return to original order
19
19
  data = Sort.desc(data) if order == :desc
20
20
  # onwards
21
+ data = Value.precision(data, 14)
21
22
  data
22
23
  end
23
24
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Operation
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  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
- [[2456537, 56.2, nil, nil], [2456518, 55.7, nil, nil], [2456506, nil, 136133.0, nil],
50
- [2456487, 55.4, nil, nil], [2456475, nil, 135964.0, nil],
51
- [2456457, 50.9, nil, nil], [2456445, nil, 135860.0, nil]]
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
- [2456566, 56.2, nil, nil],
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 = [[ 2455875, 42 ]]
77
- subject.collapse( data, :daily).should eq [[2455875, 42]]
78
- subject.collapse( data, :weekly).should eq [[2455879, 42]]
79
- subject.collapse( data, :monthly).should eq [[2455896, 42]]
80
- subject.collapse( data, :quarterly).should eq [[2455927, 42]]
81
- subject.collapse( data, :annual).should eq [[2455927, 42]]
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').jd, 20111109 ],[ Date.parse('2011-11-10').jd, 20111110 ]]
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 [[ 2455879, 20111110 ]]
91
- subject.collapse(data, :monthly).should eq [[ 2455896, 20111110 ]]
92
- subject.collapse(data, :quarterly).should eq [[ 2455927, 20111110 ]]
93
- subject.collapse(data, :annual).should eq [[ 2455927, 20111110 ]]
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').jd, Date.parse('Dec 31, 2011').jd, 2
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.0
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-06 00:00:00.000000000 Z
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
@@ -1,5 +0,0 @@
1
- module Quandl::Operation::Errors
2
-
3
- class UnknownDateFormat < StandardError; end
4
-
5
- end