earth 0.11.16 → 0.11.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/CHANGELOG +15 -0
  2. data/Gemfile +2 -2
  3. data/bin/earth_tester.rb +3 -1
  4. data/earth.gemspec +4 -8
  5. data/errata/aircraft/faa_errata.csv +375 -0
  6. data/errata/airport/openflights_errata.csv +1 -0
  7. data/errata/automobile_make_model_year_variant/feg_errata.csv +283 -0
  8. data/errata/automobile_make_year_fleet/cafe_errata.csv +1 -0
  9. data/errata/bts_aircraft/bts_errata.csv +68 -0
  10. data/errata/country/wri_errata.csv +25 -0
  11. data/errata/flight_segment/bts_errata.csv +1 -0
  12. data/errata/readme +3 -0
  13. data/features/step_definitions/data_steps.rb +1 -1
  14. data/lib/earth.rb +40 -75
  15. data/lib/earth/air/aircraft.rb +3 -1
  16. data/lib/earth/air/aircraft/data_miner.rb +2 -2
  17. data/lib/earth/air/airport.rb +1 -1
  18. data/lib/earth/air/airport/data_miner.rb +12 -32
  19. data/lib/earth/air/bts_aircraft/data_miner.rb +1 -1
  20. data/lib/earth/air/flight_segment/data_miner.rb +6 -7
  21. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +1 -1
  22. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +21 -42
  23. data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +4 -4
  24. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +8 -8
  25. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +24 -24
  26. data/lib/earth/fuel/fuel/data_miner.rb +2 -2
  27. data/lib/earth/fuel/fuel_price/data_miner.rb +1 -1
  28. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
  29. data/lib/earth/industry/naics_2002_naics_2007_concordance/data_miner.rb +3 -3
  30. data/lib/earth/industry/naics_2002_sic_1987_concordance/data_miner.rb +4 -4
  31. data/lib/earth/industry/sic_1987/data_miner.rb +3 -3
  32. data/lib/earth/locality/census_region/data_miner.rb +1 -1
  33. data/lib/earth/locality/country/data_miner.rb +2 -2
  34. data/lib/earth/locality/egrid_region/data_miner.rb +1 -1
  35. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -1
  36. data/lib/earth/locality/state/data_miner.rb +2 -2
  37. data/lib/earth/locality/zip_code.rb +1 -1
  38. data/lib/earth/pet/breed/data_miner.rb +1 -1
  39. data/lib/earth/pet/breed_gender/data_miner.rb +2 -2
  40. data/lib/earth/pet/gender/data_miner.rb +1 -1
  41. data/lib/earth/rail/country_rail_class/data_miner.rb +1 -1
  42. data/lib/earth/rail/country_rail_traction/data_miner.rb +1 -1
  43. data/lib/earth/rail/country_rail_traction_class/data_miner.rb +1 -1
  44. data/lib/earth/rail/national_transit_database_record/data_miner.rb +3 -3
  45. data/lib/earth/residence/residence_fuel_price/data_miner.rb +5 -5
  46. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +9 -9
  47. data/lib/earth/version.rb +1 -1
  48. data/spec/earth/air/aircraft_spec.rb +11 -5
  49. data/spec/earth/air/airport_spec.rb +40 -0
  50. data/spec/earth/air/bts_aircraft_spec.rb +19 -0
  51. data/spec/earth/air/flight_segment_spec.rb +49 -0
  52. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +55 -0
  53. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +37 -0
  54. data/spec/earth/locality/country_spec.rb +4 -0
  55. metadata +198 -172
  56. data/features/automobile_make_fleet_year.feature +0 -34
  57. data/features/automobile_make_model_year_variant.feature +0 -46
  58. data/features/support/imports/automobile_fuel_bad.csv +0 -3
  59. data/features/support/imports/automobile_fuel_good.csv +0 -3
  60. data/features/support/imports/automobile_make_bad.csv +0 -3
  61. data/features/support/imports/automobile_make_fleet_year_bad.csv +0 -2
  62. data/features/support/imports/automobile_make_fleet_year_good.csv +0 -2
  63. data/features/support/imports/automobile_make_good.csv +0 -3
  64. data/features/support/imports/automobile_make_model_bad.csv +0 -3
  65. data/features/support/imports/automobile_make_model_good.csv +0 -3
  66. data/features/support/imports/automobile_make_model_year_bad.csv +0 -3
  67. data/features/support/imports/automobile_make_model_year_good.csv +0 -3
  68. data/features/support/imports/automobile_make_model_year_variant_bad.csv +0 -3
  69. data/features/support/imports/automobile_make_model_year_variant_good.csv +0 -3
  70. data/features/support/imports/automobile_make_year_bad.csv +0 -3
  71. data/features/support/imports/automobile_make_year_good.csv +0 -3
  72. data/features/support/imports/automobile_size_class_bad.csv +0 -3
  73. data/features/support/imports/automobile_size_class_good.csv +0 -3
  74. data/features/support/imports/automobile_size_class_year_bad.csv +0 -2
  75. data/features/support/imports/automobile_size_class_year_good.csv +0 -2
  76. data/features/support/imports/automobile_type_fuel_age_bad.csv +0 -3
  77. data/features/support/imports/automobile_type_fuel_age_good.csv +0 -3
  78. data/features/support/imports/automobile_type_fuel_control_bad.csv +0 -3
  79. data/features/support/imports/automobile_type_fuel_control_good.csv +0 -3
  80. data/features/support/imports/automobile_type_fuel_year_age_bad.csv +0 -2
  81. data/features/support/imports/automobile_type_fuel_year_age_good.csv +0 -2
  82. data/features/support/imports/automobile_type_fuel_year_bad.csv +0 -2
  83. data/features/support/imports/automobile_type_fuel_year_control_bad.csv +0 -2
  84. data/features/support/imports/automobile_type_fuel_year_control_good.csv +0 -2
  85. data/features/support/imports/automobile_type_fuel_year_good.csv +0 -2
  86. data/features/support/imports/automobile_type_year_bad.csv +0 -2
  87. data/features/support/imports/automobile_type_year_good.csv +0 -2
  88. data/features/support/imports/bus_class_bad.csv +0 -2
  89. data/features/support/imports/bus_class_good.csv +0 -2
  90. data/features/support/imports/bus_fuel_bad.csv +0 -3
  91. data/features/support/imports/bus_fuel_good.csv +0 -3
  92. data/features/support/imports/carrier_bad.csv +0 -3
  93. data/features/support/imports/carrier_good.csv +0 -3
  94. data/features/support/imports/carrier_mode_bad.csv +0 -2
  95. data/features/support/imports/carrier_mode_good.csv +0 -2
  96. data/features/support/imports/computation_carrier_bad.csv +0 -3
  97. data/features/support/imports/computation_carrier_good.csv +0 -3
  98. data/features/support/imports/computation_carrier_instance_class_bad.csv +0 -2
  99. data/features/support/imports/computation_carrier_instance_class_good.csv +0 -2
  100. data/features/support/imports/egrid_region_bad.csv +0 -3
  101. data/features/support/imports/egrid_region_good.csv +0 -3
  102. data/features/support/imports/egrid_subregion_bad.csv +0 -2
  103. data/features/support/imports/egrid_subregion_good.csv +0 -2
  104. data/features/support/imports/fuel_year_bad.csv +0 -2
  105. data/features/support/imports/fuel_year_good.csv +0 -2
  106. data/features/support/imports/greenhouse_gas_bad.csv +0 -2
  107. data/features/support/imports/greenhouse_gas_good.csv +0 -2
  108. data/features/support/imports/rail_class_bad.csv +0 -3
  109. data/features/support/imports/rail_class_good.csv +0 -3
  110. data/features/support/imports/shipment_mode_bad.csv +0 -3
  111. data/features/support/imports/shipment_mode_good.csv +0 -3
  112. data/lib/earth/air/aircraft_instance.rb +0 -11
  113. data/lib/earth/air/aircraft_instance_seat_class.rb +0 -13
  114. data/lib/earth/hospitality/lodging_property.rb +0 -33
  115. data/vendor/clean_find_in_batches/init.rb +0 -35
@@ -1,3 +1,5 @@
1
+ require 'fuzzy_match/cached_result'
2
+
1
3
  class Aircraft < ActiveRecord::Base
2
4
  self.primary_key = "icao_code"
3
5
 
@@ -61,7 +63,7 @@ class Aircraft < ActiveRecord::Base
61
63
  # Cache fuzzy matches between FlightSegment aircraft_description and Aircraft description
62
64
  def manually_cache_flight_segments!
63
65
  FlightSegment.run_data_miner!
64
- FuzzyMatch::CachedResult.setup
66
+ FuzzyMatch::CachedResult.auto_upgrade!
65
67
  connection.select_values("SELECT DISTINCT(aircraft_description) FROM flight_segments WHERE aircraft_description IS NOT NULL").each do |original_description|
66
68
  # If the flight segment's aircraft_description contains '/' then it describes multiple aircraft.
67
69
  # We need to synthesize descriptions for those aircraft, find all Aircraft that fuzzily match the
@@ -32,8 +32,8 @@ Aircraft.class_eval do
32
32
  :encoding => 'windows-1252',
33
33
  :row_xpath => '//table[2]//table[1]//tr[3]//tr',
34
34
  :column_xpath => 'td',
35
- :errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGVBRnhkRGhSaVptSDJ5bXJGbkpUSWc&output=csv', :responder => Aircraft::Guru.new },
36
- :select => lambda { |record| manufacturer_whitelist? record['Manufacturer'] }) do
35
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/aircraft/faa_errata.csv", :responder => Aircraft::Guru.new },
36
+ :select => proc { |record| Aircraft.manufacturer_whitelist? record['Manufacturer'] }) do
37
37
  key 'icao_code', :field_name => 'Designator'
38
38
  store 'manufacturer_name', :field_name => 'Manufacturer'
39
39
  store 'model_name', :field_name => 'Model'
@@ -1,4 +1,4 @@
1
- require ::File.join(Earth.vendor_dir, 'geokit-rails', 'lib', 'geokit-rails')
1
+ require ::File.join(Earth::VENDOR_DIR, 'geokit-rails', 'lib', 'geokit-rails')
2
2
  require 'earth/locality'
3
3
 
4
4
  class Airport < ActiveRecord::Base
@@ -16,21 +16,29 @@ Airport.class_eval do
16
16
  end
17
17
  end
18
18
 
19
+ def self.countries_dictionary
20
+ @countries_dictionary ||= ::FuzzyMatch.new Country.all, :read => :name
21
+ end
22
+
19
23
  data_miner do
20
24
  process "Start from scratch" do
21
25
  delete_all
22
26
  end
23
27
 
28
+ process "Ensure Country is populated" do
29
+ Country.run_data_miner!
30
+ end
31
+
24
32
  import "the OpenFlights.org airports database",
25
33
  :url => 'https://openflights.svn.sourceforge.net/svnroot/openflights/openflights/data/airports.dat',
26
34
  :headers => %w{ id name city country_name iata_code icao_code latitude longitude altitude timezone daylight_savings },
27
- :select => lambda { |record| record['iata_code'].present? },
28
- :errata => { :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFc2UzhQYU5PWEQ0N21yWFZGNmc2a3c&gid=0&output=csv',
35
+ :select => proc { |record| record['iata_code'].present? },
36
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/airport/openflights_errata.csv",
29
37
  :responder => Airport::Guru.new } do
30
38
  key 'iata_code'
31
39
  store 'name'
32
40
  store 'city'
33
- store 'country_name'
41
+ store 'country_name', :synthesize => proc { |row| Airport.countries_dictionary.find(row['country_name'], :must_match_at_least_one_word => true).try(:name) }
34
42
  store 'latitude'
35
43
  store 'longitude'
36
44
  end
@@ -45,39 +53,11 @@ Airport.class_eval do
45
53
  store 'longitude'
46
54
  end
47
55
 
48
- process "Ensure Country is populated" do
49
- Country.run_data_miner!
50
- end
51
-
52
56
  process "Fill in blank country codes" do
53
57
  Country.find_each do |country|
54
58
  next unless country.name.present? and country.iso_3166_code.present?
55
- where(["country_name LIKE ?", country.name]).update_all :country_iso_3166_code => country.iso_3166_code
59
+ where(:country_name => country.name).update_all :country_iso_3166_code => country.iso_3166_code
56
60
  end
57
61
  end
58
-
59
- # 10/14/2011 cutting this b/c we don't use it - Ian
60
- # sabshere 5/24/10 using temporary tables because the WHERE clause has a very slow OR condition: iata_code = destination_iata_code OR iata_code = origin_iata_code
61
- # process "Derive some average flight characteristics from flight segments" do
62
- # FlightSegment.run_data_miner!
63
- # segments = FlightSegment.arel_table
64
- # airports = Airport.arel_table
65
- #
66
- # find_in_batches do |batch|
67
- # batch.each do |airport|
68
- # targeting_relation = airports[:iata_code].eq airport.iata_code
69
- # conditional_relation = segments[:origin_airport_iata_code].eq(airport.iata_code).or(segments[:destination_airport_iata_code].eq(airport.iata_code))
70
- # connection.execute "CREATE TEMPORARY TABLE tmp1 #{FlightSegment.where(conditional_relation).to_sql}"
71
- # update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
72
- # update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
73
- # update_all "load_factor = (#{FlightSegment.weighted_average_relation(:load_factor, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
74
- # update_all "freight_share = (#{FlightSegment.weighted_average_relation(:freight_share, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
75
- # update_all "payload = (#{FlightSegment.weighted_average_relation(:payload, :weighted_by => :passengers, :disaggregate_by => :departures_performed).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
76
- # connection.execute 'DROP TABLE tmp1'
77
- # end
78
- # end
79
- # end
80
-
81
- # FIXME TODO verify this
82
62
  end
83
63
  end
@@ -2,7 +2,7 @@ BtsAircraft.class_eval do
2
2
  data_miner do
3
3
  import "the BTS aircraft type lookup table",
4
4
  :url => "http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE",
5
- :errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEZ2d3JQMzV5T1o1T3JmVlFyNUZxdEE&output=csv' } do
5
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/bts_aircraft/bts_errata.csv" } do
6
6
  key 'bts_code', :field_name => 'Code'
7
7
  store 'description', :field_name => 'Description'
8
8
  end
@@ -4,11 +4,11 @@ FlightSegment.class_eval do
4
4
  # For import errata
5
5
  class FlightSegment::Guru
6
6
  def in_may_2009?(row)
7
- row ['MONTH'] == 5 and row['YEAR'] == 2009
7
+ row ['MONTH'].to_i == 5 and row['YEAR'].to_i == 2009
8
8
  end
9
9
 
10
10
  def in_july_2009?(row)
11
- row ['MONTH'] == 7 and row['YEAR'] == 2009
11
+ row ['MONTH'].to_i == 7 and row['YEAR'].to_i == 2009
12
12
  end
13
13
  end
14
14
 
@@ -186,16 +186,15 @@ FlightSegment.class_eval do
186
186
  process "Start from scratch" do
187
187
  delete_all
188
188
  end
189
-
190
- form_data_per_month(2009..::Time.now.year).each do |month, form_data|
189
+ FlightSegment.form_data_per_month(2011..2011).each do |month, form_data|
190
+ # FlightSegment.form_data_per_month(2009..::Time.now.year).each do |month, form_data|
191
191
  import "T100 flight segment data for #{month.strftime('%B %Y')}",
192
192
  :url => URL,
193
193
  :form_data => form_data,
194
194
  :compression => :zip,
195
195
  :glob => '/*.csv',
196
- # FIXME TODO 6/6/2011 the errata doesn't work - still doesn't fill in missing airline in May and July 2009
197
- :errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGxpYU1qWFR3d0syTVMyQVVOaDd0V3c&output=csv', :responder => FlightSegment::Guru.new },
198
- :select => lambda { |record| record['DEPARTURES_PERFORMED'].to_i > 0 } do
196
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/flight_segment/bts_errata.csv", :responder => FlightSegment::Guru.new },
197
+ :select => proc { |record| record['DEPARTURES_PERFORMED'].to_i > 0 } do
199
198
  key 'row_hash'
200
199
  store 'origin_airport_iata_code', :field_name => 'ORIGIN'
201
200
  store 'origin_country_iso_3166_code', :field_name => 'ORIGIN_COUNTRY'
@@ -36,7 +36,7 @@ AutomobileMakeModelYear.class_eval do
36
36
  # 2009 Dodge Durango HEV
37
37
  import "A list of hybrid make model years derived from the EPA fuel economy guide",
38
38
  :url => 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AoQJbWqPrREqdGtzekE4cGNoRGVmdmZMaTNvOWluSnc&output=csv' do
39
- key 'name', :synthesize => lambda { |record| [record['make_name'], record['model_name'], record['year']].join(' ') }
39
+ key 'name', :synthesize => proc { |record| [record['make_name'], record['model_name'], record['year']].join(' ') }
40
40
  store 'hybridity'
41
41
  end
42
42
 
@@ -66,8 +66,8 @@ AutomobileMakeModelYearVariant.class_eval do
66
66
  '(GM-PONT)' => nil,
67
67
  }
68
68
 
69
- class AutomobileMakeModelYearVariant::ParserB
70
- ::FixedWidth.define :fuel_economy_guide_b do |d|
69
+ class AutomobileMakeModelYearVariant::ParserA
70
+ ::FixedWidth.define :fuel_economy_guide_a do |d|
71
71
  d.rows do |row|
72
72
  row.trap { true } # there's only one section
73
73
  row.column 'active_year' , 4, :type => :integer # ACTIVE YEAR
@@ -149,8 +149,8 @@ AutomobileMakeModelYearVariant.class_eval do
149
149
  engine_types.flatten.include?('turbo')
150
150
  end
151
151
  end
152
-
153
- class AutomobileMakeModelYearVariant::ParserC
152
+
153
+ class AutomobileMakeModelYearVariant::ParserB
154
154
  attr_reader :year
155
155
  def initialize(options = {})
156
156
  options = options.stringify_keys
@@ -171,8 +171,8 @@ AutomobileMakeModelYearVariant.class_eval do
171
171
  row
172
172
  end
173
173
  end
174
-
175
- class AutomobileMakeModelYearVariant::ParserD
174
+
175
+ class AutomobileMakeModelYearVariant::ParserC
176
176
  attr_reader :year
177
177
  def initialize(options = {})
178
178
  options = options.stringify_keys
@@ -194,7 +194,7 @@ AutomobileMakeModelYearVariant.class_eval do
194
194
  end
195
195
  end
196
196
 
197
- class AutomobileMakeModelYearVariant::ParserE
197
+ class AutomobileMakeModelYearVariant::ParserD
198
198
  OLD_FUEL_CODES = {
199
199
  'CNG' => 'C',
200
200
  'DU' => 'D',
@@ -231,19 +231,16 @@ AutomobileMakeModelYearVariant.class_eval do
231
231
  # 1985---1997
232
232
  # FIXME TODO 14 records in the 1995 FEG are missing fuel efficiencies
233
233
  (85..97).each do |yy|
234
- # [85, 95, 96].each do |yy|
235
234
  filename = (yy == 96) ? "#{yy}MFGUI.ASC" : "#{yy}MFGUI.DAT"
236
235
  import "19#{ yy } Fuel Economy Guide",
237
236
  :url => "http://www.fueleconomy.gov/FEG/epadata/#{yy}mfgui.zip",
238
- # :url => "file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/#{filename}",
239
237
  :format => :fixed_width,
240
238
  :cut => ((yy == 95) ? '13-' : nil),
241
- :schema_name => :fuel_economy_guide_b,
242
- :select => lambda { |row| row['model'].present? and (row['suppress_code'].blank? or row['suppress_code'].to_f == 0) and row['state_code'] == 'F' },
239
+ :schema_name => :fuel_economy_guide_a,
240
+ :select => proc { |row| row['model'].present? and (row['suppress_code'].blank? or row['suppress_code'].to_f == 0) and row['state_code'] == 'F' },
243
241
  :filename => filename,
244
- :transform => { :class => AutomobileMakeModelYearVariant::ParserB, :year => "19#{yy}".to_i },
245
- :errata => { :url => "https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDkxTElWRVlvUXB3Uy04SDhSYWkzakE&output=csv", :responder => AutomobileMakeModelYearVariant::Guru.new } do
246
- # :errata => { :url => "file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/errata_new.csv", :responder => AutomobileMakeModelYearVariant::Guru.new } do
242
+ :transform => { :class => AutomobileMakeModelYearVariant::ParserA, :year => "19#{yy}".to_i },
243
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_model_year_variant/feg_errata.csv", :responder => AutomobileMakeModelYearVariant::Guru.new } do
247
244
  key 'row_hash'
248
245
  store 'make_name', :field_name => 'make'
249
246
  store 'model_name', :field_name => 'model'
@@ -278,20 +275,11 @@ AutomobileMakeModelYearVariant.class_eval do
278
275
  2003 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/03data.zip', :filename => 'guide_2003_feb04-03b.csv' },
279
276
  2004 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/04data.zip', :filename => 'gd04-Feb1804-RelDtFeb20.csv' },
280
277
  2005 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/05data.zip', :filename => 'guide2005-2004oct15.csv' }
281
- # 1998 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/98guide6.csv' },
282
- # 1999 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/99guide6.csv' },
283
- # 2000 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/G6080900.csv' },
284
- # 2001 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/01guide0918.csv' },
285
- # 2002 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/guide_jan28.csv' },
286
- # 2003 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/guide_2003_feb04-03b.csv' },
287
- # 2004 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/gd04-Feb1804-RelDtFeb20.csv' },
288
- # 2005 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/guide2005-2004oct15.csv' }
289
278
  }.each do |year, options|
290
279
  import "#{ year } Fuel Economy Guide",
291
- options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserC, :year => year },
292
- :errata => { :url => "https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDkxTElWRVlvUXB3Uy04SDhSYWkzakE&output=csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
293
- # :errata => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/errata_new.csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
294
- :select => lambda { |row| row['model'].present? }) do
280
+ options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserB, :year => year },
281
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_model_year_variant/feg_errata.csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
282
+ :select => proc { |row| row['model'].present? }) do
295
283
  key 'row_hash'
296
284
  store 'make_name', :field_name => 'make'
297
285
  store 'model_name', :field_name => 'model'
@@ -315,20 +303,14 @@ AutomobileMakeModelYearVariant.class_eval do
315
303
  # 2006--2009
316
304
  {
317
305
  2006 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/06data.zip', :filename => '2006_FE_Guide_14-Nov-2005_download.csv' },
318
- # the 07data.xls file provided by the government has a bad encoding
319
- 2007 => { :url => 'http://static.brighterplanet.com/science/data/transport/automobiles/fuel_economy_guide/2007_FE_guide_ALL_no_sales_May_01_2007.csv' },
306
+ 2007 => { :url => 'http://static.brighterplanet.com/science/data/transport/automobiles/fuel_economy_guide/2007_FE_guide_ALL_no_sales_May_01_2007.csv' }, # the 07data.xls file provided by the government has a bad encoding
320
307
  2008 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/08data.zip', :filename => '2008_FE_guide_ALL_rel_dates_-no sales-for DOE-5-1-08.csv' },
321
308
  2009 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/09data.zip', :filename => '2009_FE_guide for DOE_ALL-rel dates-no-sales-8-28-08download.csv' }
322
- # 2006 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2006_FE_Guide_14-Nov-2005_download.csv' },
323
- # 2007 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2007_FE_guide_ALL_no_sales_May_01_2007.csv' },
324
- # 2008 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2008_FE_guide.csv' },
325
- # 2009 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2009_FE_guide.csv' }
326
309
  }.each do |year, options|
327
310
  import "#{ year } Fuel Economy Guide",
328
- options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserD, :year => year },
329
- :errata => { :url => "https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDkxTElWRVlvUXB3Uy04SDhSYWkzakE&output=csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
330
- # :errata => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/errata_new.csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
331
- :select => lambda { |row| row['model'].present? }) do
311
+ options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserC, :year => year },
312
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_model_year_variant/feg_errata.csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
313
+ :select => proc { |row| row['model'].present? }) do
332
314
  key 'row_hash'
333
315
  store 'make_name', :field_name => 'make'
334
316
  store 'model_name', :field_name => 'model'
@@ -357,14 +339,11 @@ AutomobileMakeModelYearVariant.class_eval do
357
339
  # Note: it's ok for electric vehicles to be missing cylinders and displacement
358
340
  2010 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/10data.zip', :filename => '2010FEGuide for DOE-all rel dates-no-sales-02-22-2011public.xlsx' },
359
341
  2011 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/11data.zip', :filename => '2011FEGuide-for DOE rel-dates before 1-23-2011-no-sales-01-10-2011_All_public.xlsx' }
360
- # 2010 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2010FEGuide.xlsx' },
361
- # 2011 => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/2011FEGuide.xlsx' }
362
342
  }.each do |year, options|
363
343
  import "#{ year } Fuel Economy Guide",
364
- options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserE, :year => year },
365
- :errata => { :url => "https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDkxTElWRVlvUXB3Uy04SDhSYWkzakE&output=csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
366
- # :errata => { :url => 'file:///Users/ian/Documents/brighter_planet/documents1/science/data/transport/automobiles/fuel_economy_guide/errata_new.csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
367
- :select => lambda { |row| row['model'].present? }) do
344
+ options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserD, :year => year },
345
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_model_year_variant/feg_errata.csv", :responder => AutomobileMakeModelYearVariant::Guru.new },
346
+ :select => proc { |row| row['model'].present? }) do
368
347
  key 'row_hash'
369
348
  store 'make_name', :field_name => 'make'
370
349
  store 'model_name', :field_name => 'model'
@@ -2,10 +2,10 @@ require 'earth/fuel/data_miner'
2
2
  AutomobileMakeYearFleet.class_eval do
3
3
  data_miner do
4
4
  import "annual corporate average fuel economy data for domestic and imported vehicle fleets from the NHTSA",
5
- :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEdXWXB6dkVLWkowLXhYSFVUT01sS2c&hl=en&gid=0&output=csv',
6
- :errata => { 'url' => 'http://static.brighterplanet.com/science/data/transport/automobiles/make_fleet_years/errata.csv' },
7
- :select => lambda { |row| row['volume'].to_i > 0 } do
8
- key 'name', :synthesize => lambda { |row| [ row['manufacturer_name'], row['year_content'], row['fleet'][2,2] ].join ' ' }
5
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEdXWXB6dkVLWkowLXhYSFVUT01sS2c&output=csv',
6
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_year_fleet/cafe_errata.csv", :encoding => 'ISO-8859-1' },
7
+ :select => proc { |row| row['volume'].to_i > 0 } do
8
+ key 'name', :synthesize => proc { |row| [ row['manufacturer_name'], row['year_content'], row['fleet'][2,2] ].join ' ' }
9
9
  store 'make_name', :field_name => 'manufacturer_name'
10
10
  store 'year', :field_name => 'year_content'
11
11
  store 'fleet', :chars => 2..3 # zero-based
@@ -5,8 +5,8 @@ AutomobileTypeFuelYear.class_eval do
5
5
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
6
6
  :filename => 'Annex Tables/Annex 3/Table A-87.csv',
7
7
  :skip => 1,
8
- :select => lambda { |row| row['Year'].to_i.to_s == row['Year'] } do
9
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline #{row['Year']}" }
8
+ :select => proc { |row| row['Year'].to_i.to_s == row['Year'] } do
9
+ key 'name', :synthesize => proc { |row| "Passenger cars gasoline #{row['Year']}" }
10
10
  store 'type_name', :static => 'Passenger cars'
11
11
  store 'fuel_common_name', :static => 'gasoline'
12
12
  store 'year', :field_name => 'Year'
@@ -17,8 +17,8 @@ AutomobileTypeFuelYear.class_eval do
17
17
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
18
18
  :filename => 'Annex Tables/Annex 3/Table A-87.csv',
19
19
  :skip => 1,
20
- :select => lambda { |row| row['Year'].to_i.to_s == row['Year'] } do
21
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline #{row['Year']}" }
20
+ :select => proc { |row| row['Year'].to_i.to_s == row['Year'] } do
21
+ key 'name', :synthesize => proc { |row| "Light-duty trucks gasoline #{row['Year']}" }
22
22
  store 'type_name', :static => 'Light-duty trucks'
23
23
  store 'fuel_common_name', :static => 'gasoline'
24
24
  store 'year', :field_name => 'Year'
@@ -29,8 +29,8 @@ AutomobileTypeFuelYear.class_eval do
29
29
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
30
30
  :filename => 'Annex Tables/Annex 3/Table A-88.csv',
31
31
  :skip => 1,
32
- :select => lambda { |row| row['Year'].to_i.to_s == row['Year'] } do
33
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel #{row['Year']}" }
32
+ :select => proc { |row| row['Year'].to_i.to_s == row['Year'] } do
33
+ key 'name', :synthesize => proc { |row| "Passenger cars diesel #{row['Year']}" }
34
34
  store 'type_name', :static => 'Passenger cars'
35
35
  store 'fuel_common_name', :static => 'diesel'
36
36
  store 'year', :field_name => 'Year'
@@ -41,8 +41,8 @@ AutomobileTypeFuelYear.class_eval do
41
41
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
42
42
  :filename => 'Annex Tables/Annex 3/Table A-88.csv',
43
43
  :skip => 1,
44
- :select => lambda { |row| row['Year'].to_i.to_s == row['Year'] } do
45
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel #{row['Year']}" }
44
+ :select => proc { |row| row['Year'].to_i.to_s == row['Year'] } do
45
+ key 'name', :synthesize => proc { |row| "Light-duty trucks diesel #{row['Year']}" }
46
46
  store 'type_name', :static => 'Light-duty trucks'
47
47
  store 'fuel_common_name', :static => 'diesel'
48
48
  store 'year', :field_name => 'Year'
@@ -5,88 +5,88 @@ AutomobileTypeFuelYearAge.class_eval do
5
5
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
6
6
  :filename => 'Annex Tables/Annex 3/Table A-93.csv',
7
7
  :skip => 1,
8
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
9
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
8
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
9
+ key 'name', :synthesize => proc { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
10
10
  store 'type_name', :static => 'Passenger cars'
11
11
  store 'fuel_common_name', :static => 'gasoline'
12
12
  store 'year', :static => '2008'
13
13
  store 'age', :field_name => 'Vehicle Age'
14
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDGV'].to_f / 100 }
14
+ store 'total_travel_percent', :synthesize => proc { |row| row['LDGV'].to_f / 100 }
15
15
  end
16
16
 
17
17
  import "total travel distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
18
18
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
19
19
  :filename => 'Annex Tables/Annex 3/Table A-93.csv',
20
20
  :skip => 1,
21
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
22
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
21
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
22
+ key 'name', :synthesize => proc { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
23
23
  store 'type_name', :static => 'Light-duty trucks'
24
24
  store 'fuel_common_name', :static => 'gasoline'
25
25
  store 'year', :static => '2008'
26
26
  store 'age', :field_name => 'Vehicle Age'
27
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDGT'].to_f / 100 }
27
+ store 'total_travel_percent', :synthesize => proc { |row| row['LDGT'].to_f / 100 }
28
28
  end
29
29
 
30
30
  import "total travel distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
31
31
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
32
32
  :filename => 'Annex Tables/Annex 3/Table A-93.csv',
33
33
  :skip => 1,
34
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
35
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
34
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
35
+ key 'name', :synthesize => proc { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
36
36
  store 'type_name', :static => 'Passenger cars'
37
37
  store 'fuel_common_name', :static => 'diesel'
38
38
  store 'year', :static => '2008'
39
39
  store 'age', :field_name => 'Vehicle Age'
40
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDDV'].to_f / 100 }
40
+ store 'total_travel_percent', :synthesize => proc { |row| row['LDDV'].to_f / 100 }
41
41
  end
42
42
 
43
43
  import "total travel distribution of diesel light-duty trucks from the 2010 EPA GHG Inventory",
44
44
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
45
45
  :filename => 'Annex Tables/Annex 3/Table A-93.csv',
46
46
  :skip => 1,
47
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
48
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
47
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
48
+ key 'name', :synthesize => proc { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
49
49
  store 'type_name', :static => 'Light-duty trucks'
50
50
  store 'fuel_common_name', :static => 'diesel'
51
51
  store 'year', :static => '2008'
52
52
  store 'age', :field_name => 'Vehicle Age'
53
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDDT'].to_f / 100 }
53
+ store 'total_travel_percent', :synthesize => proc { |row| row['LDDT'].to_f / 100 }
54
54
  end
55
55
 
56
56
  import "average annual distance for gasoline passenger cars from the 2010 EPA GHG Inventory",
57
57
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
58
58
  :filename => 'Annex Tables/Annex 3/Table A-92.csv',
59
59
  :skip => 1,
60
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
61
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
62
- store 'annual_distance', :synthesize => lambda { |row| row['LDGV'].to_s.sub(',', '') }, :units => :miles
60
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
61
+ key 'name', :synthesize => proc { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
62
+ store 'annual_distance', :synthesize => proc { |row| row['LDGV'].to_s.sub(',', '') }, :units => :miles
63
63
  end
64
64
 
65
65
  import "average annual distance for gasoline light-duty trucks from the 2010 EPA GHG Inventory",
66
66
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
67
67
  :filename => 'Annex Tables/Annex 3/Table A-92.csv',
68
68
  :skip => 1,
69
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
70
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
71
- store 'annual_distance', :synthesize => lambda { |row| row['LDGT'].to_s.sub(',', '') }, :units => :miles
69
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
70
+ key 'name', :synthesize => proc { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
71
+ store 'annual_distance', :synthesize => proc { |row| row['LDGT'].to_s.sub(',', '') }, :units => :miles
72
72
  end
73
73
 
74
74
  import "average annual distance for diesel passenger cars from the 2010 EPA GHG Inventory",
75
75
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
76
76
  :filename => 'Annex Tables/Annex 3/Table A-92.csv',
77
77
  :skip => 1,
78
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
79
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
80
- store 'annual_distance', :synthesize => lambda { |row| row['LDDV'].to_s.sub(',', '') }, :units => :miles
78
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
79
+ key 'name', :synthesize => proc { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
80
+ store 'annual_distance', :synthesize => proc { |row| row['LDDV'].to_s.sub(',', '') }, :units => :miles
81
81
  end
82
82
 
83
83
  import "average annual distance for diesel light-duty trucks from the 2010 EPA GHG Inventory",
84
84
  :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
85
85
  :filename => 'Annex Tables/Annex 3/Table A-92.csv',
86
86
  :skip => 1,
87
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
88
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
89
- store 'annual_distance', :synthesize => lambda { |row| row['LDDT'].to_s.sub(',', '') }, :units => :miles
87
+ :select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
88
+ key 'name', :synthesize => proc { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
89
+ store 'annual_distance', :synthesize => proc { |row| row['LDDT'].to_s.sub(',', '') }, :units => :miles
90
90
  end
91
91
 
92
92
  process "Convert annual distance from miles to kilometres" do