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
data/UPGRADE.md CHANGED
@@ -1,4 +1,10 @@
1
+ ## 1.0.0
2
+
3
+ * extract Quandl::Cassandra::Models to separate gem
4
+
5
+
1
6
  ## 0.3.1
7
+
2
8
  * refactor dataset columns into Dataset::Columns
3
9
  * with_connection logs and raises error
4
10
 
@@ -19,13 +19,6 @@ require 'quandl/cassandra/base'
19
19
  require 'quandl/cassandra/configuration'
20
20
  require 'quandl/cassandra/batch'
21
21
 
22
- require 'quandl/cassandra_models/column'
23
- require 'quandl/cassandra_models/column_attribute'
24
- require 'quandl/cassandra_models/data'
25
- require 'quandl/cassandra_models/dataset'
26
- require 'quandl/cassandra_models/dataset_attribute'
27
- require 'quandl/cassandra_models/multiset'
28
-
29
22
  module Quandl
30
23
  module Cassandra
31
24
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassandra
3
- VERSION = '0.3.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -11,16 +11,16 @@ describe Quandl::Cassandra::Base::Scoping do
11
11
  end
12
12
 
13
13
  its(:scope_names){ should eq TestModel.scope.scope_names }
14
-
15
- describe ".find_or_build" do
16
- it "given nil should be a new record" do
17
- Dataset.find_or_build(nil).new_record?.should be_true
18
- end
19
- it "given empty sting should be a new record" do
20
- Dataset.find_or_build('').new_record?.should be_true
21
- end
22
- end
23
-
14
+ #
15
+ # describe ".find_or_build" do
16
+ # it "given nil should be a new record" do
17
+ # TestModel.find_or_build(nil).new_record?.should be_true
18
+ # end
19
+ # it "given empty sting should be a new record" do
20
+ # TestModel.find_or_build('').new_record?.should be_true
21
+ # end
22
+ # end
23
+ #
24
24
  describe ".to_cql" do
25
25
 
26
26
  let(:scope) { TestModel.scope.new }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassandra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -260,53 +260,12 @@ files:
260
260
  - lib/quandl/cassandra/types/utf8_type.rb
261
261
  - lib/quandl/cassandra/types/uuid_type.rb
262
262
  - lib/quandl/cassandra/version.rb
263
- - lib/quandl/cassandra_models/column.rb
264
- - lib/quandl/cassandra_models/column/read.rb
265
- - lib/quandl/cassandra_models/column/read/collapse.rb
266
- - lib/quandl/cassandra_models/column/read/column.rb
267
- - lib/quandl/cassandra_models/column/read/data.rb
268
- - lib/quandl/cassandra_models/column/read/offset.rb
269
- - lib/quandl/cassandra_models/column/read/row.rb
270
- - lib/quandl/cassandra_models/column/read/select_columns.rb
271
- - lib/quandl/cassandra_models/column/read/transform.rb
272
- - lib/quandl/cassandra_models/column/read/type.rb
273
- - lib/quandl/cassandra_models/column/write.rb
274
- - lib/quandl/cassandra_models/column/write/group_data_by_column.rb
275
- - lib/quandl/cassandra_models/column/write/group_data_by_frequency.rb
276
- - lib/quandl/cassandra_models/column/write/insert_column_attributes.rb
277
- - lib/quandl/cassandra_models/column/write/insert_columns.rb
278
- - lib/quandl/cassandra_models/column_attribute.rb
279
- - lib/quandl/cassandra_models/data.rb
280
- - lib/quandl/cassandra_models/data/search.rb
281
- - lib/quandl/cassandra_models/dataset.rb
282
- - lib/quandl/cassandra_models/dataset/columns.rb
283
- - lib/quandl/cassandra_models/dataset_attribute.rb
284
- - lib/quandl/cassandra_models/multiset.rb
285
263
  - lib/quandl/strategy.rb
286
264
  - quandl_cassandra.gemspec
287
265
  - spec/expectations/string.rb
288
266
  - spec/expectations/time.rb
289
- - spec/factories/dataset.rb
290
267
  - spec/lib/quandl/cassandra/base/sanitization_spec.rb
291
268
  - spec/lib/quandl/cassandra/base/scoping_spec.rb
292
- - spec/lib/quandl/cassandra_models/column/write/group_data_by_frequency_spec.rb
293
- - spec/lib/quandl/cassandra_models/column/write_spec.rb
294
- - spec/lib/quandl/cassandra_models/column_attribute_spec.rb
295
- - spec/lib/quandl/cassandra_models/column_spec.rb
296
- - spec/lib/quandl/cassandra_models/data_spec.rb
297
- - spec/lib/quandl/cassandra_models/dataset/collapse_spec.rb
298
- - spec/lib/quandl/cassandra_models/dataset/column_spec.rb
299
- - spec/lib/quandl/cassandra_models/dataset/persistence_spec.rb
300
- - spec/lib/quandl/cassandra_models/dataset/row_spec.rb
301
- - spec/lib/quandl/cassandra_models/dataset/transform_spec.rb
302
- - spec/lib/quandl/cassandra_models/dataset/trim_spec.rb
303
- - spec/lib/quandl/cassandra_models/dataset/update_spec.rb
304
- - spec/lib/quandl/cassandra_models/dataset_attribute_spec.rb
305
- - spec/lib/quandl/cassandra_models/dataset_spec.rb
306
- - spec/lib/quandl/cassandra_models/multiset/collapse_spec.rb
307
- - spec/lib/quandl/cassandra_models/multiset/columns_spec.rb
308
- - spec/lib/quandl/cassandra_models/multiset/data_spec.rb
309
- - spec/lib/quandl/cassandra_models/multiset/transform_spec.rb
310
269
  - spec/lib/quandl/cassandra_spec.rb
311
270
  - spec/spec_helper.rb
312
271
  homepage: http://blake.hilscher.ca/
@@ -337,26 +296,7 @@ summary: Quandl cassandra interface.
337
296
  test_files:
338
297
  - spec/expectations/string.rb
339
298
  - spec/expectations/time.rb
340
- - spec/factories/dataset.rb
341
299
  - spec/lib/quandl/cassandra/base/sanitization_spec.rb
342
300
  - spec/lib/quandl/cassandra/base/scoping_spec.rb
343
- - spec/lib/quandl/cassandra_models/column/write/group_data_by_frequency_spec.rb
344
- - spec/lib/quandl/cassandra_models/column/write_spec.rb
345
- - spec/lib/quandl/cassandra_models/column_attribute_spec.rb
346
- - spec/lib/quandl/cassandra_models/column_spec.rb
347
- - spec/lib/quandl/cassandra_models/data_spec.rb
348
- - spec/lib/quandl/cassandra_models/dataset/collapse_spec.rb
349
- - spec/lib/quandl/cassandra_models/dataset/column_spec.rb
350
- - spec/lib/quandl/cassandra_models/dataset/persistence_spec.rb
351
- - spec/lib/quandl/cassandra_models/dataset/row_spec.rb
352
- - spec/lib/quandl/cassandra_models/dataset/transform_spec.rb
353
- - spec/lib/quandl/cassandra_models/dataset/trim_spec.rb
354
- - spec/lib/quandl/cassandra_models/dataset/update_spec.rb
355
- - spec/lib/quandl/cassandra_models/dataset_attribute_spec.rb
356
- - spec/lib/quandl/cassandra_models/dataset_spec.rb
357
- - spec/lib/quandl/cassandra_models/multiset/collapse_spec.rb
358
- - spec/lib/quandl/cassandra_models/multiset/columns_spec.rb
359
- - spec/lib/quandl/cassandra_models/multiset/data_spec.rb
360
- - spec/lib/quandl/cassandra_models/multiset/transform_spec.rb
361
301
  - spec/lib/quandl/cassandra_spec.rb
362
302
  - spec/spec_helper.rb
@@ -1,20 +0,0 @@
1
- class Quandl::Cassandra::Column < Quandl::Cassandra::Base
2
-
3
- table_name :columns
4
-
5
- require_relative 'column/read'
6
- require_relative 'column/write'
7
-
8
- class << self
9
-
10
- def read(*args)
11
- Quandl::Cassandra::Column::Read.perform(*args)[:data]
12
- end
13
-
14
- def write(*args)
15
- Quandl::Cassandra::Column::Write.perform(*args)
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,32 +0,0 @@
1
- class Quandl::Cassandra::Column::Read < Quandl::Strategy::Strategize
2
-
3
- require_relative 'read/collapse'
4
- require_relative 'read/column'
5
- require_relative 'read/data'
6
- require_relative 'read/offset'
7
- require_relative 'read/select_columns'
8
- require_relative 'read/row'
9
- require_relative 'read/transform'
10
- require_relative 'read/type'
11
-
12
- define_attributes :id
13
-
14
- def self.perform(attributes)
15
- strategy = Quandl::Strategy.new( attributes ) do |c|
16
- c.use Quandl::Cassandra::Column::Read::Type
17
- c.use Quandl::Cassandra::Column::Read::Row
18
- c.use Quandl::Cassandra::Column::Read::Column
19
- c.use Quandl::Cassandra::Column::Read::Collapse
20
- c.use Quandl::Cassandra::Column::Read::Transform
21
- c.use Quandl::Cassandra::Column::Read::Offset
22
- c.use Quandl::Cassandra::Column::Read::SelectColumns
23
- c.use Quandl::Cassandra::Column::Read::Data
24
- end
25
- strategy.perform
26
- end
27
-
28
- def count?
29
- attributes[:count] == true
30
- end
31
-
32
- end
@@ -1,65 +0,0 @@
1
- class Quandl::Cassandra::Column::Read::Collapse < Quandl::Cassandra::Column::Read
2
-
3
- def perform
4
- # assign
5
- attributes[:collapse] = collapse
6
- attributes[:frequency] = frequency
7
- attributes[:column_frequencies] = column_frequencies
8
- attributes[:column_collapses] = column_collapses
9
- end
10
-
11
- def collapse
12
- # collapse is the collapse
13
- coll = attributes[:collapse]
14
- # when pristine.frequency and collapse are equal, the source data is being requested
15
- coll = :source if attributes[:pristine][:frequency] == attributes[:collapse]
16
- # when the collapse is daily, source data is being requested
17
- coll = :source if coll == :daily || coll.blank?
18
- coll
19
- end
20
-
21
- def frequency
22
- # frequency is the given frequency
23
- freq = attributes[:frequency]
24
- # grab from database
25
- freq = Quandl::Cassandra::DatasetAttribute.where(id: id).pluck(:frequency).first if freq.blank? and id.present?
26
- # fallback to collapse
27
- freq = attributes[:collapse] if freq.blank?
28
- # if freq is source, daily is being requested
29
- freq = :daily if freq == :source
30
- freq = freq.to_sym
31
- freq
32
- end
33
-
34
- def column_frequencies
35
- # default to passed value
36
- freqs = attributes[:column_frequencies]
37
- # fallback to collapse value
38
- freqs = attributes[:column_ids].collect{ attributes[:frequency] } if freqs.blank?
39
- freqs
40
- end
41
-
42
- # INPUT column_frequencies: [ :daily, :weekly, :monthly ], collapse: :monthly
43
- # OUPUT [ :monthly, :monthly, :source ]
44
-
45
- # INPUT column_frequencies: [ :daily, :weekly, :monthly ], collapse: :source
46
- # OUPUT [ :source, :source, :source ]
47
-
48
- # INPUT column_frequencies: [ :daily, :monthly, :annual ], collapse: :monthly
49
- # OUPUT [ :monthly, :source, :source ]
50
-
51
- def column_collapses
52
- attributes[:column_frequencies].collect do |frequency|
53
- # is frequency less than collapse?
54
- if Quandl::Operation::Collapse.collapses_greater_than( frequency ).include?( attributes[:collapse] )
55
- # this column needs to be collapsed
56
- attributes[:collapse]
57
- # otherwise frequency is greater than or equal to collapse
58
- else
59
- # so collapse is not needed
60
- :source
61
- end
62
- end
63
- end
64
-
65
- end
@@ -1,19 +0,0 @@
1
- class Quandl::Cassandra::Column::Read::Column < Quandl::Cassandra::Column::Read
2
-
3
- def perform
4
- # given an id, this is a dataset
5
- attributes[:column_ids] ||= Quandl::Cassandra::Dataset.find(id).try(:column_ids) if id.present?
6
- attributes[:column_ids] = [] if attributes[:column_ids].blank?
7
- # given a column, this is requesting a specific column
8
- attributes[:column_ids] = pluck_column_id if column.present? && attributes[:column_ids].present?
9
- end
10
-
11
- def pluck_column_id
12
- [ attributes[:column_ids][ column ] ]
13
- end
14
-
15
- def column
16
- attributes[:column].present? ? attributes[:column] - 1 : nil
17
- end
18
-
19
- end
@@ -1,59 +0,0 @@
1
- class Quandl::Cassandra::Column::Read::Data < Quandl::Cassandra::Column::Read
2
-
3
- def perform
4
- attributes[:data] = quandl_data( attributes[:data] ) unless count?
5
- end
6
-
7
- def quandl_data(data)
8
- # init
9
- data = Quandl::Cassandra::Data.new( data )
10
- data.dataset_id = attributes[:id]
11
- data.column_ids = attributes[:column_ids] unless attributes[:column].present?
12
- data.column_frequencies = attributes[:column_frequencies] unless attributes[:column].present?
13
- # post process
14
- data = collapse(data)
15
- data = transform(data)
16
- data = trim(data)
17
- data = sort( data )
18
- data = row( data )
19
- data = limit(data)
20
- data
21
- end
22
-
23
- def trim(data)
24
- return data unless attributes[:data_table].present?
25
- data = data.sort_order( :asc ) if attributes[:data_table][:trim_start] || attributes[:data_table][:trim_end]
26
- data = data.trim_start( attributes[:data_table][:trim_start] ) if attributes[:data_table][:trim_start]
27
- data = data.trim_end( attributes[:data_table][:trim_end] ) if attributes[:data_table][:trim_end]
28
- data
29
- end
30
-
31
- def sort(data)
32
- data = data.sort_order( attributes[:order] )
33
- end
34
-
35
- def collapse(data)
36
- data = data.collapse( attributes[:collapse] ) if attributes[:collapse]
37
- data
38
- end
39
-
40
- def transform(data)
41
- data = data.transform( attributes[:transform] ) if attributes[:transform]
42
- data
43
- end
44
-
45
- def limit(data)
46
- data = data.limit( attributes[:pristine][:limit] ) if attributes[:pristine][:limit]
47
- data
48
- end
49
-
50
- def row(data)
51
- # if a row was requested and the data count is greater than a single row
52
- if attributes[:row].present? && data.count > 1
53
- # grab the last row
54
- data.data_array = [data.data_array[-1]]
55
- end
56
- data
57
- end
58
-
59
- end
@@ -1,118 +0,0 @@
1
- class Quandl::Cassandra::Column::Read::Offset < Quandl::Cassandra::Column::Read
2
-
3
- def perform
4
- # apply offset
5
- return unless column_ids.present?
6
- apply_offset_with_transform
7
- apply_offset
8
- end
9
-
10
- def apply_offset_with_transform
11
- # rdiff_from needs the data from the current to offset
12
- if attributes[:row].present? && attributes[:transform] == :rdiff_from
13
- # limit the results by trim
14
- attributes[:trim_start] = trim_start.occurrences_of_frequency_ago( attributes[:row], collapse_with_frequency ).end_of_frequency(collapse_with_frequency).jd if order == :desc
15
- attributes[:trim_end] = trim_end.occurrences_of_frequency_ahead( attributes[:row], collapse_with_frequency ).end_of_frequency(collapse_with_frequency).jd if order == :asc
16
- # the query should not limit or offset the data
17
- attributes[:limit] = nil
18
- attributes[:offset] = nil
19
- end
20
- end
21
-
22
- def apply_offset
23
- return unless attributes[:offset].present?
24
- order == :asc ? apply_offset_asc : apply_offset_desc
25
- end
26
-
27
- def apply_offset_asc
28
- # calculate ranges
29
- offset_start = trim_end.occurrences_of_frequency_ahead( offset, collapse_with_frequency ).start_of_frequency(collapse_with_frequency)
30
- offset_end = offset_start.occurrences_of_frequency_ahead( accuracy_with_limit, collapse_with_frequency ).end_of_frequency( collapse_with_frequency ) if limit
31
- # set trims
32
- attributes[:trim_start] = offset_start.jd
33
- attributes[:trim_end] = offset_end.jd if limit
34
- end
35
-
36
- def apply_offset_desc
37
- # calculate ranges
38
- offset_start = trim_start.occurrences_of_frequency_ago( offset, collapse_with_frequency ).end_of_frequency(collapse_with_frequency)
39
- offset_end = offset_start.occurrences_of_frequency_ago( accuracy_with_limit, collapse_with_frequency ).start_of_frequency( collapse_with_frequency ) if limit
40
- # set trims
41
- attributes[:trim_start] = offset_end.jd if limit
42
- attributes[:trim_end] = offset_start.jd
43
- end
44
-
45
- def trim_start
46
- return @trim_start if defined?(@trim_start)
47
- times = column_ids.collect do |id|
48
- Quandl::Cassandra::Column.limit(1).order("type DESC").where( id: id, type: collapse ).pluck(:time)
49
- end
50
- max_time = times.flatten.max
51
- @trim_start = Date.jd( max_time )
52
- end
53
-
54
- def trim_end
55
- return @trim_end if defined?(@trim_end)
56
- times = column_ids.collect do |id|
57
- Quandl::Cassandra::Column.limit(1).order("type ASC").where( id: id, type: collapse ).pluck(:time)
58
- end
59
- max_time = times.flatten.max
60
- @trim_end = Date.jd( max_time )
61
- end
62
-
63
- def accuracy_with_limit
64
- # # short circuit for now
65
- # return 0
66
- # revist this at a later date:
67
- awl = accuracy
68
- awl = awl + limit - 1 if limit && limit > 0
69
- awl
70
- end
71
-
72
- def accuracy
73
- # did the query include an accuracy?
74
- accuracy = attributes[:accuracy]
75
- # otherwise guess at the accuracy by collapse
76
- if accuracy.blank?
77
- accuracy = case frequency
78
- when :daily then 0
79
- when :weekly then 1
80
- when :monthly then 1
81
- when :quarterly then 1
82
- when :annual then 0
83
- else
84
- 3
85
- end
86
- end
87
- accuracy
88
- end
89
-
90
- def column_ids
91
- attributes[:column_ids]
92
- end
93
-
94
- def limit
95
- @limit ||= attributes[:limit]
96
- end
97
-
98
- def offset
99
- attributes[:offset]
100
- end
101
-
102
- def order
103
- @order ||= attributes[:order] == :asc ? :asc : :desc
104
- end
105
-
106
- def collapse_with_frequency
107
- collapse == :source ? frequency : collapse
108
- end
109
-
110
- def frequency
111
- attributes[:frequency]
112
- end
113
-
114
- def collapse
115
- attributes[:collapse]
116
- end
117
-
118
- end