data_miner 0.4.38 → 0.4.40
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/Rakefile +12 -8
- data/VERSION +1 -1
- data/data_miner.gemspec +6 -10
- data/lib/data_miner/{configuration.rb → base.rb} +13 -20
- data/lib/data_miner/import.rb +5 -11
- data/lib/data_miner/process.rb +4 -4
- data/lib/data_miner/run.rb +7 -8
- data/lib/data_miner/schema.rb +6 -8
- data/lib/data_miner/tap.rb +4 -4
- data/lib/data_miner.rb +10 -11
- data/test/data_miner_test.rb +35 -46
- data/test/test_helper.rb +0 -24
- metadata +7 -21
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "seamus@abshere.net"
|
11
11
|
gem.homepage = "http://github.com/seamusabshere/data_miner"
|
12
12
|
gem.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
13
|
-
gem.add_dependency 'remote_table', '>=0.2.
|
13
|
+
gem.add_dependency 'remote_table', '>=0.2.26'
|
14
14
|
gem.add_dependency 'escape', '>=0.0.4'
|
15
15
|
gem.add_dependency 'activerecord', '>=2.3.4'
|
16
16
|
gem.add_dependency 'activesupport', '>=2.3.4'
|
@@ -20,16 +20,20 @@ begin
|
|
20
20
|
gem.add_dependency 'log4r', '>=1.1.7'
|
21
21
|
gem.add_dependency 'errata', '>=0.2.1'
|
22
22
|
gem.add_dependency 'taps', '>=0.3.5'
|
23
|
-
|
24
|
-
gem.
|
25
|
-
|
23
|
+
## sabshere 5/25/10 i was told not to do this
|
24
|
+
# gem.add_development_dependency "loose_tight_dictionary", ">=0.0.5"
|
25
|
+
## sabshere 5/25/10 i don't think i need this
|
26
|
+
# gem.require_path = "lib"
|
27
|
+
# gem.files.include %w(lib/data_miner) unless gem.files.empty? # seems to fail once it's in the wild
|
26
28
|
gem.rdoc_options << '--line-numbers' << '--inline-source'
|
27
|
-
|
29
|
+
## sabshere 5/25/10 obsolete
|
30
|
+
# gem.rubyforge_project = "dataminer"
|
28
31
|
end
|
29
32
|
Jeweler::GemcutterTasks.new
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
## sabshere 5/25/10 obsolete
|
34
|
+
# Jeweler::RubyforgeTasks.new do |rubyforge|
|
35
|
+
# rubyforge.doc_task = "rdoc"
|
36
|
+
# end
|
33
37
|
rescue LoadError
|
34
38
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
35
39
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.40
|
data/data_miner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{data_miner}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.40"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-25}
|
13
13
|
s.description = %q{Mine remote data into your ActiveRecord models. You can also perform associations and convert units.}
|
14
14
|
s.email = %q{seamus@abshere.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"data_miner.gemspec",
|
28
28
|
"lib/data_miner.rb",
|
29
29
|
"lib/data_miner/attribute.rb",
|
30
|
-
"lib/data_miner/
|
30
|
+
"lib/data_miner/base.rb",
|
31
31
|
"lib/data_miner/dictionary.rb",
|
32
32
|
"lib/data_miner/import.rb",
|
33
33
|
"lib/data_miner/process.rb",
|
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.homepage = %q{http://github.com/seamusabshere/data_miner}
|
41
41
|
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source"]
|
42
42
|
s.require_paths = ["lib"]
|
43
|
-
s.rubyforge_project = %q{dataminer}
|
44
43
|
s.rubygems_version = %q{1.3.6}
|
45
44
|
s.summary = %q{Mine remote data into your ActiveRecord models.}
|
46
45
|
s.test_files = [
|
@@ -53,7 +52,7 @@ Gem::Specification.new do |s|
|
|
53
52
|
s.specification_version = 3
|
54
53
|
|
55
54
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_runtime_dependency(%q<remote_table>, [">= 0.2.
|
55
|
+
s.add_runtime_dependency(%q<remote_table>, [">= 0.2.26"])
|
57
56
|
s.add_runtime_dependency(%q<escape>, [">= 0.0.4"])
|
58
57
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.4"])
|
59
58
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
@@ -63,9 +62,8 @@ Gem::Specification.new do |s|
|
|
63
62
|
s.add_runtime_dependency(%q<log4r>, [">= 1.1.7"])
|
64
63
|
s.add_runtime_dependency(%q<errata>, [">= 0.2.1"])
|
65
64
|
s.add_runtime_dependency(%q<taps>, [">= 0.3.5"])
|
66
|
-
s.add_development_dependency(%q<loose_tight_dictionary>, [">= 0.0.5"])
|
67
65
|
else
|
68
|
-
s.add_dependency(%q<remote_table>, [">= 0.2.
|
66
|
+
s.add_dependency(%q<remote_table>, [">= 0.2.26"])
|
69
67
|
s.add_dependency(%q<escape>, [">= 0.0.4"])
|
70
68
|
s.add_dependency(%q<activerecord>, [">= 2.3.4"])
|
71
69
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
@@ -75,10 +73,9 @@ Gem::Specification.new do |s|
|
|
75
73
|
s.add_dependency(%q<log4r>, [">= 1.1.7"])
|
76
74
|
s.add_dependency(%q<errata>, [">= 0.2.1"])
|
77
75
|
s.add_dependency(%q<taps>, [">= 0.3.5"])
|
78
|
-
s.add_dependency(%q<loose_tight_dictionary>, [">= 0.0.5"])
|
79
76
|
end
|
80
77
|
else
|
81
|
-
s.add_dependency(%q<remote_table>, [">= 0.2.
|
78
|
+
s.add_dependency(%q<remote_table>, [">= 0.2.26"])
|
82
79
|
s.add_dependency(%q<escape>, [">= 0.0.4"])
|
83
80
|
s.add_dependency(%q<activerecord>, [">= 2.3.4"])
|
84
81
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
@@ -88,7 +85,6 @@ Gem::Specification.new do |s|
|
|
88
85
|
s.add_dependency(%q<log4r>, [">= 1.1.7"])
|
89
86
|
s.add_dependency(%q<errata>, [">= 0.2.1"])
|
90
87
|
s.add_dependency(%q<taps>, [">= 0.3.5"])
|
91
|
-
s.add_dependency(%q<loose_tight_dictionary>, [">= 0.0.5"])
|
92
88
|
end
|
93
89
|
end
|
94
90
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module DataMiner
|
2
|
-
class
|
2
|
+
class Base
|
3
3
|
include Blockenspiel::DSL
|
4
4
|
|
5
5
|
attr_accessor :resource, :steps, :step_counter, :attributes
|
@@ -46,12 +46,13 @@ module DataMiner
|
|
46
46
|
def run(options = {})
|
47
47
|
options.symbolize_keys!
|
48
48
|
|
49
|
-
return if DataMiner::
|
50
|
-
DataMiner::
|
49
|
+
return if DataMiner::Base.call_stack.include? resource.name
|
50
|
+
DataMiner::Base.call_stack.push resource.name
|
51
51
|
|
52
52
|
finished = false
|
53
|
+
skipped = false
|
53
54
|
if DataMiner::Run.table_exists?
|
54
|
-
run = DataMiner::Run.create! :started_at => Time.now, :resource_name => resource.name
|
55
|
+
run = DataMiner::Run.create! :started_at => Time.now, :resource_name => resource.name, :killed => true
|
55
56
|
else
|
56
57
|
run = nil
|
57
58
|
DataMiner.log_info "Not logging individual runs. Please run DataMiner::Run.create_tables if you want to enable this."
|
@@ -63,11 +64,15 @@ module DataMiner
|
|
63
64
|
resource.reset_column_information
|
64
65
|
end
|
65
66
|
finished = true
|
66
|
-
rescue DataMiner::
|
67
|
+
rescue DataMiner::Finish
|
67
68
|
finished = true
|
69
|
+
rescue DataMiner::Skip
|
70
|
+
skipped = true
|
68
71
|
ensure
|
69
|
-
|
70
|
-
|
72
|
+
if DataMiner::Run.table_exists?
|
73
|
+
run.update_attributes! :terminated_at => Time.now, :finished => finished, :skipped => skipped, :killed => false
|
74
|
+
end
|
75
|
+
DataMiner::Base.call_stack.clear if DataMiner::Base.call_stack.first == resource.name
|
71
76
|
end
|
72
77
|
nil
|
73
78
|
end
|
@@ -118,15 +123,6 @@ You need to supply one of #{COMPLETE_UNIT_DEFINITIONS.map(&:inspect).to_sentence
|
|
118
123
|
|
119
124
|
def suggest_missing_column_migrations
|
120
125
|
missing_columns = Array.new
|
121
|
-
non_essential_missing_columns = Array.new
|
122
|
-
unless resource.column_names.include?('data_miner_touch_count')
|
123
|
-
non_essential_missing_columns << 'data_miner_touch_count'
|
124
|
-
DataMiner.log_info "Not counting how many times a row has been touched by data_miner."
|
125
|
-
end
|
126
|
-
unless resource.column_names.include?('data_miner_last_run_id')
|
127
|
-
non_essential_missing_columns << 'data_miner_last_run_id'
|
128
|
-
DataMiner.log_info "Not recording which run touched a row."
|
129
|
-
end
|
130
126
|
|
131
127
|
import_steps.each do |step|
|
132
128
|
step.attributes.each do |_, attribute|
|
@@ -156,19 +152,16 @@ and **replace** the resulting file with this:
|
|
156
152
|
class AddMissingColumnsTo#{resource.name} < ActiveRecord::Migration
|
157
153
|
def self.up
|
158
154
|
#{missing_columns.map { |column_name| " add_column :#{resource.table_name}, :#{column_name}, :#{column_name.end_with?('_units') ? 'string' : 'FIXME_WHAT_COLUMN_TYPE_AM_I' }" }.join("\n") }
|
159
|
-
#{non_essential_missing_columns.map { |column_name| " add_column :#{resource.table_name}, :#{column_name}, :integer #optional" }.join("\n") }
|
160
155
|
end
|
161
156
|
|
162
157
|
def self.down
|
163
158
|
#{missing_columns.map { |column_name| " remove_column :#{resource.table_name}, :#{column_name}" }.join("\n") }
|
164
|
-
#{non_essential_missing_columns.map { |column_name| " remove_column :#{resource.table_name}, :#{column_name} #optional" }.join("\n") }
|
165
159
|
end
|
166
160
|
end
|
167
161
|
|
168
162
|
On the other hand, if you're working directly with create_table, this might be helpful:
|
169
163
|
|
170
164
|
#{missing_columns.map { |column_name| "t.#{column_name.end_with?('_units') ? 'string' : 'FIXME_WHAT_COLUMN_TYPE_AM_I' } '#{column_name}'" }.join("\n") }
|
171
|
-
#{non_essential_missing_columns.map { |column_name| "t.integer '#{column_name}' #optional" }.join("\n") }
|
172
165
|
|
173
166
|
================================
|
174
167
|
}
|
@@ -190,7 +183,7 @@ On the other hand, if you're working directly with create_table, this might be h
|
|
190
183
|
|
191
184
|
resource_names.each do |resource_name|
|
192
185
|
if options[:resource_names].blank? or options[:resource_names].include?(resource_name)
|
193
|
-
resource_name.constantize.
|
186
|
+
resource_name.constantize.data_miner_base.run options
|
194
187
|
end
|
195
188
|
end
|
196
189
|
end
|
data/lib/data_miner/import.rb
CHANGED
@@ -3,15 +3,15 @@ module DataMiner
|
|
3
3
|
include Blockenspiel::DSL
|
4
4
|
|
5
5
|
attr_reader :attributes
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :base, :position_in_run, :table
|
7
7
|
attr_accessor :description
|
8
|
-
delegate :resource, :to => :
|
8
|
+
delegate :resource, :to => :base
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(base, position_in_run, description, table_options = {})
|
11
11
|
table_options.symbolize_keys!
|
12
12
|
|
13
13
|
@attributes = ActiveSupport::OrderedHash.new
|
14
|
-
@
|
14
|
+
@base = base
|
15
15
|
@position_in_run = position_in_run
|
16
16
|
@description = description
|
17
17
|
|
@@ -47,8 +47,6 @@ module DataMiner
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def run(run)
|
50
|
-
increment_counter = resource.column_names.include?('data_miner_touch_count')
|
51
|
-
log_run = resource.column_names.include?('data_miner_last_run_id')
|
52
50
|
primary_key = resource.primary_key
|
53
51
|
test_counter = 0
|
54
52
|
|
@@ -63,11 +61,7 @@ OUT: #{attributes.inject(Hash.new) { |memo, v| attr_name, attr = v; memo[attr_na
|
|
63
61
|
end
|
64
62
|
|
65
63
|
record = resource.send "find_or_initialize_by_#{@key}", attributes[@key].value_from_row(row)
|
66
|
-
|
67
|
-
if changes.any?
|
68
|
-
record.increment :data_miner_touch_count if increment_counter
|
69
|
-
record.data_miner_last_run = run if log_run
|
70
|
-
end
|
64
|
+
attributes.each { |_, attr| attr.set_record_from_row record, row }
|
71
65
|
record.save! if record.send(primary_key).present?
|
72
66
|
end
|
73
67
|
DataMiner.log_info "performed #{inspect}"
|
data/lib/data_miner/process.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module DataMiner
|
2
2
|
class Process
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :base, :position_in_run
|
4
4
|
attr_accessor :method_name
|
5
5
|
attr_accessor :block_description, :block
|
6
|
-
delegate :resource, :to => :
|
6
|
+
delegate :resource, :to => :base
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(base, position_in_run, method_name_or_block_description, &block)
|
9
|
+
@base = base
|
10
10
|
@position_in_run = position_in_run
|
11
11
|
if block_given?
|
12
12
|
@block_description = method_name_or_block_description
|
data/lib/data_miner/run.rb
CHANGED
@@ -5,22 +5,21 @@ module DataMiner
|
|
5
5
|
def resource
|
6
6
|
resource_name.constantize
|
7
7
|
end
|
8
|
-
|
9
|
-
def resource_records_last_touched_by_me
|
10
|
-
resource.scoped :conditions => { :data_miner_last_run_id => id }
|
11
|
-
end
|
12
|
-
|
8
|
+
|
13
9
|
class << self
|
14
10
|
def create_tables
|
15
|
-
return if table_exists?
|
16
|
-
connection.create_table 'data_miner_runs' do |t|
|
11
|
+
return if table_exists? and column_names.include?('skipped') # force a drop
|
12
|
+
connection.create_table 'data_miner_runs', :force => true do |t|
|
17
13
|
t.string 'resource_name'
|
14
|
+
t.boolean 'killed'
|
15
|
+
t.boolean 'skipped'
|
18
16
|
t.boolean 'finished'
|
19
17
|
t.datetime 'started_at'
|
20
|
-
t.datetime '
|
18
|
+
t.datetime 'terminated_at'
|
21
19
|
t.datetime 'created_at'
|
22
20
|
t.datetime 'updated_at'
|
23
21
|
end
|
22
|
+
reset_column_information
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
data/lib/data_miner/schema.rb
CHANGED
@@ -2,13 +2,13 @@ module DataMiner
|
|
2
2
|
class Schema
|
3
3
|
include Blockenspiel::DSL
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :base
|
6
6
|
attr_reader :position_in_run
|
7
7
|
attr_reader :create_table_options
|
8
|
-
delegate :resource, :to => :
|
8
|
+
delegate :resource, :to => :base
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(base, position_in_run, create_table_options)
|
11
|
+
@base = base
|
12
12
|
@position_in_run = position_in_run
|
13
13
|
@create_table_options = create_table_options
|
14
14
|
@create_table_options.symbolize_keys!
|
@@ -169,9 +169,7 @@ module DataMiner
|
|
169
169
|
|
170
170
|
EXTRA_COLUMNS = {
|
171
171
|
:updated_at => :datetime,
|
172
|
-
:created_at => :datetime
|
173
|
-
:data_miner_last_run_id => :integer,
|
174
|
-
:data_miner_touch_count => :integer
|
172
|
+
:created_at => :datetime
|
175
173
|
}
|
176
174
|
def _add_extra_columns
|
177
175
|
EXTRA_COLUMNS.each do |extra_name, extra_type|
|
@@ -237,4 +235,4 @@ module DataMiner
|
|
237
235
|
end
|
238
236
|
end
|
239
237
|
end
|
240
|
-
end
|
238
|
+
end
|
data/lib/data_miner/tap.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
|
2
2
|
module DataMiner
|
3
3
|
class Tap
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :base
|
5
5
|
attr_reader :position_in_run
|
6
6
|
attr_reader :description
|
7
7
|
attr_reader :source
|
8
8
|
attr_reader :options
|
9
|
-
delegate :resource, :to => :
|
9
|
+
delegate :resource, :to => :base
|
10
10
|
|
11
|
-
def initialize(
|
11
|
+
def initialize(base, position_in_run, description, source, options = {})
|
12
12
|
options.symbolize_keys!
|
13
13
|
DataMiner.log_or_raise "Tap has to be the first step." unless position_in_run == 0
|
14
|
-
@
|
14
|
+
@base = base
|
15
15
|
@position_in_run = position_in_run
|
16
16
|
@description = description
|
17
17
|
@source = source
|
data/lib/data_miner.rb
CHANGED
@@ -21,7 +21,7 @@ require 'tmpdir'
|
|
21
21
|
require 'zlib'
|
22
22
|
|
23
23
|
require 'data_miner/attribute'
|
24
|
-
require 'data_miner/
|
24
|
+
require 'data_miner/base'
|
25
25
|
require 'data_miner/dictionary'
|
26
26
|
require 'data_miner/import'
|
27
27
|
require 'data_miner/tap'
|
@@ -31,7 +31,8 @@ require 'data_miner/schema'
|
|
31
31
|
|
32
32
|
module DataMiner
|
33
33
|
class MissingHashColumn < StandardError; end
|
34
|
-
class
|
34
|
+
class Finish < StandardError; end
|
35
|
+
class Skip < StandardError; end
|
35
36
|
|
36
37
|
mattr_accessor :logger
|
37
38
|
|
@@ -71,11 +72,11 @@ module DataMiner
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def self.run(options = {})
|
74
|
-
DataMiner::
|
75
|
+
DataMiner::Base.run options
|
75
76
|
end
|
76
77
|
|
77
78
|
def self.resource_names
|
78
|
-
DataMiner::
|
79
|
+
DataMiner::Base.resource_names
|
79
80
|
end
|
80
81
|
|
81
82
|
# TODO this should probably live somewhere else
|
@@ -111,22 +112,20 @@ ActiveRecord::Base.class_eval do
|
|
111
112
|
|
112
113
|
DataMiner.resource_names.push self.name unless DataMiner.resource_names.include? self.name
|
113
114
|
|
114
|
-
belongs_to :data_miner_last_run, :class_name => 'DataMiner::Run'
|
115
|
-
|
116
115
|
# this is class_eval'ed here so that each ActiveRecord descendant has its own copy, or none at all
|
117
116
|
class_eval do
|
118
|
-
cattr_accessor :
|
117
|
+
cattr_accessor :data_miner_base
|
119
118
|
def self.data_miner_runs
|
120
119
|
DataMiner::Run.scoped :conditions => { :resource_name => name }
|
121
120
|
end
|
122
121
|
def self.run_data_miner!(options = {})
|
123
|
-
|
122
|
+
data_miner_base.run options
|
124
123
|
end
|
125
124
|
end
|
126
|
-
self.
|
125
|
+
self.data_miner_base = DataMiner::Base.new self
|
127
126
|
|
128
|
-
Blockenspiel.invoke block,
|
127
|
+
Blockenspiel.invoke block, data_miner_base
|
129
128
|
|
130
|
-
|
129
|
+
data_miner_base.after_invoke
|
131
130
|
end
|
132
131
|
end
|
data/test/data_miner_test.rb
CHANGED
@@ -1114,12 +1114,14 @@ class AutomobileMakeFleetYear < ActiveRecord::Base
|
|
1114
1114
|
string "make_year_name"
|
1115
1115
|
datetime "created_at"
|
1116
1116
|
datetime "updated_at"
|
1117
|
-
integer 'data_miner_touch_count'
|
1118
|
-
integer 'data_miner_last_run_id'
|
1119
1117
|
end
|
1120
1118
|
|
1121
|
-
process "
|
1122
|
-
raise DataMiner::
|
1119
|
+
process "finish if i tell you to" do
|
1120
|
+
raise DataMiner::Finish if $force_finish
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
process "skip if i tell you to" do
|
1124
|
+
raise DataMiner::Skip if $force_skip
|
1123
1125
|
end
|
1124
1126
|
|
1125
1127
|
# CAFE data privately emailed to Andy from Terry Anderson at the DOT/NHTSA
|
@@ -1168,15 +1170,28 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1168
1170
|
end
|
1169
1171
|
|
1170
1172
|
if ENV['ALL'] == 'true' or ENV['FAST'] == 'true'
|
1171
|
-
should "stop and finish if it gets a DataMiner::
|
1173
|
+
should "stop and finish if it gets a DataMiner::Finish" do
|
1174
|
+
AutomobileMakeFleetYear.delete_all
|
1175
|
+
AutomobileMakeFleetYear.data_miner_runs.delete_all
|
1176
|
+
$force_finish = true
|
1177
|
+
AutomobileMakeFleetYear.run_data_miner!
|
1178
|
+
assert_equal 0, AutomobileMakeFleetYear.count
|
1179
|
+
assert_equal true, (AutomobileMakeFleetYear.data_miner_runs.count > 0)
|
1180
|
+
assert_equal true, AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.finished? and not run.skipped and not run.killed? }
|
1181
|
+
$force_finish = false
|
1182
|
+
AutomobileMakeFleetYear.run_data_miner!
|
1183
|
+
assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
|
1184
|
+
end
|
1185
|
+
|
1186
|
+
should "stop and register skipped if it gets a DataMiner::Skip" do
|
1172
1187
|
AutomobileMakeFleetYear.delete_all
|
1173
1188
|
AutomobileMakeFleetYear.data_miner_runs.delete_all
|
1174
|
-
$
|
1189
|
+
$force_skip = true
|
1175
1190
|
AutomobileMakeFleetYear.run_data_miner!
|
1176
1191
|
assert_equal 0, AutomobileMakeFleetYear.count
|
1177
1192
|
assert_equal true, (AutomobileMakeFleetYear.data_miner_runs.count > 0)
|
1178
|
-
assert_equal true, AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.finished? }
|
1179
|
-
$
|
1193
|
+
assert_equal true, AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.skipped? and not run.finished? and not run.killed? }
|
1194
|
+
$force_skip = false
|
1180
1195
|
AutomobileMakeFleetYear.run_data_miner!
|
1181
1196
|
assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
|
1182
1197
|
end
|
@@ -1188,12 +1203,10 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1188
1203
|
# t.datetime 'created_at'
|
1189
1204
|
t.string 'census_region_name'
|
1190
1205
|
# t.integer 'census_region_number'
|
1191
|
-
# t.integer 'data_miner_touch_count'
|
1192
|
-
# t.integer 'data_miner_last_run_id'
|
1193
1206
|
end
|
1194
1207
|
ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_trois ADD INDEX (census_region_name)'
|
1195
1208
|
CensusDivisionTrois.reset_column_information
|
1196
|
-
missing_columns = %w{ updated_at created_at census_region_number
|
1209
|
+
missing_columns = %w{ updated_at created_at census_region_number }
|
1197
1210
|
|
1198
1211
|
# sanity check
|
1199
1212
|
missing_columns.each do |column|
|
@@ -1218,12 +1231,10 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1218
1231
|
# t.datetime 'created_at'
|
1219
1232
|
t.string 'census_region_name'
|
1220
1233
|
# t.integer 'census_region_number'
|
1221
|
-
# t.integer 'data_miner_touch_count'
|
1222
|
-
# t.integer 'data_miner_last_run_id'
|
1223
1234
|
end
|
1224
1235
|
ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_fours ADD INDEX (census_region_name)'
|
1225
1236
|
CensusDivisionFour.reset_column_information
|
1226
|
-
missing_columns = %w{ updated_at created_at census_region_number
|
1237
|
+
missing_columns = %w{ updated_at created_at census_region_number }
|
1227
1238
|
|
1228
1239
|
# sanity check
|
1229
1240
|
missing_columns.each do |column|
|
@@ -1288,39 +1299,39 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1288
1299
|
end
|
1289
1300
|
|
1290
1301
|
should "be idempotent" do
|
1291
|
-
Country.
|
1302
|
+
Country.data_miner_base.run
|
1292
1303
|
a = Country.count
|
1293
|
-
Country.
|
1304
|
+
Country.data_miner_base.run
|
1294
1305
|
b = Country.count
|
1295
1306
|
assert_equal a, b
|
1296
1307
|
|
1297
|
-
CensusRegion.
|
1308
|
+
CensusRegion.data_miner_base.run
|
1298
1309
|
a = CensusRegion.count
|
1299
|
-
CensusRegion.
|
1310
|
+
CensusRegion.data_miner_base.run
|
1300
1311
|
b = CensusRegion.count
|
1301
1312
|
assert_equal a, b
|
1302
1313
|
end
|
1303
1314
|
|
1304
1315
|
should "hash things" do
|
1305
|
-
AutomobileVariant.
|
1316
|
+
AutomobileVariant.data_miner_base.steps[0].run(nil)
|
1306
1317
|
assert AutomobileVariant.first.row_hash.present?
|
1307
1318
|
end
|
1308
1319
|
|
1309
1320
|
should "process a callback block instead of a method" do
|
1310
1321
|
AutomobileVariant.delete_all
|
1311
|
-
AutomobileVariant.
|
1322
|
+
AutomobileVariant.data_miner_base.steps[0].run(nil)
|
1312
1323
|
assert !AutomobileVariant.first.fuel_efficiency_city.present?
|
1313
|
-
AutomobileVariant.
|
1324
|
+
AutomobileVariant.data_miner_base.steps.last.run(nil)
|
1314
1325
|
assert AutomobileVariant.first.fuel_efficiency_city.present?
|
1315
1326
|
end
|
1316
1327
|
|
1317
1328
|
should "keep a log when it does a run" do
|
1318
1329
|
approx_started_at = Time.now
|
1319
1330
|
DataMiner.run :resource_names => %w{ Country }
|
1320
|
-
|
1331
|
+
approx_terminated_at = Time.now
|
1321
1332
|
last_run = DataMiner::Run.first(:conditions => { :resource_name => 'Country' }, :order => 'id DESC')
|
1322
1333
|
assert (last_run.started_at - approx_started_at).abs < 5 # seconds
|
1323
|
-
assert (last_run.
|
1334
|
+
assert (last_run.terminated_at - approx_terminated_at).abs < 5 # seconds
|
1324
1335
|
end
|
1325
1336
|
|
1326
1337
|
should "request a re-import from scratch" do
|
@@ -1331,29 +1342,7 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1331
1342
|
DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
|
1332
1343
|
assert !Country.exists?(:iso_3166 => 'JUNK')
|
1333
1344
|
end
|
1334
|
-
|
1335
|
-
should "track how many times a row was touched" do
|
1336
|
-
DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
|
1337
|
-
assert_equal 1, Country.first.data_miner_touch_count
|
1338
|
-
DataMiner.run :resource_names => %w{ Country }
|
1339
|
-
assert_equal 1, Country.first.data_miner_touch_count
|
1340
|
-
end
|
1341
|
-
|
1342
|
-
should "keep track of what the last import run that touched a row was" do
|
1343
|
-
DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
|
1344
|
-
a = DataMiner::Run.last
|
1345
|
-
assert_equal a, Country.first.data_miner_last_run
|
1346
|
-
DataMiner.run :resource_names => %w{ Country }
|
1347
|
-
b = DataMiner::Run.last
|
1348
|
-
assert a != b
|
1349
|
-
assert_equal a, Country.first.data_miner_last_run
|
1350
|
-
end
|
1351
|
-
|
1352
|
-
should "be able to get how many rows affected by a run" do
|
1353
|
-
DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
|
1354
|
-
assert_equal Country.first.data_miner_last_run.resource_records_last_touched_by_me.count, Country.count
|
1355
|
-
end
|
1356
|
-
|
1345
|
+
|
1357
1346
|
should "know what runs were on a resource" do
|
1358
1347
|
DataMiner.run :resource_names => %w{ Country }
|
1359
1348
|
DataMiner.run :resource_names => %w{ Country }
|
data/test/test_helper.rb
CHANGED
@@ -82,8 +82,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
82
82
|
t.datetime "updated_at"
|
83
83
|
|
84
84
|
t.string "row_hash"
|
85
|
-
t.integer 'data_miner_touch_count'
|
86
|
-
t.integer 'data_miner_last_run_id'
|
87
85
|
end
|
88
86
|
execute 'ALTER TABLE t100_flight_segments ADD PRIMARY KEY (row_hash);'
|
89
87
|
|
@@ -100,8 +98,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
100
98
|
t.float 'longitude'
|
101
99
|
t.datetime 'created_at'
|
102
100
|
t.datetime 'updated_at'
|
103
|
-
t.integer 'data_miner_touch_count'
|
104
|
-
t.integer 'data_miner_last_run_id'
|
105
101
|
end
|
106
102
|
execute 'ALTER TABLE airports ADD PRIMARY KEY (iata_code);'
|
107
103
|
|
@@ -110,8 +106,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
110
106
|
t.string "name"
|
111
107
|
t.datetime "created_at"
|
112
108
|
t.datetime "updated_at"
|
113
|
-
t.integer 'data_miner_touch_count'
|
114
|
-
t.integer 'data_miner_last_run_id'
|
115
109
|
end
|
116
110
|
execute "ALTER TABLE countries ADD PRIMARY KEY (iso_3166);"
|
117
111
|
|
@@ -120,8 +114,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
120
114
|
t.string "name"
|
121
115
|
t.datetime "updated_at"
|
122
116
|
t.datetime "created_at"
|
123
|
-
t.integer 'data_miner_touch_count'
|
124
|
-
t.integer 'data_miner_last_run_id'
|
125
117
|
end
|
126
118
|
execute "ALTER TABLE census_regions ADD PRIMARY KEY (number);"
|
127
119
|
|
@@ -133,8 +125,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
133
125
|
t.string 'census_region_name'
|
134
126
|
t.integer 'census_region_number'
|
135
127
|
|
136
|
-
t.integer 'data_miner_touch_count'
|
137
|
-
t.integer 'data_miner_last_run_id'
|
138
128
|
end
|
139
129
|
execute 'ALTER TABLE census_divisions ADD PRIMARY KEY (number);'
|
140
130
|
|
@@ -146,8 +136,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
146
136
|
t.string 'census_region_name'
|
147
137
|
t.integer 'census_region_number'
|
148
138
|
|
149
|
-
t.integer 'data_miner_touch_count'
|
150
|
-
t.integer 'data_miner_last_run_id'
|
151
139
|
end
|
152
140
|
execute 'ALTER TABLE census_division_deux ADD PRIMARY KEY (number);'
|
153
141
|
|
@@ -159,8 +147,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
159
147
|
t.string 'census_region_name'
|
160
148
|
t.integer 'census_region_number'
|
161
149
|
|
162
|
-
t.integer 'data_miner_touch_count'
|
163
|
-
t.integer 'data_miner_last_run_id'
|
164
150
|
end
|
165
151
|
execute 'ALTER TABLE crosscalling_census_divisions ADD PRIMARY KEY (number);'
|
166
152
|
|
@@ -195,8 +181,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
195
181
|
t.string 'fuel_efficiency_city_units'
|
196
182
|
|
197
183
|
t.string "row_hash"
|
198
|
-
t.integer 'data_miner_touch_count'
|
199
|
-
t.integer 'data_miner_last_run_id'
|
200
184
|
end
|
201
185
|
execute "ALTER TABLE automobile_variants ADD PRIMARY KEY (row_hash);"
|
202
186
|
|
@@ -207,8 +191,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
207
191
|
t.float "emission_factor"
|
208
192
|
t.float "annual_distance"
|
209
193
|
t.string "code"
|
210
|
-
t.integer 'data_miner_touch_count'
|
211
|
-
t.integer 'data_miner_last_run_id'
|
212
194
|
end
|
213
195
|
execute "ALTER TABLE automobile_fuel_types ADD PRIMARY KEY (code);"
|
214
196
|
|
@@ -282,8 +264,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
282
264
|
|
283
265
|
t.datetime "created_at"
|
284
266
|
t.datetime "updated_at"
|
285
|
-
t.integer 'data_miner_touch_count'
|
286
|
-
t.integer 'data_miner_last_run_id'
|
287
267
|
end
|
288
268
|
execute "ALTER TABLE residential_energy_consumption_survey_responses ADD PRIMARY KEY (department_of_energy_identifier);"
|
289
269
|
|
@@ -302,8 +282,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
302
282
|
# t.float 'endpoint_fuel'
|
303
283
|
t.datetime 'updated_at'
|
304
284
|
t.datetime 'created_at'
|
305
|
-
t.integer 'data_miner_touch_count'
|
306
|
-
t.integer 'data_miner_last_run_id'
|
307
285
|
end
|
308
286
|
execute 'ALTER TABLE aircraft ADD PRIMARY KEY (icao_code);'
|
309
287
|
|
@@ -322,8 +300,6 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
322
300
|
# t.float 'endpoint_fuel'
|
323
301
|
t.datetime 'updated_at'
|
324
302
|
t.datetime 'created_at'
|
325
|
-
t.integer 'data_miner_touch_count'
|
326
|
-
t.integer 'data_miner_last_run_id'
|
327
303
|
end
|
328
304
|
execute 'ALTER TABLE aircraft_deux ADD PRIMARY KEY (icao_code);'
|
329
305
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 40
|
9
|
+
version: 0.4.40
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Seamus Abshere
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-25 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 2
|
31
|
-
-
|
32
|
-
version: 0.2.
|
31
|
+
- 26
|
32
|
+
version: 0.2.26
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -158,20 +158,6 @@ dependencies:
|
|
158
158
|
version: 0.3.5
|
159
159
|
type: :runtime
|
160
160
|
version_requirements: *id010
|
161
|
-
- !ruby/object:Gem::Dependency
|
162
|
-
name: loose_tight_dictionary
|
163
|
-
prerelease: false
|
164
|
-
requirement: &id011 !ruby/object:Gem::Requirement
|
165
|
-
requirements:
|
166
|
-
- - ">="
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
segments:
|
169
|
-
- 0
|
170
|
-
- 0
|
171
|
-
- 5
|
172
|
-
version: 0.0.5
|
173
|
-
type: :development
|
174
|
-
version_requirements: *id011
|
175
161
|
description: Mine remote data into your ActiveRecord models. You can also perform associations and convert units.
|
176
162
|
email: seamus@abshere.net
|
177
163
|
executables: []
|
@@ -192,7 +178,7 @@ files:
|
|
192
178
|
- data_miner.gemspec
|
193
179
|
- lib/data_miner.rb
|
194
180
|
- lib/data_miner/attribute.rb
|
195
|
-
- lib/data_miner/
|
181
|
+
- lib/data_miner/base.rb
|
196
182
|
- lib/data_miner/dictionary.rb
|
197
183
|
- lib/data_miner/import.rb
|
198
184
|
- lib/data_miner/process.rb
|
@@ -228,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
214
|
version: "0"
|
229
215
|
requirements: []
|
230
216
|
|
231
|
-
rubyforge_project:
|
217
|
+
rubyforge_project:
|
232
218
|
rubygems_version: 1.3.6
|
233
219
|
signing_key:
|
234
220
|
specification_version: 3
|