data_miner 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/data_miner.gemspec +1 -1
- data/lib/data_miner/configuration.rb +2 -2
- data/lib/data_miner/process.rb +21 -5
- data/test/data_miner_test.rb +14 -7
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
data/data_miner.gemspec
CHANGED
@@ -16,9 +16,9 @@ module DataMiner
|
|
16
16
|
args.each { |arg| unique_indices.add arg }
|
17
17
|
end
|
18
18
|
|
19
|
-
def process(
|
19
|
+
def process(method_name_or_block_description, &block)
|
20
20
|
self.runnable_counter += 1
|
21
|
-
runnables << DataMiner::Process.new(self, runnable_counter,
|
21
|
+
runnables << DataMiner::Process.new(self, runnable_counter, method_name_or_block_description, &block)
|
22
22
|
end
|
23
23
|
|
24
24
|
def import(options = {}, &block)
|
data/lib/data_miner/process.rb
CHANGED
@@ -1,20 +1,36 @@
|
|
1
1
|
module DataMiner
|
2
2
|
class Process
|
3
|
-
attr_accessor :configuration, :position_in_run
|
3
|
+
attr_accessor :configuration, :position_in_run
|
4
|
+
attr_accessor :method_name
|
5
|
+
attr_accessor :block_description, :block
|
4
6
|
delegate :klass, :to => :configuration
|
5
7
|
|
6
|
-
def initialize(configuration, position_in_run,
|
8
|
+
def initialize(configuration, position_in_run, method_name_or_block_description, &block)
|
7
9
|
@configuration = configuration
|
8
10
|
@position_in_run = position_in_run
|
9
|
-
|
11
|
+
if block_given?
|
12
|
+
@block_description = method_name_or_block_description
|
13
|
+
@block = block
|
14
|
+
else
|
15
|
+
@method_name = method_name
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
def inspect
|
13
|
-
"Process(#{klass}) position #{position_in_run}"
|
20
|
+
str = "Process(#{klass}) position #{position_in_run}"
|
21
|
+
if block
|
22
|
+
str << " called :#{method_name}"
|
23
|
+
else
|
24
|
+
str << " ran block (#{block_description})"
|
25
|
+
end
|
14
26
|
end
|
15
27
|
|
16
28
|
def run(run)
|
17
|
-
|
29
|
+
if block
|
30
|
+
block.call
|
31
|
+
else
|
32
|
+
klass.send method_name
|
33
|
+
end
|
18
34
|
DataMiner.logger.info "ran #{inspect}"
|
19
35
|
end
|
20
36
|
end
|
data/test/data_miner_test.rb
CHANGED
@@ -446,7 +446,11 @@ class AutomobileVariant < ActiveRecord::Base
|
|
446
446
|
# derive :automobile_model_id # creates models by name
|
447
447
|
# associate :model_year, :key => :original_automobile_model_year_year, :foreign_key => :year
|
448
448
|
# associate :fuel_type, :key => :original_automobile_fuel_type_code, :foreign_key => :code
|
449
|
-
|
449
|
+
|
450
|
+
process 'Set adjusted fuel economy' do
|
451
|
+
update_all 'fuel_efficiency_city = 1 / ((0.003259 / 0.425143707) + (1.1805 / raw_fuel_efficiency_city))'
|
452
|
+
update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
|
453
|
+
end
|
450
454
|
end
|
451
455
|
|
452
456
|
def name
|
@@ -466,11 +470,6 @@ class AutomobileVariant < ActiveRecord::Base
|
|
466
470
|
end
|
467
471
|
|
468
472
|
class << self
|
469
|
-
def set_adjusted_fuel_economy
|
470
|
-
update_all 'fuel_efficiency_city = 1 / ((0.003259 / 0.425143707) + (1.1805 / raw_fuel_efficiency_city))'
|
471
|
-
update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
|
472
|
-
end
|
473
|
-
|
474
473
|
# the following matching methods are needed by the errata
|
475
474
|
# per https://brighterplanet.sifterapp.com/projects/30/issues/750/comments
|
476
475
|
|
@@ -871,6 +870,14 @@ class DataMinerTest < Test::Unit::TestCase
|
|
871
870
|
assert AutomobileVariant.first.row_hash.present?
|
872
871
|
end
|
873
872
|
|
873
|
+
should "process a callback block instead of a method" do
|
874
|
+
AutomobileVariant.delete_all
|
875
|
+
AutomobileVariant.data_miner_config.runnables[0].run(nil)
|
876
|
+
assert !AutomobileVariant.first.fuel_efficiency_city.present?
|
877
|
+
AutomobileVariant.data_miner_config.runnables.last.run(nil)
|
878
|
+
assert AutomobileVariant.first.fuel_efficiency_city.present?
|
879
|
+
end
|
880
|
+
|
874
881
|
# should "mine multiple classes in the correct order" do
|
875
882
|
# DataMiner.run
|
876
883
|
# uy = Country.find_by_iso_3166('UY')
|
@@ -917,7 +924,7 @@ class DataMinerTest < Test::Unit::TestCase
|
|
917
924
|
assert a != b
|
918
925
|
assert_equal b, Country.first.data_miner_last_run
|
919
926
|
end
|
920
|
-
|
927
|
+
|
921
928
|
unless ENV['FAST'] == 'true'
|
922
929
|
should "import using a dictionary" do
|
923
930
|
DataMiner.run :class_names => %w{ ResidentialEnergyConsumptionSurveyResponse }
|