quandl_data 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/UPGRADE.md +5 -1
- data/lib/quandl/data/random.rb +3 -88
- data/lib/quandl/data/version.rb +1 -1
- data/lib/quandl/data.rb +1 -1
- data/lib/quandl/fabricate/data.rb +101 -0
- data/lib/quandl/fabricate.rb +6 -0
- data/spec/lib/fabricate/data_spec.rb +23 -0
- data/spec/{quandl → lib/quandl}/data_spec.rb +0 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -4
data/README.md
CHANGED
@@ -14,13 +14,13 @@ table.collapse(:monthly).transform(:rdiff).to_date
|
|
14
14
|
```
|
15
15
|
|
16
16
|
|
17
|
-
### Quandl::Data::
|
17
|
+
### Quandl::Fabricate::Data::Table
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
|
21
|
-
require 'quandl/data'
|
21
|
+
require 'quandl/fabricate/data'
|
22
22
|
|
23
|
-
data = Quandl::Data::
|
23
|
+
data = Quandl::Fabricate::Data::Table.rand( rows: 4, columns: 2, nils: false )
|
24
24
|
data.to_csv
|
25
25
|
|
26
26
|
=> "2456459,9.75573946698621,11.003327581245657\n2456460,9.815208080651333,11.06123640714187\n2456461,9.85055418685121,11.054083764705883\n2456462,9.915882352941177,10.96635294117647\n"
|
data/UPGRADE.md
CHANGED
data/lib/quandl/data/random.rb
CHANGED
@@ -4,95 +4,10 @@ module Quandl
|
|
4
4
|
module Data
|
5
5
|
|
6
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
7
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
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
|
8
|
+
def self.table(*args)
|
9
|
+
warn "[DEPRECATION] `Quandl::Data::Random.table` is deprecated. Please use `Quandl::Fabricate::Data::Table` instead."
|
10
|
+
Quandl::Fabricate::Data::Table.rand(*args)
|
96
11
|
end
|
97
12
|
|
98
13
|
end
|
data/lib/quandl/data/version.rb
CHANGED
data/lib/quandl/data.rb
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Fabricate
|
3
|
+
module Data
|
4
|
+
|
5
|
+
class Table
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def rand(*args)
|
10
|
+
new(*args).random
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :attributes, :offset, :rows, :columns, :frequency, :data, :nils
|
16
|
+
|
17
|
+
def initialize(*args)
|
18
|
+
self.attributes = default_options.merge args.extract_options!
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_csv(*args)
|
22
|
+
data.collect(&:to_csv).join
|
23
|
+
end
|
24
|
+
|
25
|
+
def random_column
|
26
|
+
self.columns = 1
|
27
|
+
random
|
28
|
+
end
|
29
|
+
|
30
|
+
def random
|
31
|
+
data = []
|
32
|
+
index = 0
|
33
|
+
until data.count >= rows
|
34
|
+
data << row(index) unless nils
|
35
|
+
index += 1
|
36
|
+
end
|
37
|
+
Quandl::Data::Table.new( data ).sort_descending
|
38
|
+
end
|
39
|
+
|
40
|
+
def row(index)
|
41
|
+
row = [ date(index) ]
|
42
|
+
columns.times{|column_index| row << point(index, column_index) }
|
43
|
+
row
|
44
|
+
end
|
45
|
+
|
46
|
+
def date(index)
|
47
|
+
(Date.today - ( index * ( frequencies[frequency] ) - offset )).jd
|
48
|
+
end
|
49
|
+
|
50
|
+
def point(row_index, column_index)
|
51
|
+
percent = ( (rand(10).to_f / 1000) ) - ( (rand(10).to_f / 850) ) + 1
|
52
|
+
# increase the value
|
53
|
+
trending_point[column_index] ||= column_index * column_index + 10
|
54
|
+
trending_point[column_index] = trending_point[column_index] * percent
|
55
|
+
# increase
|
56
|
+
nils ? nil : trending_point[column_index]
|
57
|
+
end
|
58
|
+
|
59
|
+
def trending_point
|
60
|
+
@trending_point ||= {}
|
61
|
+
end
|
62
|
+
|
63
|
+
def nils
|
64
|
+
@nils == false ? false : rand(6) == 1
|
65
|
+
end
|
66
|
+
|
67
|
+
def frequencies
|
68
|
+
{daily: 1, weekly: 7, monthly: 30, quarterly: 90, annual: 365}
|
69
|
+
end
|
70
|
+
|
71
|
+
def default_options
|
72
|
+
{
|
73
|
+
offset: 1,
|
74
|
+
rows: 20 + rand(100),
|
75
|
+
columns: 2 + rand(4),
|
76
|
+
frequency: :daily,
|
77
|
+
monkey: 6
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def attributes
|
82
|
+
@attributes ||= {}
|
83
|
+
end
|
84
|
+
|
85
|
+
def attributes=(attrs)
|
86
|
+
assign_attributes(attrs)
|
87
|
+
attributes
|
88
|
+
end
|
89
|
+
|
90
|
+
# mass assignment protection
|
91
|
+
def assign_attributes(attrs)
|
92
|
+
attrs.each do |name, value|
|
93
|
+
self.send("#{name}=", value) if self.respond_to?("#{name}=")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Fabricate::Data::Table do
|
5
|
+
|
6
|
+
let(:data){ Quandl::Fabricate::Data::Table.rand( rows: 4, columns: 5, nils: false ) }
|
7
|
+
subject{ data }
|
8
|
+
|
9
|
+
it{ should be_a Quandl::Data::Table }
|
10
|
+
its(:count){ should eq 4 }
|
11
|
+
|
12
|
+
describe "#first" do
|
13
|
+
subject{ data.first }
|
14
|
+
its(:count){ should eq 6 }
|
15
|
+
|
16
|
+
its([0]){ should be_a Integer }
|
17
|
+
|
18
|
+
[1,2,3,4,5].each do |i|
|
19
|
+
its([i]){ should be_a Float }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -145,8 +145,11 @@ files:
|
|
145
145
|
- lib/quandl/data/table/loggable.rb
|
146
146
|
- lib/quandl/data/table/operations.rb
|
147
147
|
- lib/quandl/data/version.rb
|
148
|
+
- lib/quandl/fabricate.rb
|
149
|
+
- lib/quandl/fabricate/data.rb
|
148
150
|
- quandl_data.gemspec
|
149
|
-
- spec/
|
151
|
+
- spec/lib/fabricate/data_spec.rb
|
152
|
+
- spec/lib/quandl/data_spec.rb
|
150
153
|
- spec/spec_helper.rb
|
151
154
|
homepage: http://blake.hilscher.ca/
|
152
155
|
licenses:
|
@@ -174,5 +177,6 @@ signing_key:
|
|
174
177
|
specification_version: 3
|
175
178
|
summary: For interfacing with data
|
176
179
|
test_files:
|
177
|
-
- spec/
|
180
|
+
- spec/lib/fabricate/data_spec.rb
|
181
|
+
- spec/lib/quandl/data_spec.rb
|
178
182
|
- spec/spec_helper.rb
|