quandl_cassandra_models 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +10 -0
- data/UPGRADE.md +7 -0
- data/lib/quandl/cassandra/models/column/read/offset.rb +7 -2
- data/lib/quandl/cassandra/models/column.rb +3 -3
- data/lib/quandl/cassandra/models/dataset/columns.rb +8 -1
- data/lib/quandl/cassandra/models/version.rb +1 -1
- data/quandl_cassandra_models.gemspec +2 -0
- data/spec/lib/quandl/cassandra/models/column_spec.rb +43 -0
- data/spec/lib/quandl/cassandra/models/dataset/columns_spec.rb +24 -0
- data/spec/spec_helper.rb +2 -0
- metadata +33 -4
- data/spec/lib/quandl/cassandra/models/dataset/column_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dba8a80af70ec60a10f0214ab262a68aff64dee
|
4
|
+
data.tar.gz: b425b1bfaba56bbccda9e859b92eb3635c119770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc80a451921d95abbf80c0555e816c2338b9b3567b8e1dbff8b75653cfa363eef3c1b6981d4b55c69fb714b9157873c717a3b3e1c4aae638f673357533c040bf
|
7
|
+
data.tar.gz: 54eea88045fd66edb7702aff58338283cd599a396b9726a45cb47f2b48d10ed3f721d134cbd21d6ebbb72374b7c4b8932a94f5f7a2e8f62a56f2159a7cd22ce9
|
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
group :specs do
|
5
|
+
guard :rspec, :cli => '--color --format doc --fail-fast' do
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
7
|
+
watch(%r{^(lib/.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
9
|
+
end
|
10
|
+
end
|
data/UPGRADE.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
class Quandl::Cassandra::Models::Column::Read::Offset < Quandl::Cassandra::Models::Column::Read
|
2
2
|
|
3
3
|
def perform
|
4
|
-
#
|
5
|
-
return unless
|
4
|
+
# skip strategy unless all required attriutes are present
|
5
|
+
return unless required_attributes_present?
|
6
|
+
# apply strategy
|
6
7
|
apply_offset_with_transform
|
7
8
|
apply_offset
|
8
9
|
end
|
9
10
|
|
11
|
+
def required_attributes_present?
|
12
|
+
column_ids.present? && trim_start.is_a?(Date) && trim_end.is_a?(Date)
|
13
|
+
end
|
14
|
+
|
10
15
|
def apply_offset_with_transform
|
11
16
|
# rdiff_from needs the data from the current to offset
|
12
17
|
if attributes[:row].present? && attributes[:transform] == :rdiff_from
|
@@ -25,16 +25,16 @@ class Quandl::Cassandra::Models::Column < Quandl::Cassandra::Base
|
|
25
25
|
def find_max_time_by_ids_and_collapses(ids, collapses, order)
|
26
26
|
# otherwise lookup each column seperately
|
27
27
|
times = []
|
28
|
-
|
28
|
+
ids.each_with_index do |id, index|
|
29
29
|
column_collapse = collapses[index]
|
30
30
|
next if column_collapse.blank?
|
31
|
-
times << limit(1).order("type #{order}, time #{order}").where( id: id, type:
|
31
|
+
times << limit(1).order("type #{order}, time #{order}").where( id: id, type: column_collapse ).select(:time, :type).to_a[0].try(:[], 'time')
|
32
32
|
end
|
33
33
|
times.flatten.max
|
34
34
|
end
|
35
35
|
|
36
36
|
def find_max_time_by_ids_and_collapse(ids, collapse, order)
|
37
|
-
limit(1).order("type #{order}, time #{order}").where( id: ids, type: collapse ).select(:time, :type).to_a[0]['time'
|
37
|
+
limit(1).order("type #{order}, time #{order}").where( id: ids, type: collapse ).select(:time, :type).to_a[0].try(:[], 'time')
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -23,8 +23,12 @@ module Quandl::Cassandra::Models::Dataset::Columns
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def column_frequencies
|
27
|
+
@column_frequencies ||= columns.collect(&:frequency)
|
28
|
+
end
|
29
|
+
|
26
30
|
def column_units
|
27
|
-
@column_units ||= columns.collect(&:
|
31
|
+
@column_units ||= columns.collect(&:units)
|
28
32
|
end
|
29
33
|
|
30
34
|
def column_names
|
@@ -51,6 +55,9 @@ module Quandl::Cassandra::Models::Dataset::Columns
|
|
51
55
|
def clear_attributes!
|
52
56
|
@columns = nil
|
53
57
|
@column_ids = nil
|
58
|
+
@column_frequencies = nil
|
59
|
+
@column_names = nil
|
60
|
+
@column_units = nil
|
54
61
|
end
|
55
62
|
|
56
63
|
|
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "factory_girl_rails"
|
23
23
|
s.add_development_dependency "fivemat", "~> 1.2"
|
24
24
|
s.add_development_dependency "pry"
|
25
|
+
s.add_development_dependency "guard"
|
26
|
+
s.add_development_dependency "guard-rspec"
|
25
27
|
|
26
28
|
s.add_runtime_dependency "quandl_cassandra", "~> 1.1"
|
27
29
|
|
@@ -6,12 +6,55 @@ describe Quandl::Cassandra::Models::Column do
|
|
6
6
|
let(:data){ Quandl::Fabricate::Data.rand( rows: 10, columns: 2, nils: false ) }
|
7
7
|
let(:dataset){ Quandl::Cassandra::Models::Dataset.create( id: id, data: data ) }
|
8
8
|
|
9
|
+
let(:column_ids){ dataset.column_ids }
|
10
|
+
let(:collapses){ ['source', 'source'] }
|
11
|
+
let(:column_order){ :desc }
|
12
|
+
|
9
13
|
describe ".read" do
|
10
14
|
before(:each){ Quandl::Cassandra::Models::Column.write( id: id, data: data ); sleep(0.2) }
|
11
15
|
|
12
16
|
subject{ Quandl::Cassandra::Models::Column.read( id: id ) }
|
13
17
|
its(:count){ should eq 10 }
|
14
18
|
it{ should eq data }
|
19
|
+
|
20
|
+
context "offset with missing data" do
|
21
|
+
before(:each){ dataset.data.scoped.delete_all }
|
22
|
+
subject{ Quandl::Cassandra::Models::Column.read( id: id, offset: 20 ) }
|
23
|
+
its(:count){ should eq 0 }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".find_max_time_by_ids" do
|
29
|
+
let(:data){ Quandl::Fabricate::Data.rand( rows: 2, columns: 2, nils: false ) }
|
30
|
+
subject{ Quandl::Cassandra::Models::Column.find_max_time_by_ids(column_ids, collapses, column_order) }
|
31
|
+
|
32
|
+
it{ should be_a Date }
|
33
|
+
it{ should eq dataset.data.scoped.to_table.to_date.first.first }
|
34
|
+
|
35
|
+
context "asc order" do
|
36
|
+
let(:column_order){ :asc }
|
37
|
+
it{ should be_a Date }
|
38
|
+
it{ should eq dataset.data.scoped.to_table.to_date.last.first }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "invalid collapse" do
|
42
|
+
let(:collapses){ ['invalid', 'invalid'] }
|
43
|
+
it{ should be_nil }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".find_max_time_by_ids_and_collapses" do
|
49
|
+
subject{ Quandl::Cassandra::Models::Column.find_max_time_by_ids_and_collapses(column_ids, collapses, column_order) }
|
50
|
+
it{ should be_a Integer }
|
51
|
+
it{ should eq dataset.data.scoped.to_table.first.first }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".find_max_time_by_ids_and_collapse" do
|
55
|
+
subject{ Quandl::Cassandra::Models::Column.find_max_time_by_ids_and_collapse(column_ids, collapses.first, column_order) }
|
56
|
+
it{ should be_a Integer }
|
57
|
+
it{ should eq dataset.data.scoped.to_table.first.first }
|
15
58
|
end
|
16
59
|
|
17
60
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Quandl::Cassandra::Models::Dataset::Columns do
|
5
|
+
|
6
|
+
subject { create(:dataset, data: Quandl::Fabricate::Data.rand( rows: 10, columns: 4, nils: false, frequency: :quarterly ) ) }
|
7
|
+
|
8
|
+
its(:column_frequencies){ should eq 4.times.collect{'quarterly'} }
|
9
|
+
its(:column_units){ should eq 4.times.collect{nil} }
|
10
|
+
its(:column_names){ should eq 4.times.collect{nil} }
|
11
|
+
|
12
|
+
it "should return first column" do
|
13
|
+
subject.data.column(1)[0][1].should eq subject.data.scoped.to_table[0][1]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return second column" do
|
17
|
+
subject.data.column(2)[0][1].should eq subject.data.scoped.to_table[0][2]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return third column" do
|
21
|
+
subject.data.column(2)[0][1].should eq subject.data.scoped.to_table[0][2]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_cassandra_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
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-11-
|
11
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: quandl_cassandra
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,6 +131,7 @@ extra_rdoc_files: []
|
|
103
131
|
files:
|
104
132
|
- .gitignore
|
105
133
|
- Gemfile
|
134
|
+
- Guardfile
|
106
135
|
- LICENSE
|
107
136
|
- README.md
|
108
137
|
- Rakefile
|
@@ -149,7 +178,7 @@ files:
|
|
149
178
|
- spec/lib/quandl/cassandra/models/column_spec.rb
|
150
179
|
- spec/lib/quandl/cassandra/models/data_spec.rb
|
151
180
|
- spec/lib/quandl/cassandra/models/dataset/collapse_spec.rb
|
152
|
-
- spec/lib/quandl/cassandra/models/dataset/
|
181
|
+
- spec/lib/quandl/cassandra/models/dataset/columns_spec.rb
|
153
182
|
- spec/lib/quandl/cassandra/models/dataset/persistence_spec.rb
|
154
183
|
- spec/lib/quandl/cassandra/models/dataset/row_spec.rb
|
155
184
|
- spec/lib/quandl/cassandra/models/dataset/transform_spec.rb
|
@@ -198,7 +227,7 @@ test_files:
|
|
198
227
|
- spec/lib/quandl/cassandra/models/column_spec.rb
|
199
228
|
- spec/lib/quandl/cassandra/models/data_spec.rb
|
200
229
|
- spec/lib/quandl/cassandra/models/dataset/collapse_spec.rb
|
201
|
-
- spec/lib/quandl/cassandra/models/dataset/
|
230
|
+
- spec/lib/quandl/cassandra/models/dataset/columns_spec.rb
|
202
231
|
- spec/lib/quandl/cassandra/models/dataset/persistence_spec.rb
|
203
232
|
- spec/lib/quandl/cassandra/models/dataset/row_spec.rb
|
204
233
|
- spec/lib/quandl/cassandra/models/dataset/transform_spec.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Quandl::Cassandra::Models::Dataset do
|
5
|
-
|
6
|
-
context "column" do
|
7
|
-
|
8
|
-
subject { create(:dataset) }
|
9
|
-
|
10
|
-
it "should return first column" do
|
11
|
-
subject.data.column(1)[0][1].should eq subject.data.scoped.to_table[0][1]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return second column" do
|
15
|
-
subject.data.column(2)[0][1].should eq subject.data.scoped.to_table[0][2]
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return third column" do
|
19
|
-
subject.data.column(2)[0][1].should eq subject.data.scoped.to_table[0][2]
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|