quandl_babelfish 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,7 +1,7 @@
1
- .idea/
2
- /Gemfile.lock
3
- /pkg
4
- /tmp
5
- .rvmrc
6
- *.gem
7
- *.log
1
+ .idea/
2
+ /Gemfile.lock
3
+ /pkg
4
+ /tmp
5
+ .rvmrc
6
+ *.gem
7
+ *.log
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.0.0
5
- - 1.9.3
6
-
7
- gemfile:
8
- - Gemfile
9
-
10
- matrix:
11
-
12
- script: bundle exec rspec
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+
7
+ gemfile:
8
+ - Gemfile
9
+
10
+ matrix:
11
+
12
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source "https://rubygems.org"
1
+ source "https://rubygems.org"
2
2
  gemspec
data/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright (c) 2012-2013 Quandl
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2012-2013 Quandl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
- # Quandl::Babelfish
2
-
3
- ### Installation
4
-
5
- ```ruby
6
-
7
-
8
- gem 'quandl_babelfish'
9
-
10
- ```
11
-
12
-
13
- ### Usage
14
-
15
- ```ruby
16
-
17
-
18
- ```
1
+ # Quandl::Babelfish
2
+
3
+ ### Installation
4
+
5
+ ```ruby
6
+
7
+
8
+ gem 'quandl_babelfish'
9
+
10
+ ```
11
+
12
+
13
+ ### Usage
14
+
15
+ ```ruby
16
+
17
+
18
+ ```
data/UPGRADE.md CHANGED
@@ -1,30 +1,32 @@
1
- ## 0.0.6
2
-
3
- * add Babelfish::Chronometer
4
- * add Babelfish.guess_frequency
5
-
6
-
7
- ## 0.0.5
8
-
9
- * improve error messages with line, row, context
10
- * add Quandl::Error::Standard, all errors inherit from Error::Standard
11
-
12
-
13
- ## 0.0.4
14
-
15
- * remove quandl_data as a dependency
16
-
17
-
18
- ## 0.0.3
19
-
20
- * Add Quandl::Data as a add_runtime_dependency
21
- * refactor Babelfish::Data to inherit from Quandl::Data
22
- * refactor specs
23
-
24
-
25
- ## 0.0.1
26
-
27
- * replace Cleaner.process return clean_array, header with Quandl::Babelfish::Data.new( clean_array, headers: header )
28
- * refactored error
29
- * added header extraction support
1
+ ## 0.0.7
2
+ * added squaring final data
3
+
4
+ ## 0.0.6
5
+
6
+ * add Babelfish::Chronometer
7
+ * add Babelfish.guess_frequency
8
+
9
+ ## 0.0.5
10
+
11
+ * improve error messages with line, row, context
12
+ * add Quandl::Error::Standard, all errors inherit from Error::Standard
13
+
14
+
15
+ ## 0.0.4
16
+
17
+ * remove quandl_data as a dependency
18
+
19
+
20
+ ## 0.0.3
21
+
22
+ * Add Quandl::Data as a add_runtime_dependency
23
+ * refactor Babelfish::Data to inherit from Quandl::Data
24
+ * refactor specs
25
+
26
+
27
+ ## 0.0.1
28
+
29
+ * replace Cleaner.process return clean_array, header with Quandl::Babelfish::Data.new( clean_array, headers: header )
30
+ * refactored error
31
+ * added header extraction support
30
32
  * init
@@ -1,44 +1,44 @@
1
- module Quandl
2
- module Babelfish
3
-
4
- class Chronometer
5
- class << self
6
-
7
- #return frequency and warning message if present
8
- def process(table)
9
- # guesses date frequency in a table
10
- return nil if table.nil? || table.size==0
11
- return 'daily' if table.size==1 #not enough , need more points
12
- freqs = []
13
- fmt = "%Y-%m"
14
- fmt = "%Y" if table[0][0].to_s !~ /-/
15
- fmt = "%Y-%m-%d" if table[0][0].to_s =~ /^.*-.*-.*$/
16
-
17
- table.each_index do |r|
18
- break if r==6 #first 6 record is enough to analyze
19
- if table[r+1].nil?
20
- break
21
- else
22
- diff = (Date.strptime(table[r+1][0].to_s, fmt) -
23
- Date.strptime(table[r][0].to_s, fmt)).to_i.abs
24
- if diff < 4
25
- freqs << 'daily'
26
- elsif diff < 10
27
- freqs << 'weekly'
28
- elsif diff < 60
29
- freqs << 'monthly'
30
- elsif diff < 200
31
- freqs << 'quarterly'
32
- else
33
- freqs << 'annual'
34
- end
35
- end
36
- end
37
- return freqs.sort_by { |e| freqs.count(e) }.reverse.first#, nil
38
- end
39
-
40
- end
41
- end
42
-
43
- end
1
+ module Quandl
2
+ module Babelfish
3
+
4
+ class Chronometer
5
+ class << self
6
+
7
+ #return frequency and warning message if present
8
+ def process(table)
9
+ # guesses date frequency in a table
10
+ return nil if table.nil? || table.size==0
11
+ return 'daily' if table.size==1 #not enough , need more points
12
+ freqs = []
13
+ fmt = "%Y-%m"
14
+ fmt = "%Y" if table[0][0].to_s !~ /-/
15
+ fmt = "%Y-%m-%d" if table[0][0].to_s =~ /^.*-.*-.*$/
16
+
17
+ table.each_index do |r|
18
+ break if r==6 #first 6 record is enough to analyze
19
+ if table[r+1].nil?
20
+ break
21
+ else
22
+ diff = (Date.strptime(table[r+1][0].to_s, fmt) -
23
+ Date.strptime(table[r][0].to_s, fmt)).to_i.abs
24
+ if diff < 4
25
+ freqs << 'daily'
26
+ elsif diff < 10
27
+ freqs << 'weekly'
28
+ elsif diff < 60
29
+ freqs << 'monthly'
30
+ elsif diff < 200
31
+ freqs << 'quarterly'
32
+ else
33
+ freqs << 'annual'
34
+ end
35
+ end
36
+ end
37
+ return freqs.sort_by { |e| freqs.count(e) }.reverse.first#, nil
38
+ end
39
+
40
+ end
41
+ end
42
+
43
+ end
44
44
  end
@@ -1,33 +1,33 @@
1
- module Quandl
2
- module Babelfish
3
-
4
- class Cleaner
5
- class << self
6
- def process(dirty_array, date_settings={}, number_settings={})
7
- return nil,nil if dirty_array.nil?
8
-
9
- #check if first line is header
10
- header=DateMaid::disinfect(dirty_array.shift) unless DateMaid::analyze_date_format(DateMaid::disinfect(dirty_array[0][0])[0])[0]
11
-
12
- #converts dates first
13
- dirty_array
14
- dates = dirty_array.collect{|x| x[0]}
15
- DateMaid::init(date_settings)
16
- clean_dates=DateMaid::sweep dates
17
-
18
- clean_array=[]
19
- #clean numbers later
20
- NumberMaid::init(number_settings)
21
- dirty_array.each.with_index do |row, i|
22
- new_row=[]
23
- (new_row << clean_dates[i]).concat Array(NumberMaid::clean(row[1..-1])) #add clean date and all clean numbers
24
- clean_array << new_row
25
- end
26
-
27
- return clean_array, header
28
- end
29
- end
30
- end
31
-
32
- end
1
+ module Quandl
2
+ module Babelfish
3
+
4
+ class Cleaner
5
+ class << self
6
+ def process(dirty_array, date_settings={}, number_settings={})
7
+ return nil,nil if dirty_array.nil?
8
+
9
+ #check if first line is header
10
+ header=DateMaid::disinfect(dirty_array.shift) unless DateMaid::analyze_date_format(DateMaid::disinfect(dirty_array[0][0])[0])[0]
11
+
12
+ #converts dates first
13
+ dirty_array
14
+ dates = dirty_array.collect{|x| x[0]}
15
+ DateMaid::init(date_settings)
16
+ clean_dates=DateMaid::sweep dates
17
+
18
+ clean_array=[]
19
+ #clean numbers later
20
+ NumberMaid::init(number_settings)
21
+ dirty_array.each.with_index do |row, i|
22
+ new_row=[]
23
+ (new_row << clean_dates[i]).concat Array(NumberMaid::clean(row[1..-1])) #add clean date and all clean numbers
24
+ clean_array << new_row
25
+ end
26
+
27
+ return Helper::make_square(clean_array), header
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
33
  end