quandl_cassandra 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/UPGRADE.md +6 -0
  2. data/lib/quandl/cassandra.rb +0 -7
  3. data/lib/quandl/cassandra/version.rb +1 -1
  4. data/spec/lib/quandl/cassandra/base/scoping_spec.rb +10 -10
  5. metadata +1 -61
  6. data/lib/quandl/cassandra_models/column.rb +0 -20
  7. data/lib/quandl/cassandra_models/column/read.rb +0 -32
  8. data/lib/quandl/cassandra_models/column/read/collapse.rb +0 -65
  9. data/lib/quandl/cassandra_models/column/read/column.rb +0 -19
  10. data/lib/quandl/cassandra_models/column/read/data.rb +0 -59
  11. data/lib/quandl/cassandra_models/column/read/offset.rb +0 -118
  12. data/lib/quandl/cassandra_models/column/read/row.rb +0 -20
  13. data/lib/quandl/cassandra_models/column/read/select_columns.rb +0 -60
  14. data/lib/quandl/cassandra_models/column/read/transform.rb +0 -53
  15. data/lib/quandl/cassandra_models/column/read/type.rb +0 -25
  16. data/lib/quandl/cassandra_models/column/write.rb +0 -22
  17. data/lib/quandl/cassandra_models/column/write/group_data_by_column.rb +0 -37
  18. data/lib/quandl/cassandra_models/column/write/group_data_by_frequency.rb +0 -24
  19. data/lib/quandl/cassandra_models/column/write/insert_column_attributes.rb +0 -20
  20. data/lib/quandl/cassandra_models/column/write/insert_columns.rb +0 -9
  21. data/lib/quandl/cassandra_models/column_attribute.rb +0 -11
  22. data/lib/quandl/cassandra_models/data.rb +0 -18
  23. data/lib/quandl/cassandra_models/data/search.rb +0 -104
  24. data/lib/quandl/cassandra_models/dataset.rb +0 -72
  25. data/lib/quandl/cassandra_models/dataset/columns.rb +0 -61
  26. data/lib/quandl/cassandra_models/dataset_attribute.rb +0 -6
  27. data/lib/quandl/cassandra_models/multiset.rb +0 -50
  28. data/spec/factories/dataset.rb +0 -8
  29. data/spec/lib/quandl/cassandra_models/column/write/group_data_by_frequency_spec.rb +0 -28
  30. data/spec/lib/quandl/cassandra_models/column/write_spec.rb +0 -23
  31. data/spec/lib/quandl/cassandra_models/column_attribute_spec.rb +0 -16
  32. data/spec/lib/quandl/cassandra_models/column_spec.rb +0 -17
  33. data/spec/lib/quandl/cassandra_models/data_spec.rb +0 -84
  34. data/spec/lib/quandl/cassandra_models/dataset/collapse_spec.rb +0 -44
  35. data/spec/lib/quandl/cassandra_models/dataset/column_spec.rb +0 -24
  36. data/spec/lib/quandl/cassandra_models/dataset/persistence_spec.rb +0 -24
  37. data/spec/lib/quandl/cassandra_models/dataset/row_spec.rb +0 -26
  38. data/spec/lib/quandl/cassandra_models/dataset/transform_spec.rb +0 -16
  39. data/spec/lib/quandl/cassandra_models/dataset/trim_spec.rb +0 -74
  40. data/spec/lib/quandl/cassandra_models/dataset/update_spec.rb +0 -37
  41. data/spec/lib/quandl/cassandra_models/dataset_attribute_spec.rb +0 -18
  42. data/spec/lib/quandl/cassandra_models/dataset_spec.rb +0 -111
  43. data/spec/lib/quandl/cassandra_models/multiset/collapse_spec.rb +0 -122
  44. data/spec/lib/quandl/cassandra_models/multiset/columns_spec.rb +0 -57
  45. data/spec/lib/quandl/cassandra_models/multiset/data_spec.rb +0 -25
  46. data/spec/lib/quandl/cassandra_models/multiset/transform_spec.rb +0 -69
@@ -1,74 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Quandl::Cassandra::Dataset do
5
-
6
- describe ".trim_start,.trim_end" do
7
- { weekly: 7, monthly: 30, quarterly: 92, annual: 365 }.each do | collapse_to, occurences |
8
- context "when collapsed to #{collapse_to}" do
9
-
10
- subject(:dataset){ create(:dataset, data: Quandl::Fabricate::Data.rand( rows: occurences * 3, columns: 1, nils: false ).to_csv ) }
11
-
12
- it "should include trim_start" do
13
- # raw data
14
- source_data = subject.data.scoped.collapse(collapse_to).to_table
15
- trim_start = source_data[-1][0]
16
- # trim and check
17
- trim_data = subject.data.trim_start( trim_start ).collapse(collapse_to).to_table
18
- trim_data.last[0].should eq trim_start
19
- end
20
- it "should include trim_end" do
21
- # raw data
22
- source_data = subject.data.scoped.collapse(collapse_to).to_table
23
- trim_end = source_data[1][0]
24
- # trim and check
25
- trim_data = subject.data.trim_end( trim_end ).collapse(collapse_to).to_table
26
- trim_data.first[0].should eq trim_end
27
- end
28
- it "should include trim_start and trim_end" do
29
- # raw data
30
- source_data = subject.data.scoped.collapse(collapse_to).to_table
31
- trim_end = source_data[1][0]
32
- trim_start = source_data[-1][0]
33
- # trim and check
34
- trim_data = subject.data.trim_start( trim_start ).trim_end( trim_end ).collapse(collapse_to).to_table
35
- trim_data.first[0].should eq trim_end
36
- trim_data.last[0].should eq trim_start
37
- end
38
-
39
- [:diff, :rdiff, :cumul].each do |transformed_to|
40
- context "when transformed to #{transformed_to}" do
41
- it "should include trim_start" do
42
- # raw data
43
- source_data = subject.data.scoped.collapse(collapse_to).transform(transformed_to).to_table
44
- trim_start = source_data[-1][0]
45
- # trim and check
46
- trim_data = subject.data.trim_start( trim_start ).transform(transformed_to).collapse(collapse_to).to_table
47
- trim_data.last[0].should eq trim_start
48
- end
49
- it "should include trim_end" do
50
- # raw data
51
- source_data = subject.data.scoped.collapse(collapse_to).transform(transformed_to).to_table
52
- trim_end = source_data[-1][0]
53
- # trim and check
54
- trim_data = subject.data.trim_end( trim_end ).transform(transformed_to).collapse(collapse_to).to_table
55
- trim_data.first[0].should eq trim_end
56
- end
57
- it "should include trim_start and trim_end" do
58
- source_data = subject.data.scoped.collapse(collapse_to).transform(transformed_to).to_table
59
- trim_end = source_data[1][0]
60
- trim_start = source_data[-1][0]
61
- # trim and check
62
- trim_data = subject.data.trim_start( trim_start ).trim_end( trim_end ).transform(transformed_to).collapse(collapse_to).to_table
63
- trim_data.first[0].should eq trim_end
64
- trim_data.last[0].should eq trim_start
65
- end
66
- end # each transform
67
-
68
- end
69
-
70
- end # each collapse
71
- end
72
- end
73
-
74
- end
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- context "update data with newer data" do
7
-
8
- subject{ create(:dataset, data: Quandl::Fabricate::Data.rand( rows: 730, columns: 2, nils: false ).to_csv ) }
9
-
10
- it "should update the collapse data" do
11
- old_row = subject.data.scoped[0]
12
- old_row_month = subject.data.scoped.collapse(:monthly)[0]
13
- # update
14
- dataset = Dataset.find(subject.id)
15
- # advance data dates by 60 days
16
- new_data = subject.data.collect{|r|
17
- date = r[0] + 60
18
- values = r[1..-1].collect{ rand(9102841).to_f / 1000 }
19
- [date, values].flatten
20
- }
21
- # assign new data
22
- dataset.data = new_data.to_a.collect{|r| r.to_csv }.join
23
- dataset.save!
24
-
25
- new_row = dataset.data.scoped[0]
26
- new_row_month = dataset.data.scoped.collapse(:monthly)[0]
27
-
28
- new_row[0].should_not eq new_row_month[0]
29
- new_row[1].should eq new_row_month[1]
30
-
31
- old_row[0].should_not eq new_row[0]
32
- old_row_month[1].should_not eq new_row_month[1]
33
- end
34
-
35
- end
36
-
37
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DatasetAttribute do
4
- let(:id){ rand(10000*10000) + 10000*10000 }
5
- let(:dataset_attribute){ DatasetAttribute.create( id: id ) }
6
- subject{ dataset_attribute }
7
-
8
- its(:updated_at){ should be_present }
9
- its(:created_at){ should be_present }
10
-
11
- describe ".find" do
12
- subject{ DatasetAttribute.find( dataset_attribute.id ) }
13
- it{ should be_a DatasetAttribute }
14
- its(:updated_at){ should be_same_second_as dataset_attribute.updated_at }
15
- its(:created_at){ should be_same_second_as dataset_attribute.created_at }
16
- end
17
-
18
- end
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Quandl::Cassandra::Dataset do
4
-
5
- let(:id){ rand(10000*10000) + 10000*10000 }
6
- let(:dataset){ Quandl::Cassandra::Dataset.new( id: id ) }
7
- subject{ dataset }
8
-
9
- it{ should respond_to :id }
10
- it{ should respond_to :data }
11
- it{ should respond_to :column_ids }
12
-
13
- its(:id){ should eq id }
14
- its(:changes){ should eq( { "id" => [nil, id] }) }
15
-
16
- describe ".new" do
17
- let(:dataset){ Quandl::Cassandra::Dataset.new( id: 0 ) }
18
- subject{ dataset }
19
- its(:data){ should eq [] }
20
- its(:column_ids){ should eq [] }
21
- its(:columns){ should eq [] }
22
- describe "#data" do
23
- subject{ dataset.data }
24
- its(:count){ should eq 0 }
25
- its(:to_a){ should eq Quandl::Cassandra::Data.new }
26
- context "given filters" do
27
- subject{ dataset.data.row(0).column(1) }
28
- its(:to_a){ should eq Quandl::Cassandra::Data.new }
29
- end
30
- end
31
- end
32
-
33
- describe "#save" do
34
- subject{ Quandl::Cassandra::Dataset.new }
35
- before(:each){ subject.save }
36
- its(:new_record?){ should be_true }
37
- end
38
-
39
- describe "#class" do
40
- subject{ dataset.class }
41
- its(:table_name){ should eq 'datasets' }
42
- end
43
-
44
- context "given data" do
45
- before(:each){ dataset.data = Quandl::Fabricate::Data.rand(rows: 10, columns: 2, nils: false) }
46
-
47
- describe "#save" do
48
- before(:each){ dataset.save }
49
-
50
- subject{ dataset }
51
-
52
- its(:changes){ should be_blank }
53
- its(:frequency){ should eq 'daily' }
54
-
55
- describe ".find" do
56
- subject{ Quandl::Cassandra::Dataset.find(id) }
57
- its(:data){ should eq dataset.data.to_table }
58
- its(:frequency){ should eq 'daily' }
59
-
60
- describe "#columns" do
61
- subject{ Quandl::Cassandra::Dataset.find(id).columns }
62
- its(:first){ should be_a Quandl::Cassandra::ColumnAttribute }
63
- end
64
-
65
- it "data should count and return data" do
66
- subject.data.count.should eq 10
67
- subject.data.to_table.should be_a Quandl::Cassandra::Data
68
- end
69
- it "columns should eq dataset.columns" do
70
- subject.columns.collect{|c| c.id.to_s }.should eq dataset.columns.collect{|c| c.id.to_s }
71
- end
72
- it "column_ids should eq dataset.column_ids" do
73
- subject.column_ids.collect(&:to_s).should eq dataset.column_ids.collect(&:to_s)
74
- end
75
- end
76
-
77
- describe "#reload" do
78
- before(:each){
79
- dataset.data.limit(5).to_a
80
- dataset.reload
81
- }
82
-
83
- describe "#attributes" do
84
- subject{ dataset.attributes }
85
- its([:data]){ should eq nil }
86
- end
87
-
88
- end
89
-
90
- describe "#data" do
91
- subject{ dataset.data }
92
- its(:count){ should eq 10 }
93
- end
94
-
95
- describe "#column_ids" do
96
- subject{ dataset.column_ids }
97
- its(:count){ should eq 2 }
98
- its(:first){ should be_a Cql::Uuid }
99
- end
100
-
101
- describe "#columns" do
102
- subject{ dataset.columns }
103
- its(:count){ should eq 2 }
104
- its(:first){ should be_a Quandl::Cassandra::ColumnAttribute }
105
- end
106
-
107
- end
108
-
109
- end
110
-
111
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Multiset do
5
-
6
- context "collapse" do
7
-
8
- let(:d1){ create(:dataset) }
9
- let(:d2){ create(:dataset) }
10
- subject { Multiset.with_columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1,#{d2.id.to_i}.3,#{d1.id.to_i}.2") }
11
-
12
- it "should change the scope" do
13
- scope = subject.data.collapse('weekly')
14
- scope.attributes[:collapse].should eq :weekly
15
- end
16
-
17
- it "should accept daily" do
18
- subject.data.collapse(:daily).count.should eq 60
19
- end
20
-
21
- it "should accept weekly" do
22
- subject.data.collapse(:weekly).count.should be < 12
23
- end
24
-
25
- it "should accept monthly" do
26
- subject.data.collapse(:monthly).count.should be < 4
27
- end
28
-
29
- it "should accept annual" do
30
- subject.data.collapse(:annual).count.should eq 1
31
- end
32
-
33
- end
34
-
35
- context "multiple frequencies" do
36
-
37
- let(:dataset_daily) { create(:dataset, data: Quandl::Fabricate::Data.rand( rows: 10, columns: 3, nils: false ).to_csv ) }
38
- let(:dataset_monthly) { create(:dataset, data: Quandl::Fabricate::Data.rand( rows: 10, columns: 3, frequency: :monthly, nils: false ).to_csv ) }
39
- let(:dataset_annual) { create(:dataset, data: Quandl::Fabricate::Data.rand( rows: 10, columns: 3, frequency: :annual, nils: false ).to_csv ) }
40
-
41
- context "without collapse" do
42
-
43
- subject { Multiset.with_columns("#{dataset_daily.id.to_i}.1,#{dataset_monthly.id.to_i}.1,#{dataset_annual.id.to_i}.1") }
44
-
45
- describe "#data" do
46
-
47
- it "should be correct" do
48
- row = subject.data[0]
49
- row[1].should eq Dataset.find(dataset_daily.id).data[0][1]
50
- row[2].should eq Dataset.find(dataset_monthly.id).data[0][1]
51
- row[3].should eq Dataset.find(dataset_annual.id).data[0][1]
52
- end
53
-
54
- end
55
-
56
- describe "#column_frequencies" do
57
-
58
- it "should be correct" do
59
- subject.column_frequencies[0].should eq 'daily'
60
- subject.column_frequencies[1].should eq 'monthly'
61
- subject.column_frequencies[2].should eq 'annual'
62
- end
63
-
64
- end
65
-
66
- end
67
-
68
- context "collapsed to annual" do
69
-
70
- subject {
71
- m = Multiset.with_columns("#{dataset_daily.id.to_i}.1,#{dataset_monthly.id.to_i}.1,#{dataset_annual.id.to_i}.1")
72
- m.data.collapse(:annual)
73
- m
74
- }
75
-
76
- it "should return the data" do
77
- data_hash = subject.data.scoped.collapse(:annual).to_table.to_h
78
- # check daily
79
- daily_row = Dataset.find(dataset_daily.id).data.column(1).collapse(:annual)
80
- daily_date = daily_row[0][0]
81
- data_hash[daily_date][0].should eq daily_row[0][1]
82
- # check monthly
83
- monthly_row = Dataset.find(dataset_monthly.id).data.column(1).collapse(:annual)
84
- monthly_date = monthly_row[0][0]
85
- data_hash[monthly_date][1].should eq monthly_row[0][1]
86
- # check annual
87
- annual_row = Dataset.find(dataset_annual.id).data.column(1).collapse(:annual)
88
- annual_date = annual_row[0][0]
89
- data_hash[annual_date][2].should eq annual_row[0][1]
90
- end
91
-
92
- end
93
-
94
- context "collapsed to monthly" do
95
-
96
- subject {
97
- m = Multiset.with_columns("#{dataset_daily.id.to_i}.1,#{dataset_monthly.id.to_i}.1,#{dataset_annual.id.to_i}.1")
98
- m.data.collapse(:monthly)
99
- m
100
- }
101
-
102
- it "should return the data" do
103
- data_hash = subject.data.to_table.to_h
104
- # check daily
105
- daily_row = Dataset.find(dataset_daily.id).data.column(1).collapse(:monthly)
106
- daily_date = daily_row[0][0]
107
- data_hash[daily_date][0].should eq daily_row[0][1]
108
- # check monthly
109
- monthly_row = Dataset.find(dataset_monthly.id).data.column(1).collapse(:monthly)
110
- monthly_date = monthly_row[0][0]
111
- data_hash[monthly_date][1].should eq monthly_row[0][1]
112
- # check annual
113
- annual_row = Dataset.find(dataset_annual.id).data.column(1).collapse(:monthly)
114
- annual_date = annual_row[0][0]
115
- data_hash[annual_date][2].should eq annual_row[0][1]
116
- end
117
-
118
- end
119
-
120
- end
121
-
122
- end
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Multiset do
5
-
6
- context "columns" do
7
-
8
- let(:d1){ create(:dataset) }
9
- let(:d2){ create(:dataset) }
10
-
11
- let(:multiset){ Multiset.with_columns("#{d2.id.to_i}.2,#{d1.id.to_i}.2,#{d2.id.to_i}.4,#{d1.id.to_i}.3") }
12
-
13
- describe ".with_columns" do
14
- subject{ multiset }
15
-
16
- describe "#column_ids" do
17
- subject{ multiset.column_ids }
18
- its([0]){ should be_same_string_as Dataset.find(d2.id).column_ids[1] }
19
- its([1]){ should be_same_string_as Dataset.find(d1.id).column_ids[1] }
20
- its([2]){ should be_same_string_as Dataset.find(d2.id).column_ids[3] }
21
- its([3]){ should be_same_string_as Dataset.find(d1.id).column_ids[2] }
22
- end
23
-
24
- describe "#data" do
25
- subject{ multiset.data.to_a }
26
- its(:count){ should eq 60 }
27
-
28
- describe "#first" do
29
- subject{ multiset.data.to_a.first }
30
- its(:count){ should eq 5 }
31
- end
32
-
33
- end
34
-
35
- end
36
-
37
- it "should limit the data" do
38
- data = Multiset.with_columns("#{d1.id.to_i}.2,#{d2.id.to_i}.1").data.limit(10)
39
- data.count.should eq 10
40
- end
41
-
42
- it "should return the correct data" do
43
- d = Multiset.with_columns("#{d1.id.to_i}.2,#{d2.id.to_i}.1")
44
- d.data[0][1].should eq Dataset.find(d1.id).data[0][2]
45
- d.data[0][2].should eq Dataset.find(d2.id).data[0][1]
46
- end
47
-
48
- it "should transform the data" do
49
- d = Multiset.with_columns("#{d1.id.to_i}.2,#{d2.id.to_i}.1")
50
- data = d.data.limit(1).transform(:rdiff)
51
- plain_data = Multiset.with_columns("#{d1.id.to_i}.2,#{d2.id.to_i}.1").data.limit(1)
52
- data[0][1].should_not eq plain_data[0][1]
53
- end
54
-
55
- end
56
-
57
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Multiset do
5
-
6
- context "data" do
7
-
8
- let(:d1){ create(:dataset) }
9
- let(:d2){ create(:dataset) }
10
- subject { Multiset.with_columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1,#{d2.id.to_i}.3,#{d1.id.to_i}.2") }
11
- # wait for cassandra to be eventually consistent
12
-
13
- it "should have columns" do
14
- subject.columns.count.should eq 4
15
- end
16
-
17
- it "should have data" do
18
- subject.data.count.should eq 60
19
- end
20
-
21
- its(:to_json){ should be_present }
22
-
23
- end
24
-
25
- end