quandl_cassandra 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/UPGRADE.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.1
2
+ * refactor dataset columns into Dataset::Columns
3
+ * with_connection logs and raises error
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  * Base::Connection methods use #with_connection
@@ -35,15 +35,15 @@ module Quandl::Cassandra::Base::Connection
35
35
  begin
36
36
  yield(connection)
37
37
 
38
- rescue Cql::Io::ConnectionError => e
39
- Quandl::Logger.error(e)
38
+ rescue Cql::Io::ConnectionError => err
39
+ Quandl::Logger.error(err)
40
40
  reset_connection
41
- raise Cql::Io::ConnectionError
41
+ raise
42
42
 
43
- rescue Cql::NotConnectedError => e
44
- Quandl::Logger.error(e)
43
+ rescue Cql::NotConnectedError => err
44
+ Quandl::Logger.error(err)
45
45
  reset_connection
46
- raise Cql::NotConnectedError
46
+ raise
47
47
 
48
48
  end
49
49
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassandra
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -0,0 +1,61 @@
1
+ module Quandl::Cassandra::Dataset::Columns
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # define_attributes :column_ids
7
+ before_save :save_columns
8
+
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def find_column_ids_by_id(id)
14
+ Quandl::Cassandra::Dataset.where( id: id ).pluck(:column_id, :position).sort_by{|r| r[1] }.collect{|r| r[0] }
15
+ end
16
+
17
+ end
18
+
19
+ def column_attributes=(column_attrs)
20
+ column_attrs.each_with_index do |attrs, index|
21
+ self.columns[index] ||= Quandl::Cassandra::Column.new
22
+ self.columns[index].assign_attributes(attrs)
23
+ end
24
+ end
25
+
26
+ def column_units
27
+ @column_units ||= columns.collect(&:unit)
28
+ end
29
+
30
+ def column_names
31
+ @column_names ||= columns.collect(&:name)
32
+ end
33
+
34
+ def columns
35
+ return @columns if @columns
36
+ # find columns
37
+ columns = Quandl::Cassandra::ColumnAttribute.where( id: column_ids ).all
38
+ # build column where column_id was not found
39
+ @columns = column_ids.collect{|cid| columns.detect{|c| c.id.to_s == cid.to_s } || Quandl::Cassandra::ColumnAttribute.new( id: cid ) }
40
+ end
41
+
42
+ def column_ids
43
+ @column_ids ||= id.blank? ? [] : self.class.find_column_ids_by_id(id)
44
+ end
45
+
46
+
47
+ protected
48
+
49
+ def clear_attributes!
50
+ @columns = nil
51
+ @column_ids = nil
52
+ end
53
+
54
+
55
+ private
56
+
57
+ def save_columns
58
+ columns.each(&:save)
59
+ end
60
+
61
+ end
@@ -1,33 +1,18 @@
1
1
  class Quandl::Cassandra::Dataset < Quandl::Cassandra::Base
2
-
2
+
3
+ require_relative 'dataset/columns'
4
+
5
+ include Quandl::Cassandra::Dataset::Columns
6
+
3
7
  table_name :datasets
4
8
  autosave_changes false
5
9
 
6
- define_attributes :id, :data, :column_ids
10
+ define_attributes :id, :data
7
11
 
8
- before_save :save_columns, :save_data, :save_dataset_attribute
12
+ before_save :save_data, :save_dataset_attribute
9
13
  after_save :clear_attributes!
10
14
 
11
15
  delegate :type, :updated_at, :created_at, :frequency, to: :dataset_attribute, allow_nil: true
12
-
13
- def self.find_column_ids_by_id(id)
14
- Quandl::Cassandra::Dataset.where( id: id ).pluck(:column_id, :position).sort_by{|r| r[1] }.collect{|r| r[0] }
15
- end
16
-
17
- def column_attributes=(column_attrs)
18
- column_attrs.each_with_index do |attrs, index|
19
- self.columns[index] ||= Quandl::Cassandra::Column.new
20
- self.columns[index].assign_attributes(attrs)
21
- end
22
- end
23
-
24
- def columns
25
- @columns ||= column_ids.collect{|cid| Quandl::Cassandra::ColumnAttribute.find(cid) }
26
- end
27
-
28
- def column_ids
29
- @column_ids ||= id.blank? ? [] : self.class.find_column_ids_by_id(id)
30
- end
31
16
 
32
17
  def trim_start
33
18
  @trim_start ||= Date.jd( data.scoped.limit(1).order(:asc)[0][0] )
@@ -73,19 +58,14 @@ class Quandl::Cassandra::Dataset < Quandl::Cassandra::Base
73
58
  dataset_attribute.save
74
59
  end
75
60
 
76
- def save_columns
77
- columns.each(&:save)
78
- end
79
-
80
61
  def save_data
81
62
  Quandl::Cassandra::Column.write( id: id, data: data ) if data_changed?
82
63
  end
83
64
 
84
65
  def clear_attributes!
66
+ super if defined?(super)
85
67
  @trim_start = nil
86
68
  @trim_end = nil
87
- @columns = nil
88
- @column_ids = nil
89
69
  @attributes = { id: id }
90
70
  end
91
71
 
@@ -56,7 +56,12 @@ describe Quandl::Cassandra::Dataset do
56
56
  subject{ Quandl::Cassandra::Dataset.find(id) }
57
57
  its(:data){ should eq dataset.data.to_table }
58
58
  its(:frequency){ should eq 'daily' }
59
-
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
+
60
65
  it "data should count and return data" do
61
66
  subject.data.count.should eq 10
62
67
  subject.data.to_table.should be_a Quandl::Cassandra::Data
@@ -74,7 +74,7 @@ describe Multiset do
74
74
  }
75
75
 
76
76
  it "should return the data" do
77
- data_hash = subject.data.to_table.to_h
77
+ data_hash = subject.data.scoped.collapse(:annual).to_table.to_h
78
78
  # check daily
79
79
  daily_row = Dataset.find(dataset_daily.id).data.column(1).collapse(:annual)
80
80
  daily_date = daily_row[0][0]
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.0
4
+ version: 0.3.1
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-11-04 00:00:00.000000000 Z
12
+ date: 2013-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -279,6 +279,7 @@ files:
279
279
  - lib/quandl/cassandra_models/data.rb
280
280
  - lib/quandl/cassandra_models/data/search.rb
281
281
  - lib/quandl/cassandra_models/dataset.rb
282
+ - lib/quandl/cassandra_models/dataset/columns.rb
282
283
  - lib/quandl/cassandra_models/dataset_attribute.rb
283
284
  - lib/quandl/cassandra_models/multiset.rb
284
285
  - lib/quandl/strategy.rb