quandl_cassandra_models 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19c6f57810b76a53543512153c5b92509b37067e
4
- data.tar.gz: ba82d7c28e4e048f1abd221765d779a5d981fe4a
3
+ metadata.gz: 4259f1381c30f2b0931bd4972551d33c70286c71
4
+ data.tar.gz: 6bb2d31d9a58d24f89ee3379185e2c0af713d420
5
5
  SHA512:
6
- metadata.gz: 9d39a799aeb081836cd8debf0e0c033fc2f06ee9b9433f0c7e9ced7307a06ec67a30d3490e7e27172486e8048a15effe8119f37a4b505eff7e7755afb3c17d84
7
- data.tar.gz: b7417e67ee39584d3d34fc8b14e6524929827ef28358950f0d0692c44ae136871399299faed4168bda9ff08378977524360cb7c7141080d7166b4d25cdd5b72b
6
+ metadata.gz: f789664acaf5f8afae282a7fcc42147735af37bedcb1661b2aa76f6c13081393d2cdbd441a9b76deb3ab5f65485a44a956877df03bd9e3cd25b50caa5b020cb6
7
+ data.tar.gz: 773b3492342adc6372329848736fbfb0c376b7724407416ebbf64e20ba02d814e23fde5592c1f9681fcc304282de3e6ff0f2360a2a79c0e9580262e74d7c602a
data/UPGRADE.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.3.13
2
+
3
+ * dataset.data.delete_rows_by_time(*times) passes
4
+ * add write validation that asserts required keys
5
+ * dataset.data.delete_collapses pass specs
6
+ * remove travis.yml
7
+
8
+
1
9
  ## 0.3.12
2
10
 
3
11
  * refactor read to use define_attributes for trim_start, trim_end, collapse WIKI-28 passes
@@ -13,7 +13,7 @@ class Quandl::Cassandra::Models::Column::Write::InsertColumnAttributes < Quandl:
13
13
  # insert dataset_attribute
14
14
  Quandl::Cassandra::Base.execute("INSERT INTO dataset_attributes (id, updated_at, frequency) VALUES (#{id}, #{(Time.now.to_f * 1000).to_i}, '#{frequency}')")
15
15
  # insert data
16
- Quandl::Cassandra::Batch.insert(rows_values) do |id, column_id, position, frequency|
16
+ Quandl::Cassandra::Batch.execute(rows_values) do |id, column_id, position, frequency|
17
17
  %Q{INSERT INTO datasets (id, column_id, position) VALUES (#{id}, #{column_id}, #{position})
18
18
  INSERT INTO column_attributes ( id, frequency ) VALUES ( #{column_id}, '#{frequency}' )}
19
19
  end
@@ -1,7 +1,7 @@
1
1
  class Quandl::Cassandra::Models::Column::Write::InsertColumns < Quandl::Cassandra::Models::Column::Write
2
2
 
3
3
  def perform
4
- Quandl::Cassandra::Batch.insert(statement_values) do |id, type, time, value|
4
+ Quandl::Cassandra::Batch.execute(statement_values) do |id, type, time, value|
5
5
  "INSERT INTO columns (id, type, time, value) VALUES (#{id}, '#{type}', #{time}, #{value})"
6
6
  end
7
7
  end
@@ -0,0 +1,10 @@
1
+ class Quandl::Cassandra::Models::Column::Write::Validate < Quandl::Cassandra::Models::Column::Write
2
+
3
+ def perform
4
+ # ensure args are present
5
+ if attributes[:id].blank? || attributes[:data].blank?
6
+ raise ArgumentError, "attributes require keys [:id, :data], you passed #{attributes.keys} "
7
+ end
8
+ end
9
+
10
+ end
@@ -3,6 +3,7 @@ class Quandl::Cassandra::Models::Column::Write < Quandl::Strategy::Strategize
3
3
  # strategy attributes
4
4
  define_attributes :id, :data, :frequency, :column_ids, :frequency_data, :frequency_column_data, :statement_values
5
5
 
6
+ require_relative 'write/validate'
6
7
  require_relative 'write/insert_columns'
7
8
  require_relative 'write/insert_column_attributes'
8
9
  require_relative 'write/group_data_by_column'
@@ -10,7 +11,9 @@ class Quandl::Cassandra::Models::Column::Write < Quandl::Strategy::Strategize
10
11
 
11
12
  # execute strategy
12
13
  def self.perform(attributes)
14
+ # perform strategy
13
15
  strategy = Quandl::Strategy.new( attributes ) do |c|
16
+ c.use Quandl::Cassandra::Models::Column::Write::Validate
14
17
  c.use Quandl::Cassandra::Models::Column::Write::GroupDataByFrequency
15
18
  c.use Quandl::Cassandra::Models::Column::Write::GroupDataByColumn
16
19
  c.use Quandl::Cassandra::Models::Column::Write::InsertColumns
@@ -18,7 +21,7 @@ class Quandl::Cassandra::Models::Column::Write < Quandl::Strategy::Strategize
18
21
  end
19
22
  strategy.perform
20
23
  rescue => e
21
- Quandl::Logger.error("#{e} #{strategy.attributes}")
24
+ Quandl::Logger.error("#{e} #{attributes}")
22
25
  raise
23
26
  end
24
27
 
@@ -44,6 +44,7 @@ module Quandl::Cassandra::Models::Data::Search
44
44
  date = Date.jd(value) if value.is_a?(Integer)
45
45
  date = Date.parse(value) if value.is_a?(String) && value =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/
46
46
  date = value if value.is_a?(Date)
47
+ date = value.to_date if value.respond_to?(:to_date)
47
48
  date.jd
48
49
  rescue
49
50
  nil
@@ -55,13 +56,34 @@ module Quandl::Cassandra::Models::Data::Search
55
56
  delegate :to_a, :==, :inspect, :first, :flatten, :[], :collect, :<=>, :each, :each_with_index, :to_date, :to_h, to: :all, allow_nil: true
56
57
 
57
58
  def delete_all(*args)
58
- if attributes[:column_ids].present?
59
- result = Quandl::Cassandra::Models::Column.where( id: attributes[:column_ids] ).delete_all
59
+ if dataset_column_ids.present?
60
+ result = Quandl::Cassandra::Models::Column.where( id: dataset_column_ids ).delete_all
60
61
  return result.nil? ? true : result
61
62
  end
62
63
  false
63
64
  end
64
-
65
+
66
+ def delete_rows_by_time(*times)
67
+ times = Array(times).flatten
68
+ # dataset_column_ids are required
69
+ return false unless dataset_column_ids
70
+ statement_values = []
71
+ # for each column_id
72
+ dataset_column_ids.each do |column_id|
73
+ # for each time
74
+ times.each do |time|
75
+ # delete the requested column_id_time
76
+ statement_values << [column_id, time]
77
+ end
78
+ end
79
+ # execute deletion of rquested rows
80
+ Quandl::Cassandra::Batch.execute(statement_values) do |id, time|
81
+ "DELETE FROM columns WHERE id = #{id} AND type = 'source' AND time = #{time}"
82
+ end
83
+ # delete collapse data and regenerate
84
+ regenerate_collapses_from_source
85
+ end
86
+
65
87
  def count(*args)
66
88
  attributes[:count] = true
67
89
  result = dataset? ? fetch.to_i : 0
@@ -74,7 +96,7 @@ module Quandl::Cassandra::Models::Data::Search
74
96
  end
75
97
 
76
98
  def dataset?
77
- self.id.present? || attributes[:column_ids].present?
99
+ self.id.present? || dataset_column_ids.present?
78
100
  end
79
101
 
80
102
  def fetched?
@@ -84,11 +106,15 @@ module Quandl::Cassandra::Models::Data::Search
84
106
  def scoped
85
107
  s = self.class.new
86
108
  s.id( self.id ) if id.present?
87
- s.column_ids( attributes[:column_ids] ) if attributes[:column_ids].present?
109
+ s.column_ids( dataset_column_ids ) if dataset_column_ids.present?
88
110
  s.column_frequencies(attributes[:column_frequencies]) if attributes[:column_frequencies].present?
89
111
  s
90
112
  end
91
113
 
114
+ def dataset_column_ids
115
+ attributes[:column_ids]
116
+ end
117
+
92
118
  protected
93
119
 
94
120
  def fetch
@@ -98,6 +124,31 @@ module Quandl::Cassandra::Models::Data::Search
98
124
  Quandl::Cassandra::Models::Column.read( attributes.merge(scope_attributes) )
99
125
  end
100
126
 
127
+ private
128
+
129
+ def regenerate_collapses_from_source
130
+ # delete collapse data
131
+ delete_collapses
132
+ # get existing data
133
+ data = Quandl::Cassandra::Models::Column.read( column_ids: dataset_column_ids )
134
+ # rewrite data
135
+ Quandl::Cassandra::Models::Column.write( id: id, data: data, column_ids: dataset_column_ids )
136
+ end
137
+
138
+ def delete_collapses
139
+ statement_values = []
140
+ # for each column
141
+ dataset_column_ids.each do |column_id|
142
+ # for each collapse
143
+ Quandl::Operation::Collapse.collapses_greater_than(:daily).each do |collapse|
144
+ statement_values << [ column_id, collapse ]
145
+ end
146
+ end
147
+ # execute deletion
148
+ Quandl::Cassandra::Batch.execute(statement_values) do |id, type|
149
+ "DELETE FROM columns WHERE id = #{id} AND type = '#{type}'"
150
+ end
151
+ end
101
152
 
102
153
  end
103
154
 
@@ -1,7 +1,7 @@
1
1
  module Quandl
2
2
  module Cassandra
3
3
  module Models
4
- VERSION = '0.3.12'
4
+ VERSION = '0.3.13'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Quandl::Cassandra::Models::Data::Search do
4
+
5
+ let(:dataset){ create(:dataset) }
6
+
7
+ describe "#delete_collapses" do
8
+ before(:each){ dataset.data.send(:delete_collapses) }
9
+
10
+ it "dataset.data.to_a should be_present" do
11
+ dataset.data.scoped.to_a.should be_present
12
+ end
13
+
14
+ [:weekly, :monthly, :quarterly, :annual].each do |collapse|
15
+ it "data.collapse(#{collapse}).to_a should be_blank" do
16
+ dataset.data.scoped.collapse(collapse).to_a.should be_blank
17
+ end
18
+
19
+ describe "#regenerate_collapses_from_source" do
20
+ before(:each){ dataset.data.send(:regenerate_collapses_from_source) }
21
+
22
+ it "data.collapse(#{collapse}).to_a should be_present" do
23
+ dataset.data.scoped.collapse(collapse).to_a.should be_present
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#delete_rows_by_time" do
31
+
32
+ let(:dates){ dataset.data.scoped.to_table.to_h.keys }
33
+
34
+ let(:times){ [ dates[1], dates[5], dates[7], dates[10] ] }
35
+
36
+ before(:each){ dataset.data.delete_rows_by_time(times) }
37
+
38
+ it "times should be removed from data" do
39
+ data = dataset.data.scoped.to_table.to_h
40
+ times.each do |time|
41
+ data[time].should be_nil
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassandra_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
@@ -130,7 +130,6 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - .gitignore
133
- - .travis.yml
134
133
  - Gemfile
135
134
  - Guardfile
136
135
  - LICENSE
@@ -157,6 +156,7 @@ files:
157
156
  - lib/quandl/cassandra/models/column/write/group_data_by_frequency.rb
158
157
  - lib/quandl/cassandra/models/column/write/insert_column_attributes.rb
159
158
  - lib/quandl/cassandra/models/column/write/insert_columns.rb
159
+ - lib/quandl/cassandra/models/column/write/validate.rb
160
160
  - lib/quandl/cassandra/models/column_attribute.rb
161
161
  - lib/quandl/cassandra/models/data.rb
162
162
  - lib/quandl/cassandra/models/data/search.rb
@@ -181,6 +181,7 @@ files:
181
181
  - spec/lib/quandl/cassandra/models/column/write_spec.rb
182
182
  - spec/lib/quandl/cassandra/models/column_attribute_spec.rb
183
183
  - spec/lib/quandl/cassandra/models/column_spec.rb
184
+ - spec/lib/quandl/cassandra/models/data/search_spec.rb
184
185
  - spec/lib/quandl/cassandra/models/data_spec.rb
185
186
  - spec/lib/quandl/cassandra/models/dataset/collapse_spec.rb
186
187
  - spec/lib/quandl/cassandra/models/dataset/columns_spec.rb
@@ -233,6 +234,7 @@ test_files:
233
234
  - spec/lib/quandl/cassandra/models/column/write_spec.rb
234
235
  - spec/lib/quandl/cassandra/models/column_attribute_spec.rb
235
236
  - spec/lib/quandl/cassandra/models/column_spec.rb
237
+ - spec/lib/quandl/cassandra/models/data/search_spec.rb
236
238
  - spec/lib/quandl/cassandra/models/data_spec.rb
237
239
  - spec/lib/quandl/cassandra/models/dataset/collapse_spec.rb
238
240
  - spec/lib/quandl/cassandra/models/dataset/columns_spec.rb
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "1.9.3"
4
- script: bundle exec rspec
5
- source_key: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb2dJQkFBS0NBUUVBNGFHWmVzQk00V0V2TWtyVzNJODNwS2VmN3B0c3k5ZGRaNW1mT01zYm5PQnZBZ1NvClpPdHprdmw2ellYYU9Tazc4UmlYamozQVJhTG9VMU5ORWNEbVcxbHpEQlFWdjFLbmVEUGduZkoyNlNmZGJoYjAKV1ZXdWlSRldLV0I0c0Rabk0yWm42TTQ3MUpodVhFVGU5a3BiSjFIOEFSbll5LzBtSGJZQj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