earth 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/Gemfile +4 -5
  2. data/README.markdown +0 -8
  3. data/Rakefile +14 -10
  4. data/bin/earth_tester.rb +12 -12
  5. data/earth.gemspec +2 -1
  6. data/features/automobile_make_fleet_year.feature +9 -19
  7. data/features/automobile_make_model_year.feature +4 -4
  8. data/features/support/env.rb +11 -7
  9. data/features/support/imports/automobile_make_fleet_year_bad.csv +1 -1
  10. data/features/support/imports/automobile_make_fleet_year_good.csv +1 -1
  11. data/features/support/imports/automobile_make_model_year_bad.csv +1 -1
  12. data/features/support/imports/automobile_make_model_year_good.csv +1 -1
  13. data/lib/earth/air/aircraft/data_miner.rb +63 -15
  14. data/lib/earth/air/aircraft.rb +0 -11
  15. data/lib/earth/air/aircraft_class/data_miner.rb +0 -13
  16. data/lib/earth/air/aircraft_class.rb +12 -3
  17. data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
  18. data/lib/earth/air/aircraft_fuel_use_equation.rb +12 -3
  19. data/lib/earth/air/airline/data_miner.rb +0 -7
  20. data/lib/earth/air/airline.rb +6 -3
  21. data/lib/earth/air/airport/data_miner.rb +5 -14
  22. data/lib/earth/air/airport.rb +9 -7
  23. data/lib/earth/air/bts_aircraft/data_miner.rb +0 -5
  24. data/lib/earth/air/bts_aircraft.rb +3 -3
  25. data/lib/earth/air/data_miner.rb +2 -3
  26. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -6
  27. data/lib/earth/air/flight_distance_class.rb +4 -3
  28. data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
  29. data/lib/earth/air/flight_seat_class.rb +6 -3
  30. data/lib/earth/air/flight_segment/data_miner.rb +30 -112
  31. data/lib/earth/air/flight_segment.rb +47 -13
  32. data/lib/earth/air.rb +2 -1
  33. data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -25
  34. data/lib/earth/automobile/automobile_fuel.rb +24 -8
  35. data/lib/earth/automobile/automobile_make/data_miner.rb +3 -16
  36. data/lib/earth/automobile/automobile_make.rb +5 -3
  37. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +16 -30
  38. data/lib/earth/automobile/automobile_make_fleet_year.rb +10 -7
  39. data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -11
  40. data/lib/earth/automobile/automobile_make_model.rb +9 -7
  41. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +4 -17
  42. data/lib/earth/automobile/automobile_make_model_year.rb +11 -6
  43. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +37 -65
  44. data/lib/earth/automobile/automobile_make_model_year_variant.rb +36 -6
  45. data/lib/earth/automobile/automobile_make_year/data_miner.rb +3 -15
  46. data/lib/earth/automobile/automobile_make_year.rb +8 -7
  47. data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -15
  48. data/lib/earth/automobile/automobile_size_class.rb +13 -2
  49. data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -11
  50. data/lib/earth/automobile/automobile_size_class_year.rb +10 -3
  51. data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -12
  52. data/lib/earth/automobile/automobile_type_fuel_age.rb +10 -2
  53. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -11
  54. data/lib/earth/automobile/automobile_type_fuel_control.rb +9 -3
  55. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -17
  56. data/lib/earth/automobile/automobile_type_fuel_year.rb +14 -6
  57. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -13
  58. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +12 -7
  59. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -11
  60. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +9 -6
  61. data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -10
  62. data/lib/earth/automobile/automobile_type_year.rb +9 -3
  63. data/lib/earth/bus/bus_class/data_miner.rb +0 -29
  64. data/lib/earth/bus/bus_class.rb +27 -2
  65. data/lib/earth/bus/bus_fuel/data_miner.rb +1 -16
  66. data/lib/earth/bus/bus_fuel.rb +15 -8
  67. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -10
  68. data/lib/earth/bus/bus_fuel_control.rb +8 -3
  69. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -10
  70. data/lib/earth/bus/bus_fuel_year_control.rb +8 -7
  71. data/lib/earth/bus/data_miner.rb +2 -0
  72. data/lib/earth/bus.rb +2 -0
  73. data/lib/earth/computation/computation_carrier/data_miner.rb +0 -5
  74. data/lib/earth/computation/computation_carrier.rb +3 -2
  75. data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -8
  76. data/lib/earth/computation/computation_carrier_instance_class.rb +6 -6
  77. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -7
  78. data/lib/earth/computation/computation_carrier_region.rb +6 -7
  79. data/lib/earth/computation/data_miner.rb +2 -0
  80. data/lib/earth/computation.rb +2 -0
  81. data/lib/earth/diet/diet_class/data_miner.rb +0 -16
  82. data/lib/earth/diet/diet_class.rb +16 -4
  83. data/lib/earth/diet/food_group/data_miner.rb +0 -9
  84. data/lib/earth/diet/food_group.rb +7 -2
  85. data/lib/earth/fuel/fuel/data_miner.rb +0 -16
  86. data/lib/earth/fuel/fuel.rb +14 -2
  87. data/lib/earth/fuel/fuel_price/data_miner.rb +0 -6
  88. data/lib/earth/fuel/fuel_price.rb +4 -6
  89. data/lib/earth/fuel/fuel_type/data_miner.rb +0 -14
  90. data/lib/earth/fuel/fuel_type.rb +14 -4
  91. data/lib/earth/fuel/fuel_year/data_miner.rb +0 -16
  92. data/lib/earth/fuel/fuel_year.rb +14 -2
  93. data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -9
  94. data/lib/earth/fuel/greenhouse_gas.rb +10 -5
  95. data/lib/earth/hospitality/lodging_class/data_miner.rb +0 -12
  96. data/lib/earth/hospitality/lodging_class.rb +10 -2
  97. data/lib/earth/industry/data_miner.rb +0 -0
  98. data/lib/earth/industry/industry.rb +3 -10
  99. data/lib/earth/industry/industry_product.rb +6 -13
  100. data/lib/earth/industry/industry_product_line.rb +5 -12
  101. data/lib/earth/industry/industry_sector.rb +5 -12
  102. data/lib/earth/industry/merchant.rb +4 -11
  103. data/lib/earth/industry/merchant_category.rb +3 -10
  104. data/lib/earth/industry/merchant_category_industry.rb +5 -12
  105. data/lib/earth/industry/product_line.rb +5 -12
  106. data/lib/earth/industry/product_line_industry_product.rb +5 -12
  107. data/lib/earth/industry/sector.rb +5 -12
  108. data/lib/earth/locality/census_division/data_miner.rb +0 -23
  109. data/lib/earth/locality/census_division.rb +21 -6
  110. data/lib/earth/locality/census_region/data_miner.rb +0 -5
  111. data/lib/earth/locality/census_region.rb +3 -2
  112. data/lib/earth/locality/climate_division/data_miner.rb +0 -7
  113. data/lib/earth/locality/climate_division.rb +5 -7
  114. data/lib/earth/locality/country/data_miner.rb +16 -29
  115. data/lib/earth/locality/country.rb +15 -4
  116. data/lib/earth/locality/data_miner.rb +3 -0
  117. data/lib/earth/locality/egrid_region/data_miner.rb +0 -5
  118. data/lib/earth/locality/egrid_region.rb +5 -8
  119. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -20
  120. data/lib/earth/locality/egrid_subregion.rb +17 -6
  121. data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +4 -13
  122. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +8 -4
  123. data/lib/earth/locality/state/data_miner.rb +0 -8
  124. data/lib/earth/locality/state.rb +6 -7
  125. data/lib/earth/locality/urbanity/data_miner.rb +0 -4
  126. data/lib/earth/locality/urbanity.rb +2 -2
  127. data/lib/earth/locality/zip_code/data_miner.rb +0 -10
  128. data/lib/earth/locality/zip_code.rb +8 -6
  129. data/lib/earth/locality.rb +3 -0
  130. data/lib/earth/pet/breed/data_miner.rb +0 -7
  131. data/lib/earth/pet/breed.rb +5 -6
  132. data/lib/earth/pet/breed_gender/data_miner.rb +0 -8
  133. data/lib/earth/pet/breed_gender.rb +6 -6
  134. data/lib/earth/pet/gender/data_miner.rb +0 -3
  135. data/lib/earth/pet/gender.rb +2 -2
  136. data/lib/earth/pet/species/data_miner.rb +0 -17
  137. data/lib/earth/pet/species.rb +17 -4
  138. data/lib/earth/rail/rail_class/data_miner.rb +0 -14
  139. data/lib/earth/rail/rail_class.rb +12 -3
  140. data/lib/earth/residence/air_conditioner_use/data_miner.rb +0 -6
  141. data/lib/earth/residence/air_conditioner_use.rb +5 -3
  142. data/lib/earth/residence/clothes_machine_use/data_miner.rb +0 -6
  143. data/lib/earth/residence/clothes_machine_use.rb +4 -2
  144. data/lib/earth/residence/data_miner.rb +2 -0
  145. data/lib/earth/residence/dishwasher_use/data_miner.rb +0 -6
  146. data/lib/earth/residence/dishwasher_use.rb +5 -3
  147. data/lib/earth/residence/residence_appliance/data_miner.rb +0 -6
  148. data/lib/earth/residence/residence_appliance.rb +4 -2
  149. data/lib/earth/residence/residence_class/data_miner.rb +0 -4
  150. data/lib/earth/residence/residence_class.rb +2 -2
  151. data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -14
  152. data/lib/earth/residence/residence_fuel_price.rb +12 -7
  153. data/lib/earth/residence/residence_fuel_type/data_miner.rb +0 -8
  154. data/lib/earth/residence/residence_fuel_type.rb +6 -2
  155. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -94
  156. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +92 -6
  157. data/lib/earth/residence.rb +2 -0
  158. data/lib/earth/shipping/carrier/data_miner.rb +0 -10
  159. data/lib/earth/shipping/carrier.rb +8 -2
  160. data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -10
  161. data/lib/earth/shipping/carrier_mode.rb +9 -3
  162. data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -7
  163. data/lib/earth/shipping/shipment_mode.rb +5 -2
  164. data/lib/earth/version.rb +1 -1
  165. data/lib/earth.rb +92 -84
  166. data/spec/earth/air/aircraft_spec.rb +1 -1
  167. data/spec/earth_spec.rb +15 -15
  168. data/spec/spec_helper.rb +12 -9
  169. metadata +175 -171
  170. data/lib/earth/active_record_ext.rb +0 -9
  171. data/lib/earth/air/aircraft_manufacturer/data_miner.rb +0 -21
  172. data/lib/earth/air/aircraft_manufacturer.rb +0 -7
  173. data/lib/earth/base.rb +0 -7
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
- source :rubygems
1
+ gem 'data_miner', :path => ENV['LOCAL_DATA_MINER'] if ENV['LOCAL_DATA_MINER']
2
+ gem 'create_table', :path => ENV['LOCAL_CREATE_TABLE'] if ENV['LOCAL_CREATE_TABLE']
2
3
 
3
- # Specify your gem's dependencies in earth.gemspec
4
- gemspec
4
+ source :rubygems
5
5
 
6
- gem 'data_miner', :path => ENV['LOCAL_DATA_MINER'] if ENV['LOCAL_DATA_MINER']
7
- gem 'sniff', :path => ENV['LOCAL_SNIFF'] if ENV['LOCAL_SNIFF']
6
+ gemspec :path => '.'
8
7
 
9
8
  if RUBY_VERSION < "1.9"
10
9
  gem 'fastercsv'
data/README.markdown CHANGED
@@ -11,14 +11,6 @@ The data that these models represent can be pulled from http://data.brighterplan
11
11
  ft = AutomobileFuel.first
12
12
  ...
13
13
 
14
- You can also run data imports via the data_miner gem.
15
-
16
- require 'earth'
17
- Earth.init :fuel
18
- Earth.taps_server # 'http://user:pass@data.brighterplanet.com'
19
-
20
- DataMiner.run :resource_names #> [FuelPrice]</tt>
21
-
22
14
  ## Collaboration cycle
23
15
  Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
24
16
 
data/Rakefile CHANGED
@@ -24,11 +24,13 @@ Cucumber::Rake::Task.new(:features) do |t|
24
24
  end
25
25
  end
26
26
 
27
- desc "Run cucumber tests with RCov"
28
- Cucumber::Rake::Task.new(:features_with_coverage) do |t|
29
- t.cucumber_opts = "features --format pretty"
30
- t.rcov = true
31
- t.rcov_opts = ['--exclude', 'features']
27
+ if RUBY_VERSION =~ /^1\.8/
28
+ desc "Run cucumber tests with RCov"
29
+ Cucumber::Rake::Task.new(:features_with_coverage) do |t|
30
+ t.cucumber_opts = "features --format pretty"
31
+ t.rcov = true
32
+ t.rcov_opts = ['--exclude', 'features']
33
+ end
32
34
  end
33
35
 
34
36
  require 'rspec/core/rake_task'
@@ -41,11 +43,13 @@ RSpec::Core::RakeTask.new(:examples) do |c|
41
43
  end
42
44
  end
43
45
 
44
- desc "Run specs with RCov"
45
- RSpec::Core::RakeTask.new(:examples_with_coverage) do |t|
46
- t.rcov = true
47
- t.rcov_opts = ['--exclude', 'spec']
48
- t.rspec_opts = '-Ispec'
46
+ if RUBY_VERSION =~ /^1\.8/
47
+ desc "Run specs with RCov"
48
+ RSpec::Core::RakeTask.new(:examples_with_coverage) do |t|
49
+ t.rcov = true
50
+ t.rcov_opts = ['--exclude', 'spec']
51
+ t.rspec_opts = '-Ispec'
52
+ end
49
53
  end
50
54
 
51
55
  task :test => [:features, :examples]
data/bin/earth_tester.rb CHANGED
@@ -14,19 +14,19 @@ end
14
14
  require 'active_support/all'
15
15
  require 'active_record'
16
16
 
17
- ActiveRecord::Schema.verbose = false
18
- begin
19
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
20
- rescue ArgumentError
21
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :dbfile => ':memory:')
22
- end
17
+ ActiveRecord::Base.establish_connection(
18
+ 'adapter' => 'mysql',
19
+ 'database' => 'test_earth',
20
+ 'username' => 'root',
21
+ 'password' => 'password',
22
+ 'encoding' => 'utf8' # very, very important
23
+ )
23
24
 
24
25
  require 'earth'
25
26
 
26
- Earth.init :load_data_miner => true, :apply_schemas => true
27
+ Earth.init ARGV[0], :load_data_miner => true, :apply_schemas => true
27
28
 
28
- if ARGV[0].present?
29
- eval ARGV[0]
30
- else
31
- $stderr.puts "Usage: earth_tester.rb 'ResidenceFuelPrice.run_data_miner!' (Note single quotes)"
32
- end
29
+ ActiveRecord::Base.logger = Logger.new $stderr
30
+ ActiveRecord::Base.logger.level = Logger::INFO
31
+
32
+ ARGV[1].camelcase.constantize.run_data_miner!
data/earth.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency 'geokit-rails'
37
37
  s.add_runtime_dependency 'loose_tight_dictionary', '>=0.2.3'
38
38
  s.add_runtime_dependency 'weighted_average'
39
+ s.add_runtime_dependency 'create_table', '>=0.0.2'
39
40
  s.add_development_dependency 'bundler'
40
41
  s.add_development_dependency 'bueller'
41
42
  s.add_development_dependency 'cucumber'
@@ -43,6 +44,6 @@ Gem::Specification.new do |s|
43
44
  s.add_development_dependency 'rdoc'
44
45
  s.add_development_dependency 'rdoc'
45
46
  s.add_development_dependency 'rspec'
46
- s.add_development_dependency 'ruby-debug19'
47
47
  s.add_development_dependency 'sqlite3-ruby'
48
+ s.add_development_dependency 'mysql' # for bin/earth_tester.rb
48
49
  end
@@ -2,42 +2,32 @@ Feature: Data import for AutomobileMakeFleetYear
2
2
  As a data user
3
3
  I want to import MakeFleetYear data
4
4
  So that I can perform year-based calculations
5
-
6
- Scenario: Successfully verifying that year is from 1978 to 2009
7
- Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_good"
8
- When a data import verifies "Year should be from 1978 to 2009"
9
- Then the verification should be successful
10
5
 
11
- Scenario: Successfully verifying that fuel efficiency is greater than zero
6
+ Scenario: Successfully verifying that year is from 1978 to 2010
12
7
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_good"
13
- When a data import verifies "Fuel efficiency should be greater than zero"
8
+ When a data import verifies "Year should be from 1978 to 2010"
14
9
  Then the verification should be successful
15
10
 
16
- Scenario: Successfully verifying that volume is greater than zero
11
+ Scenario: Successfully verifying that fuel efficiency and volume are greater than zero
17
12
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_good"
18
- When a data import verifies "Volume should be greater than zero"
13
+ When a data import verifies "Fuel efficiency and volume should be greater than zero"
19
14
  Then the verification should be successful
20
-
15
+
21
16
  Scenario: Successfully verifying that fuel efficiency units are kilometres per litre
22
17
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_good"
23
18
  When a data import verifies "Fuel efficiency units should be kilometres per litre"
24
19
  Then the verification should be successful
25
20
 
26
- Scenario: Failing to verify that year is from 1978 to 2009
21
+ Scenario: Failing to verify that year is from 1978 to 2010
27
22
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_bad"
28
- When a data import verifies "Year should be from 1978 to 2009"
23
+ When a data import verifies "Year should be from 1978 to 2010"
29
24
  Then the verification should not be successful
30
25
 
31
- Scenario: Failing to verify that fuel efficiency is greater than zero
26
+ Scenario: Failing to verify that fuel efficiency and volume are greater than zero
32
27
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_bad"
33
- When a data import verifies "Fuel efficiency should be greater than zero"
28
+ When a data import verifies "Fuel efficiency and volume should be greater than zero"
34
29
  Then the verification should not be successful
35
30
 
36
- Scenario: Failing to verify that volume is greater than zero
37
- Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_bad"
38
- When a data import verifies "Volume should be greater than zero"
39
- Then the verification should not be successful
40
-
41
31
  Scenario: Failing to verify that fuel efficiency units are kilometres per litre
42
32
  Given a "AutomobileMakeFleetYear" data import fetches results listed in "automobile_make_fleet_year_bad"
43
33
  When a data import verifies "Fuel efficiency units should be kilometres per litre"
@@ -3,9 +3,9 @@ Feature: Data import for AutomobileMakeModelYear
3
3
  I want to import MakeModelYear data
4
4
  So that I can perform model year-based calculations
5
5
 
6
- Scenario: Successfully verifying that year is from 1985 to 2010
6
+ Scenario: Successfully verifying that year is from 1985 to 2011
7
7
  Given a "AutomobileMakeModelYear" data import fetches results listed in "automobile_make_model_year_good"
8
- When a data import verifies "Year should be from 1985 to 2010"
8
+ When a data import verifies "Year should be from 1985 to 2011"
9
9
  Then the verification should be successful
10
10
 
11
11
  Scenario: Successfully verifying that fuel efficiences are greater than zero
@@ -18,9 +18,9 @@ Feature: Data import for AutomobileMakeModelYear
18
18
  When a data import verifies "Fuel efficiency units should be kilometres per litre"
19
19
  Then the verification should be successful
20
20
 
21
- Scenario: Failing to verify that year is from 1985 to 2010
21
+ Scenario: Failing to verify that year is from 1985 to 2011
22
22
  Given a "AutomobileMakeModelYear" data import fetches results listed in "automobile_make_model_year_bad"
23
- When a data import verifies "Year should be from 1985 to 2010"
23
+ When a data import verifies "Year should be from 1985 to 2011"
24
24
  Then the verification should not be successful
25
25
 
26
26
  Scenario: Failing to verify that fuel efficiences are greater than zero
@@ -1,15 +1,19 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
-
4
3
  Bundler.setup
5
-
4
+ require 'logger'
5
+ require 'active_record'
6
+ require 'data_miner'
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
9
  require 'earth'
7
10
 
8
- require 'data_miner'
9
- DataMiner.logger = Logger.new 'log/test.log'
11
+ logger = Logger.new 'log/test.log'
12
+ logger.level = Logger::DEBUG
10
13
 
11
- require 'active_record'
12
- require 'sqlite3'
13
- ActiveRecord::Base.logger = Logger.new 'log/test.log'
14
14
  ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
15
+ ActiveRecord::Base.logger = logger
16
+
17
+ DataMiner.logger = logger
18
+
15
19
  Earth.init :all, :apply_schemas => true
@@ -1,2 +1,2 @@
1
1
  name,year,fuel_efficiency,volume,fuel_efficiency_units
2
- Honda 2010 DP,2010,0,0
2
+ Honda 2011 DP,2011
@@ -1,2 +1,2 @@
1
1
  name,year,fuel_efficiency,volume,fuel_efficiency_units
2
- Honda 2009 DP,2009,15,2000,kilometres_per_litre
2
+ Honda 2010 DP,2010,15,2000,kilometres_per_litre
@@ -1,3 +1,3 @@
1
1
  name,year,fuel_efficiency_city,fuel_efficiency_highway,fuel_efficiency_city_units,fuel_efficiency_highway_units
2
2
  Toyota,2000,10,10.5,kilometres_per_litre,kilometres_per_litre
3
- Honda,2011,0,-10,foo
3
+ Honda,2012,0,-10,foo
@@ -1,3 +1,3 @@
1
1
  name,year,fuel_efficiency_city,fuel_efficiency_highway,fuel_efficiency_city_units,fuel_efficiency_highway_units
2
2
  Toyota,2000,10,10.5,kilometres_per_litre,kilometres_per_litre
3
- Honda,2010,20,21,kilometres_per_litre,kilometres_per_litre
3
+ Honda,2011,20,21,kilometres_per_litre,kilometres_per_litre
@@ -20,23 +20,23 @@ Aircraft.class_eval do
20
20
  @manufacturer_whitelist ||= RemoteTable.new(:url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdFRFalpOdlg1cnF6amlSM1dDc1lya2c&output=csv').map { |record| record['Manufacturer'].to_regexp }
21
21
  @manufacturer_whitelist.any? { |manufacturer_regexp| manufacturer_regexp.match candidate }
22
22
  end
23
+
24
+ create_table do
25
+ string 'icao_code'
26
+ string 'manufacturer_name'
27
+ string 'model_name'
28
+ string 'description'
29
+ string 'aircraft_type'
30
+ string 'engine_type'
31
+ integer 'engines'
32
+ string 'weight_class'
33
+ string 'class_code'
34
+ string 'fuel_use_code'
35
+ float 'seats'
36
+ float 'passengers'
37
+ end
23
38
 
24
39
  data_miner do
25
- schema Earth.database_options do
26
- string 'icao_code'
27
- string 'manufacturer_name'
28
- string 'model_name'
29
- string 'description'
30
- string 'aircraft_type'
31
- string 'engine_type'
32
- integer 'engines'
33
- string 'weight_class'
34
- string 'class_code'
35
- string 'fuel_use_code'
36
- float 'seats'
37
- float 'passengers'
38
- end
39
-
40
40
  ('A'..'Z').each do |letter|
41
41
  import("aircraft made by whitelisted manufacturers whose ICAO code starts with '#{letter}' from the FAA",
42
42
  :url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
@@ -96,6 +96,54 @@ Aircraft.class_eval do
96
96
  FlightSegment.run_data_miner!
97
97
  end
98
98
 
99
+ process "Cache fuzzy matches between FlightSegment aircraft_description and Aircraft description" do
100
+ LooseTightDictionary::CachedResult.setup
101
+ FlightSegment.find_by_sql("SELECT * FROM flight_segments GROUP BY aircraft_description HAVING aircraft_description IS NOT NULL").each do |flight_segment|
102
+ original_description = flight_segment.aircraft_description
103
+
104
+ # If the flight segment's aircraft_description contains '/' then it describes multiple aircraft.
105
+ # We need to synthesize descriptions for those aircraft, find all Aircraft that fuzzily match the
106
+ # synthesized descriptions, and associate those Aircraft with the original aircraft_description.
107
+ # e.g. boeing 747-100/200
108
+ if original_description.include?("/")
109
+ # Pull out the complete first aircraft description
110
+ # e.g. 'boeing 747-100'
111
+ first_description = original_description.split('/')[0]
112
+
113
+ # Pull out the root of the description - the text up to and including the last ' ' or '-'
114
+ # e.g. 'boeing 747-'
115
+ root_length = first_description.rindex(/[ \-]/)
116
+ root = first_description.slice(0..root_length)
117
+
118
+ # Pull out the suffixes - the text separated by forward slashes
119
+ # e.g. ['100', '200']
120
+ suffixes = original_description.split(root)[1].split('/')
121
+
122
+ # Create an array of synthesized descriptions by appending each suffix to the root
123
+ # e.g. ['boeing 747-100', 'boeing 747-200']
124
+ suffixes.map{ |suffix| root + suffix }.each do |synthesized_description|
125
+ # Look up the Aircraft that match each synthesized description and associate
126
+ # them with the original flight segment aircraft_description
127
+ Aircraft.loose_tight_dictionary.find_all(synthesized_description).each do |aircraft|
128
+ attrs = {
129
+ :a_class => "Aircraft",
130
+ :a => aircraft.description,
131
+ :b_class => "FlightSegment",
132
+ :b => original_description
133
+ }
134
+ unless ::LooseTightDictionary::CachedResult.exists? attrs
135
+ ::LooseTightDictionary::CachedResult.create! attrs
136
+ end
137
+ end
138
+ end
139
+ # If the flight segment's aircraft_description doesn't contain '/' we can use
140
+ # a method provided by loose_tight_dictionary to associate it with Aircraft
141
+ else
142
+ flight_segment.cache_aircraft!
143
+ end
144
+ end
145
+ end
146
+
99
147
  # FIXME TODO do we want to restrict this to certain years?
100
148
  process "Derive some average characteristics from flight segments" do
101
149
  Aircraft.find_each do |aircraft|
@@ -1,6 +1,3 @@
1
- # need this for association with FlightSegment through loose_tight_dictionary_cached_results
2
- require 'loose_tight_dictionary/cached_result'
3
-
4
1
  class Aircraft < ActiveRecord::Base
5
2
  set_primary_key :icao_code
6
3
 
@@ -22,12 +19,4 @@ class Aircraft < ActiveRecord::Base
22
19
 
23
20
  # Enable aircraft.flight_segments
24
21
  cache_loose_tight_dictionary_matches_with :flight_segments, :primary_key => :description, :foreign_key => :aircraft_description
25
-
26
- data_miner do
27
- tap "Brighter Planet's sanitized aircraft data", Earth.taps_server
28
-
29
- process "pull dependencies" do
30
- run_data_miner_on_belongs_to_associations
31
- end
32
- end
33
22
  end
@@ -1,18 +1,5 @@
1
1
  AircraftClass.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'code'
5
- float 'm3'
6
- string 'm3_units'
7
- float 'm2'
8
- string 'm2_units'
9
- float 'm1'
10
- string 'm1_units'
11
- float 'b'
12
- string 'b_units'
13
- float 'seats'
14
- end
15
-
16
3
  process "Ensure Aircraft is populated" do
17
4
  Aircraft.run_data_miner!
18
5
  end
@@ -10,8 +10,17 @@ class AircraftClass < ActiveRecord::Base
10
10
  def valid_fuel_use_equation?
11
11
  fuel_use_coefficients.all?(&:present?) and fuel_use_coefficients.any?(&:nonzero?)
12
12
  end
13
-
14
- data_miner do
15
- tap "Brighter Planet's aircraft class data", Earth.taps_server
13
+
14
+ create_table do
15
+ string 'code'
16
+ float 'm3'
17
+ string 'm3_units'
18
+ float 'm2'
19
+ string 'm2_units'
20
+ float 'm1'
21
+ string 'm1_units'
22
+ float 'b'
23
+ string 'b_units'
24
+ float 'seats'
16
25
  end
17
26
  end
@@ -1,18 +1,5 @@
1
1
  AircraftFuelUseEquation.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'code'
5
- string 'aircraft_description'
6
- float 'm3'
7
- string 'm3_units'
8
- float 'm2'
9
- string 'm2_units'
10
- float 'm1'
11
- string 'm1_units'
12
- float 'b'
13
- string 'b_units'
14
- end
15
-
16
3
  import "aircraft fuel use equations derived from EMEP/EEA and ICAO",
17
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDltUVZVekVobEJPYlpFNUpWNkwyYXc&output=csv' do
18
5
  key 'code'
@@ -19,8 +19,17 @@ class AircraftFuelUseEquation < ActiveRecord::Base
19
19
  def valid_fuel_use_equation?
20
20
  fuel_use_coefficients.all?(&:present?) and fuel_use_coefficients.any?(&:nonzero?)
21
21
  end
22
-
23
- data_miner do
24
- tap "Brighter Planet's sanitized aircraft fuel use data", Earth.taps_server
22
+
23
+ create_table do
24
+ string 'code'
25
+ string 'aircraft_description'
26
+ float 'm3'
27
+ string 'm3_units'
28
+ float 'm2'
29
+ string 'm2_units'
30
+ float 'm1'
31
+ string 'm1_units'
32
+ float 'b'
33
+ string 'b_units'
25
34
  end
26
35
  end
@@ -1,12 +1,5 @@
1
1
  Airline.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'name'
5
- string 'bts_code'
6
- string 'iata_code'
7
- string 'icao_code'
8
- end
9
-
10
3
  import "a Brighter Planet-curated list of airlines",
11
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDhoVHZmSTlZcHBsRUtPR0dPd0prMkE&output=csv' do
12
5
  key 'name'
@@ -1,7 +1,10 @@
1
1
  class Airline < ActiveRecord::Base
2
2
  set_primary_key :name
3
-
4
- data_miner do
5
- tap "Brighter Planet's sanitized airlines data", Earth.taps_server
3
+
4
+ create_table do
5
+ string 'name'
6
+ string 'bts_code'
7
+ string 'iata_code'
8
+ string 'icao_code'
6
9
  end
7
10
  end
@@ -15,19 +15,10 @@ Airport.class_eval do
15
15
  end
16
16
 
17
17
  data_miner do
18
- schema Earth.database_options do
19
- string 'iata_code'
20
- string 'name'
21
- string 'city'
22
- string 'country_name'
23
- string 'country_iso_3166_code'
24
- float 'latitude'
25
- float 'longitude'
26
- end
27
-
28
18
  import "the OpenFlights.org airports database",
29
19
  :url => 'https://openflights.svn.sourceforge.net/svnroot/openflights/openflights/data/airports.dat',
30
20
  :headers => %w{ id name city country_name iata_code icao_code latitude longitude altitude timezone daylight_savings },
21
+ :select => lambda { |record| record['iata_code'].present? },
31
22
  :errata => { :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFc2UzhQYU5PWEQ0N21yWFZGNmc2a3c&gid=0&output=csv',
32
23
  :responder => Airport::Guru.new } do
33
24
  key 'iata_code'
@@ -52,10 +43,10 @@ Airport.class_eval do
52
43
  Country.run_data_miner!
53
44
  end
54
45
 
55
- process "Replace country names with country ISO 3166 codes" do
56
- connection.select_values("SELECT DISTINCT country_name FROM airports WHERE country_name IS NOT NULL").each do |name|
57
- code = Country.find_by_name(name).iso_3166_code
58
- update_all %{country_iso_3166_code = "#{code}"}, %{country_name = "#{name}"}
46
+ process "Fill in blank country codes" do
47
+ Country.find_each do |country|
48
+ next unless country.name.present? and country.iso_3166_code.present?
49
+ update_all %{country_iso_3166_code = "#{country.iso_3166_code}"}, %{country_name LIKE "#{country.name}"}
59
50
  end
60
51
  end
61
52
 
@@ -6,12 +6,14 @@ class Airport < ActiveRecord::Base
6
6
  acts_as_mappable :default_units => :nms,
7
7
  :lat_column_name => :latitude,
8
8
  :lng_column_name => :longitude
9
-
10
- data_miner do
11
- tap "Brighter Planet's sanitized airports data", Earth.taps_server
12
-
13
- process "pull dependencies" do
14
- run_data_miner_on_belongs_to_associations
15
- end
9
+
10
+ create_table do
11
+ string 'iata_code'
12
+ string 'name'
13
+ string 'city'
14
+ string 'country_name'
15
+ string 'country_iso_3166_code'
16
+ float 'latitude'
17
+ float 'longitude'
16
18
  end
17
19
  end
@@ -1,10 +1,5 @@
1
1
  BtsAircraft.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'bts_code'
5
- string 'description'
6
- end
7
-
8
3
  import "the BTS aircraft type lookup table",
9
4
  :url => "http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE",
10
5
  :errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEZ2d3JQMzV5T1o1T3JmVlFyNUZxdEE&output=csv' } do
@@ -1,7 +1,7 @@
1
1
  class BtsAircraft < ActiveRecord::Base
2
2
  set_primary_key :bts_code
3
-
4
- data_miner do
5
- tap "Brighter Planet's BTS Aircraft data", Earth.taps_server
3
+ create_table do
4
+ string 'bts_code'
5
+ string 'description'
6
6
  end
7
7
  end
@@ -1,12 +1,11 @@
1
- require 'earth/locality'
2
- require 'earth/locality/data_miner'
3
1
  require 'earth/air/aircraft/data_miner'
4
2
  require 'earth/air/aircraft_class/data_miner'
5
3
  require 'earth/air/aircraft_fuel_use_equation/data_miner'
6
- require 'earth/air/aircraft_manufacturer/data_miner'
7
4
  require 'earth/air/airline/data_miner'
8
5
  require 'earth/air/airport/data_miner'
9
6
  require 'earth/air/bts_aircraft/data_miner'
10
7
  require 'earth/air/flight_distance_class/data_miner'
11
8
  require 'earth/air/flight_seat_class/data_miner'
12
9
  require 'earth/air/flight_segment/data_miner'
10
+
11
+ require 'earth/locality/data_miner'
@@ -1,11 +1,5 @@
1
1
  FlightDistanceClass.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'name'
5
- float 'distance'
6
- string 'distance_units'
7
- end
8
-
9
3
  import "a list of distance classes taken from the WRI business travel tool and UK DEFRA/DECC GHG Conversion Factors for Company Reporting",
10
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFBKM0xWaUhKVkxDRmdBVkE3VklxY2c&hl=en&gid=0&output=csv' do
11
5
  key 'name'
@@ -1,7 +1,8 @@
1
1
  class FlightDistanceClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
-
4
- data_miner do
5
- tap "Brighter Planet's sanitized distance class data", Earth.taps_server
3
+ create_table do
4
+ string 'name'
5
+ float 'distance'
6
+ string 'distance_units'
6
7
  end
7
8
  end
@@ -1,12 +1,5 @@
1
1
  FlightSeatClass.class_eval do
2
2
  data_miner do
3
- schema Earth.database_options do
4
- string 'name'
5
- string 'distance_class_name'
6
- string 'seat_class_name'
7
- float 'multiplier'
8
- end
9
-
10
3
  import "seat classes used in the WRI GHG Protocol calculation tools",
11
4
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdG5zSER1QmFVVkhNcTM2cmhCMEJtWVE&hl=en&gid=0&output=csv' do
12
5
  key 'name'
@@ -2,8 +2,11 @@ class FlightSeatClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
4
  falls_back_on :multiplier => 1
5
-
6
- data_miner do
7
- tap "Brighter Planet's sanitized flight seat class data", Earth.taps_server
5
+
6
+ create_table do
7
+ string 'name'
8
+ string 'distance_class_name'
9
+ string 'seat_class_name'
10
+ float 'multiplier'
8
11
  end
9
12
  end