quandl_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.travis.yml +20 -0
- data/.yardopts +2 -0
- data/Gemfile +2 -0
- data/LICENSE +7 -0
- data/README.md +1 -0
- data/Rakefile +11 -0
- data/UPGRADE.md +3 -0
- data/lib/quandl/data/random.rb +101 -0
- data/lib/quandl/data/table/operations.rb +109 -0
- data/lib/quandl/data/table.rb +44 -0
- data/lib/quandl/data/version.rb +5 -0
- data/lib/quandl/data.rb +16 -0
- data/quandl_data.gemspec +26 -0
- data/spec/quandl_data.rb +28 -0
- data/spec/spec_helper.rb +4 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b82905af7563344474ade78afcce832343508302
|
4
|
+
data.tar.gz: 624de4e651cfab921af731df00bb72c94ba3f98e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51837e3e38ee917e5768aecbd8dde6033e080fc8b7181da95994a48e4776b1a9144915c5403464bcb0b350bf48ffec4d51946cdcbe22f13c1663b7693ea5f6ba
|
7
|
+
data.tar.gz: 03a3e69dc9c625df5935fdcd3b4d13a4c2ac9d2aa9994163ecabb36bf1afee1bb1ce728ecd43ad3f1c2ebfc5e498a885aa188e43a93afaa35c9a86b4aba8cc74
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format=Fivemat
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 1.9.3
|
6
|
+
- 1.9.2
|
7
|
+
- 1.8.7
|
8
|
+
|
9
|
+
gemfile:
|
10
|
+
- Gemfile
|
11
|
+
- gemfiles/activemodel-4.0.gemfile
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 1.8.7
|
16
|
+
gemfile: gemfiles/activemodel-4.0.gemfile
|
17
|
+
- rvm: 1.9.2
|
18
|
+
gemfile: gemfiles/activemodel-4.0.gemfile
|
19
|
+
|
20
|
+
script: "echo 'COME ON!' && bundle exec rake spec"
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012-2013 Blake Hilscher
|
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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Quandl::Data
|
data/Rakefile
ADDED
data/UPGRADE.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'quandl/data/table/operations'
|
2
|
+
|
3
|
+
module Quandl
|
4
|
+
module Data
|
5
|
+
|
6
|
+
class Random
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def table(*args)
|
11
|
+
new(*args).random
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :attributes, :offset, :rows, :columns, :frequency, :data, :nils
|
17
|
+
|
18
|
+
def initialize(*args)
|
19
|
+
self.attributes = default_options.merge args.extract_options!
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_csv(*args)
|
23
|
+
data.collect(&:to_csv).join
|
24
|
+
end
|
25
|
+
|
26
|
+
def random_column
|
27
|
+
self.columns = 1
|
28
|
+
random
|
29
|
+
end
|
30
|
+
|
31
|
+
def random
|
32
|
+
data = []
|
33
|
+
index = 0
|
34
|
+
until data.count >= rows
|
35
|
+
data << row(index) unless nils
|
36
|
+
index += 1
|
37
|
+
end
|
38
|
+
Quandl::Data::Table.new( data ).sort_descending
|
39
|
+
end
|
40
|
+
|
41
|
+
def row(index)
|
42
|
+
row = [ date(index) ]
|
43
|
+
columns.times{|column_index| row << point(index, column_index) }
|
44
|
+
row
|
45
|
+
end
|
46
|
+
|
47
|
+
def date(index)
|
48
|
+
(Date.today - ( index * ( frequencies[frequency] ) - offset )).jd
|
49
|
+
end
|
50
|
+
|
51
|
+
def point(row_index, column_index)
|
52
|
+
percent = ( (rand(10).to_f / 1000) ) - ( (rand(10).to_f / 850) ) + 1
|
53
|
+
# increase the value
|
54
|
+
trending_point[column_index] ||= column_index * column_index + 10
|
55
|
+
trending_point[column_index] = trending_point[column_index] * percent
|
56
|
+
# increase
|
57
|
+
nils ? nil : trending_point[column_index]
|
58
|
+
end
|
59
|
+
|
60
|
+
def trending_point
|
61
|
+
@trending_point ||= {}
|
62
|
+
end
|
63
|
+
|
64
|
+
def nils
|
65
|
+
@nils == false ? false : rand(6) == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
def frequencies
|
69
|
+
{daily: 1, weekly: 7, monthly: 30, quarterly: 90, annual: 365}
|
70
|
+
end
|
71
|
+
|
72
|
+
def default_options
|
73
|
+
{
|
74
|
+
offset: 1,
|
75
|
+
rows: 20 + rand(100),
|
76
|
+
columns: 2 + rand(4),
|
77
|
+
frequency: :daily,
|
78
|
+
monkey: 6
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def attributes
|
83
|
+
@attributes ||= {}
|
84
|
+
end
|
85
|
+
|
86
|
+
def attributes=(attrs)
|
87
|
+
assign_attributes(attrs)
|
88
|
+
attributes
|
89
|
+
end
|
90
|
+
|
91
|
+
# mass assignment protection
|
92
|
+
def assign_attributes(attrs)
|
93
|
+
attrs.each do |name, value|
|
94
|
+
self.send("#{name}=", value) if self.respond_to?("#{name}=")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Data
|
3
|
+
class Table
|
4
|
+
|
5
|
+
module Operations
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include Quandl::Operation
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def forwardable_methods
|
13
|
+
@forwardable_methods ||= (operations + operations.collect{|o| "#{o}!" if method_defined?("#{o}!") }).compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def operations
|
17
|
+
[
|
18
|
+
:to_csv, :to_jd, :to_date, :sort_order, :sort_ascending,
|
19
|
+
:sort_descending, :transform, :collapse, :frequency, :parse
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h
|
26
|
+
data_array.inject({}) do |memo, row|
|
27
|
+
memo[row[0]] = row[1..-1]
|
28
|
+
memo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_csv
|
33
|
+
data_array.collect(&:to_csv).join
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_jd
|
37
|
+
Table.new( Parse.date_to_julian( data_array ), frequency: frequency )
|
38
|
+
end
|
39
|
+
def to_jd!
|
40
|
+
@data_array = Parse.date_to_julian( data_array )
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_date
|
45
|
+
Parse.julian_to_date data_array
|
46
|
+
end
|
47
|
+
def to_date!
|
48
|
+
@data_array = Parse.julian_to_date data_array
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def sort_order(dir)
|
53
|
+
dir == :asc ? sort_ascending! : sort_descending!
|
54
|
+
end
|
55
|
+
|
56
|
+
def sort_ascending
|
57
|
+
Table.new( Parse.sort( data_array, :asc ), frequency: frequency )
|
58
|
+
end
|
59
|
+
def sort_ascending!
|
60
|
+
@data_array = Parse.sort( data_array, :asc )
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def sort_descending
|
65
|
+
Table.new( Parse.sort( data_array, :desc ), frequency: frequency )
|
66
|
+
end
|
67
|
+
def sort_descending!
|
68
|
+
@data_array = Parse.sort( data_array, :desc )
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def transform(*args)
|
73
|
+
return @transform unless args.first.present?
|
74
|
+
self.transform = args.first
|
75
|
+
self
|
76
|
+
end
|
77
|
+
def transform=(value)
|
78
|
+
@transform = value
|
79
|
+
@data_array = Transform.perform( data_array, value )
|
80
|
+
end
|
81
|
+
|
82
|
+
def collapse(*args)
|
83
|
+
return @collapse unless args.first.present?
|
84
|
+
self.collapse = args.first
|
85
|
+
self
|
86
|
+
end
|
87
|
+
def collapse=(collapse)
|
88
|
+
@collapse = collapse
|
89
|
+
@frequency = collapse
|
90
|
+
@data_array = Collapse.perform( data_array, collapse )
|
91
|
+
end
|
92
|
+
|
93
|
+
def frequency
|
94
|
+
@frequency ||= Collapse.frequency?( data_array )
|
95
|
+
end
|
96
|
+
def frequency=(value)
|
97
|
+
@frequency = value.to_sym
|
98
|
+
end
|
99
|
+
|
100
|
+
def parse(data)
|
101
|
+
data = Parse.perform( data )
|
102
|
+
data
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'quandl/data/table/operations'
|
2
|
+
|
3
|
+
module Quandl
|
4
|
+
module Data
|
5
|
+
|
6
|
+
class Table
|
7
|
+
|
8
|
+
include Operations
|
9
|
+
|
10
|
+
delegate *Array.forwardable_methods, to: :data_array
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
data = args.first
|
14
|
+
self.attributes = args.extract_options!
|
15
|
+
self.data_array = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def data_array
|
19
|
+
@data_array ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def data_array=(data)
|
23
|
+
@data_array = parse(data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def attributes
|
27
|
+
@attributes ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def attributes=(attrs)
|
31
|
+
assign_attributes(attrs)
|
32
|
+
attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
# mass assignment protection
|
36
|
+
def assign_attributes(attrs)
|
37
|
+
attrs.each do |name, value|
|
38
|
+
self.send("#{name}=", value) if self.respond_to?("#{name}=")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/quandl/data.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "quandl/data/version"
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/inflector"
|
5
|
+
require "active_support/core_ext/hash"
|
6
|
+
require "active_support/core_ext/object"
|
7
|
+
|
8
|
+
require "quandl/operation"
|
9
|
+
|
10
|
+
require 'quandl/data/table'
|
11
|
+
require 'quandl/data/random'
|
12
|
+
|
13
|
+
module Quandl
|
14
|
+
module Data
|
15
|
+
end
|
16
|
+
end
|
data/quandl_data.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "quandl/data/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "quandl_data"
|
7
|
+
s.version = Quandl::Data::VERSION
|
8
|
+
s.authors = ["Blkae Hilscher"]
|
9
|
+
s.email = ["blake@hilscher.ca"]
|
10
|
+
s.homepage = "http://blake.hilscher.ca/"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.summary = "For interfacing with data"
|
13
|
+
s.description = "Data will be interfaced"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rake", "~> 10.0"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.13"
|
22
|
+
s.add_development_dependency "fivemat", "~> 1.2"
|
23
|
+
|
24
|
+
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
25
|
+
s.add_runtime_dependency "quandl_operation", "~> 0.0.3"
|
26
|
+
end
|
data/spec/quandl_data.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Data::Table do
|
5
|
+
subject { Quandl::Data::Random.table( nils: false, rows: 4, columns: 4 ) }
|
6
|
+
|
7
|
+
its(:to_csv){ should be_a String }
|
8
|
+
its(:to_h){ should be_a Hash }
|
9
|
+
its(:count){ should eq 4 }
|
10
|
+
|
11
|
+
it "should parse csv" do
|
12
|
+
Quandl::Data::Table.new(subject.to_csv).count.should eq 4
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should transform the data" do
|
16
|
+
value = subject.first[1]
|
17
|
+
subject.transform(:rdiff).first[1].should_not eq value
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should collapse the data" do
|
21
|
+
subject.collapse(:monthly).count.should eq 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should convert julian dates to dates" do
|
25
|
+
subject.to_date.first.first.should be_a Date
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quandl_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blkae Hilscher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fivemat
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: quandl_operation
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.3
|
83
|
+
description: Data will be interfaced
|
84
|
+
email:
|
85
|
+
- blake@hilscher.ca
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- .yardopts
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- UPGRADE.md
|
99
|
+
- lib/quandl/data.rb
|
100
|
+
- lib/quandl/data/random.rb
|
101
|
+
- lib/quandl/data/table.rb
|
102
|
+
- lib/quandl/data/table/operations.rb
|
103
|
+
- lib/quandl/data/version.rb
|
104
|
+
- quandl_data.gemspec
|
105
|
+
- spec/quandl_data.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: http://blake.hilscher.ca/
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.0.3
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: For interfacing with data
|
131
|
+
test_files:
|
132
|
+
- spec/quandl_data.rb
|
133
|
+
- spec/spec_helper.rb
|