quandl_babelfish 0.0.5 → 0.0.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/UPGRADE.md +6 -0
- data/lib/quandl/babelfish.rb +6 -0
- data/lib/quandl/babelfish/chronometer.rb +44 -0
- data/lib/quandl/babelfish/version.rb +1 -1
- data/spec/lib/quandl/babelfish/chronometer_spec.rb +51 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e1ec77b75eed3bc2b3be144ff782fa873f2e29
|
4
|
+
data.tar.gz: 6dd9ada8a25d09604ea51cb5ef4e5e02dc500f2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49ab0ab69e7023843dc2309220df05f778774d6c6060afc3f330b82bf981c3c208e4cc3b5f61c0d849174a8e10c03176c67854ba1b56af8145c9cf496231f84d
|
7
|
+
data.tar.gz: fa8027cb6a693b7362575f60bc022998997b2ff3367c61c5a8cb9d2895a14932cce2a27eccbead473b9bec7ae1e6978276d770faace7a29f9b95c467363060cd
|
data/UPGRADE.md
CHANGED
data/lib/quandl/babelfish.rb
CHANGED
@@ -3,6 +3,7 @@ require "quandl/babelfish/version"
|
|
3
3
|
require "quandl/babelfish/cleaner"
|
4
4
|
require "quandl/babelfish/date_maid"
|
5
5
|
require "quandl/babelfish/number_maid"
|
6
|
+
require "quandl/babelfish/chronometer"
|
6
7
|
|
7
8
|
require 'quandl/error/standard'
|
8
9
|
require 'quandl/error/guess_date_format'
|
@@ -16,6 +17,11 @@ module Babelfish
|
|
16
17
|
def clean(data, date_settings={}, number_settings={})
|
17
18
|
Cleaner::process data, date_settings, number_settings
|
18
19
|
end
|
20
|
+
|
21
|
+
def guess_frequency(data)
|
22
|
+
Chronometer::process data
|
23
|
+
end
|
24
|
+
|
19
25
|
end
|
20
26
|
|
21
27
|
end
|
@@ -0,0 +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
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Quandl::Babelfish
|
4
|
+
describe Chronometer do
|
5
|
+
|
6
|
+
it 'should calculate frequency = daily' do
|
7
|
+
table = [['2012-01-01','1','2'],['2012-01-02','3','4'],['2012-01-03','5','6']]
|
8
|
+
frequency = Chronometer.process(table)
|
9
|
+
frequency.should == 'daily'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should calculate frequency = monthly' do
|
13
|
+
table = [['2012-01-01','1','2'],['2012-02-01','3','4'],['2012-04-01','5','6'],
|
14
|
+
['2012-04-01','1','2'],['2012-05-01','3','4'],['2012-06-01','5','6']]
|
15
|
+
frequency = Chronometer.process(table)
|
16
|
+
frequency.should == 'monthly'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should calculate frequency = quarterly' do
|
20
|
+
table = [['2012-01-01','1','2'],['2012-04-01','3','4'],['2012-07-01','5','6'],
|
21
|
+
['2012-10-01','1','2'],['2013-01-01','3','4'],['2012-04-01','5','6']]
|
22
|
+
frequency = Chronometer.process(table)
|
23
|
+
frequency.should == 'quarterly'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should calculate frequency = quarterly' do
|
27
|
+
table = [['2012-01-01','1','2'],['2012-07-01','3','4'],['2013-01-01','5','6'],
|
28
|
+
['2013-07-01','1','2']]
|
29
|
+
frequency = Chronometer.process(table)
|
30
|
+
frequency.should == 'quarterly'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should calculate frequency = annual' do
|
34
|
+
table = [['2008-01-01','1','2'],['2008-12-01','3','4'],['2010-01-01','5','6'],
|
35
|
+
['2011-01-01','1','2'],['2013-01-01','5','6']]
|
36
|
+
frequency = Chronometer.process(table)
|
37
|
+
frequency.should == 'annual'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should calculate frequency = daily if only one row' do
|
41
|
+
table = [['2010-01-01','1','2']]
|
42
|
+
frequency = Chronometer.process(table)
|
43
|
+
frequency.should == 'daily'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should calculate frequency = nil if nil table passed' do
|
47
|
+
frequency = Chronometer.process(nil)
|
48
|
+
frequency.should == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_babelfish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Ryshkevich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- UPGRADE.md
|
54
54
|
- lib/quandl/babelfish.rb
|
55
|
+
- lib/quandl/babelfish/chronometer.rb
|
55
56
|
- lib/quandl/babelfish/cleaner.rb
|
56
57
|
- lib/quandl/babelfish/date_maid.rb
|
57
58
|
- lib/quandl/babelfish/number_maid.rb
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- lib/quandl/error/standard.rb
|
62
63
|
- lib/quandl/error/unknown_date_format.rb
|
63
64
|
- quandl_babelfish.gemspec
|
65
|
+
- spec/lib/quandl/babelfish/chronometer_spec.rb
|
64
66
|
- spec/lib/quandl/babelfish/cleaner_spec.rb
|
65
67
|
- spec/lib/quandl/babelfish/date_maid_spec.rb
|
66
68
|
- spec/lib/quandl/babelfish/number_maid_spec.rb
|
@@ -92,6 +94,7 @@ signing_key:
|
|
92
94
|
specification_version: 4
|
93
95
|
summary: Quandl Data Cleaner
|
94
96
|
test_files:
|
97
|
+
- spec/lib/quandl/babelfish/chronometer_spec.rb
|
95
98
|
- spec/lib/quandl/babelfish/cleaner_spec.rb
|
96
99
|
- spec/lib/quandl/babelfish/date_maid_spec.rb
|
97
100
|
- spec/lib/quandl/babelfish/number_maid_spec.rb
|