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
@@ -14,7 +14,7 @@ Fuel.class_eval do
14
14
 
15
15
  import "liquid fuels with non-variable characteristics",
16
16
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGJmYkdtajZyV3Byb0lrd21xLVhXUGc&output=csv',
17
- :select => lambda {|row| row['energy_content_units'] == 'million_btu_per_barrel'} do
17
+ :select => proc {|row| row['energy_content_units'] == 'million_btu_per_barrel'} do
18
18
  key 'name'
19
19
  store 'physical_units', :static => 'litre'
20
20
  store 'energy_content', :from_units => :million_btu_per_barrel, :to_units => :megajoules_per_litre
@@ -25,7 +25,7 @@ Fuel.class_eval do
25
25
 
26
26
  import "gaseous fuels with non-variable characteristics",
27
27
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGJmYkdtajZyV3Byb0lrd21xLVhXUGc&output=csv',
28
- :select => lambda {|row| row['energy_content_units'] == 'btu_per_cubic_foot'} do
28
+ :select => proc {|row| row['energy_content_units'] == 'btu_per_cubic_foot'} do
29
29
  key 'name'
30
30
  store 'physical_units', :static => 'cubic_metre'
31
31
  store 'energy_content', :from_units => :btus_per_cubic_foot, :to_units => :megajoules_per_cubic_metre
@@ -6,7 +6,7 @@ FuelPrice.class_eval do
6
6
  data_miner do
7
7
  import 'fuel prices derived from the EIA',
8
8
  :url => 'http://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHlSdXJoOFB5aEpHenJQbTVJdS1pMVE&gid=0&output=csv',
9
- :select => lambda { |row| row['fuel_type_name'].present? } do
9
+ :select => proc { |row| row['fuel_type_name'].present? } do
10
10
  key 'name', :field_name => 'fuel_type_name'
11
11
  store 'price', :units_field_name => 'price_units'
12
12
  end
@@ -128,7 +128,7 @@ CbecsEnergyIntensity.class_eval do
128
128
  }
129
129
  })
130
130
 
131
- const_set(:NAICS_CODE_SYNTHESIZER, lambda { |row|
131
+ const_set(:NAICS_CODE_SYNTHESIZER, proc { |row|
132
132
  case row[0].to_s
133
133
  when /Education/
134
134
  61
@@ -8,9 +8,9 @@ Naics2002Naics2007Concordance.class_eval do
8
8
  :skip => 3,
9
9
  :headers => %w{ 2002_code 2002_title 2007_code 2007_title } do
10
10
  key 'row_hash'
11
- store 'naics_2002_code', :synthesize => lambda { |row| "%06d" % row['2002_code'].to_i }
12
- store 'naics_2007_code', :synthesize => lambda { |row| "%06d" % row['2007_code'].to_i }
13
- store 'naics_2002_note', :synthesize => lambda { |row| extract_note row['2002_title'] }
11
+ store 'naics_2002_code', :synthesize => proc { |row| "%06d" % row['2002_code'].to_i }
12
+ store 'naics_2007_code', :synthesize => proc { |row| "%06d" % row['2007_code'].to_i }
13
+ store 'naics_2002_note', :synthesize => proc { |row| Naics2002Naics2007Concordance.extract_note row['2002_title'] }
14
14
  end
15
15
  end
16
16
  end
@@ -5,11 +5,11 @@ Naics2002Sic1987Concordance.class_eval do
5
5
  data_miner do
6
6
  import "the US Census SIC 1987 to NAICS 2002 concordance",
7
7
  :url => 'http://www.census.gov/eos/www/naics/concordances/1987_SIC_to_2002_NAICS.xls',
8
- :select => lambda {|row| row['SIC'].to_i > 0} do
8
+ :select => proc {|row| row['SIC'].to_i > 0 } do
9
9
  key 'row_hash'
10
- store 'naics_2002_code', :synthesize => lambda { |row| "%06d" % row['2002 NAICS'].to_i }
11
- store 'sic_1987_code', :synthesize => lambda { |row| "%04d" % row['SIC'].to_i }
12
- store 'sic_note', :synthesize => lambda { |row| extract_note row['SIC Title (and note)'] }
10
+ store 'naics_2002_code', :synthesize => proc { |row| "%06d" % row['2002 NAICS'].to_i }
11
+ store 'sic_1987_code', :synthesize => proc { |row| "%04d" % row['SIC'].to_i }
12
+ store 'sic_note', :synthesize => proc { |row| Naics2002Sic1987Concordance.extract_note row['SIC Title (and note)'] }
13
13
  end
14
14
  end
15
15
  end
@@ -2,9 +2,9 @@ Sic1987.class_eval do
2
2
  data_miner do
3
3
  import "SIC 1987 codes derived from US Census SIC 1987 to NAICS 2002 concordance",
4
4
  :url => 'http://www.census.gov/eos/www/naics/concordances/1987_SIC_to_2002_NAICS.xls',
5
- :select => lambda {|row| row['SIC'].to_i > 0} do
6
- key 'code', :synthesize => lambda { |row| "%04d" % row['SIC'].to_i }
7
- store 'description', :synthesize => lambda { |row| format_description row['SIC Title (and note)'] }
5
+ :select => proc {|row| row['SIC'].to_i > 0} do
6
+ key 'code', :synthesize => proc { |row| "%04d" % row['SIC'].to_i }
7
+ store 'description', :synthesize => proc { |row| Sic1987.format_description row['SIC Title (and note)'] }
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ CensusRegion.class_eval do
4
4
  :url => 'http://www.census.gov/popest/about/geo/state_geocodes_v2009.txt',
5
5
  :skip => 6,
6
6
  :headers => %w{ Region Division FIPS Name },
7
- :select => ::Proc.new { |row| row['Region'].to_i > 0 and row['Division'].to_i == 0 }) do
7
+ :select => proc { |row| row['Region'].to_i > 0 and row['Division'].to_i == 0 }) do
8
8
  key 'number', :field_name => 'Region'
9
9
  store 'name', :field_name => 'Name'
10
10
  end
@@ -21,7 +21,7 @@ Country.class_eval do
21
21
  import "heating and cooling degree day data from WRI CAIT",
22
22
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDN4MkRTSWtWRjdfazhRdWllTkVSMkE&output=csv',
23
23
  :select => Proc.new { |record| record['country'] != 'European Union (27)' },
24
- :errata => { :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDNSMUtCV0h4cUF4UnBKZlNkczlNbFE&output=csv' } do
24
+ :errata => { :url => "file://#{Earth::ERRATA_DIR}/country/wri_errata.csv" } do
25
25
  key 'name', :field_name => 'country'
26
26
  store 'heating_degree_days', :units => :degrees_celsius
27
27
  store 'cooling_degree_days', :units => :degrees_celsius
@@ -91,7 +91,7 @@ Country.class_eval do
91
91
  import "calculate national electricity emission factors from Brander et al. (2011)",
92
92
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDZmWHFjLVdBZGRBdGxVdDdqd1YtYWc&output=csv' do
93
93
  key 'iso_3166_code', :field_name => 'country_iso_3166_code'
94
- store 'electricity_emission_factor', :synthesize => lambda { |row|
94
+ store 'electricity_emission_factor', :synthesize => proc { |row|
95
95
  (
96
96
  row['electricity_co2_emission_factor'].to_f +
97
97
  (row['electricity_ch4_emission_factor'].to_f * GreenhouseGas[:ch4].global_warming_potential) +
@@ -4,7 +4,7 @@ EgridRegion.class_eval do
4
4
  :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2010V1_1_STIE_USGC.xls',
5
5
  :sheet => 'STIE07',
6
6
  :skip => 4,
7
- :select => lambda { |row| row['eGRID2010 year 2007 file state sequence number'].to_i.between?(1, 51) } do
7
+ :select => proc { |row| row['eGRID2010 year 2007 file state sequence number'].to_i.between?(1, 51) } do
8
8
  key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
9
9
  store 'country_name', :static => 'US'
10
10
  store 'loss_factor', :field_name => 'Year 2007 grid gross loss factor'
@@ -6,7 +6,7 @@ EgridSubregion.class_eval do
6
6
  :filename => 'eGRID2010V1_1_year07_AGGREGATION.xls',
7
7
  :sheet => 'SRL07',
8
8
  :skip => 4,
9
- :select => lambda { |row| row['SEQSRL07'].to_i.between?(1, 26) } do
9
+ :select => proc { |row| row['SEQSRL07'].to_i.between?(1, 26) } do
10
10
  key 'abbreviation', :field_name => 'SUBRGN'
11
11
  store 'name', :field_name => 'SRNAME'
12
12
  store 'nerc_abbreviation', :field_name => 'NERC'
@@ -4,7 +4,7 @@ State.class_eval do
4
4
  import 'the U.S. Census State ANSI Code file',
5
5
  :url => 'http://www.census.gov/geo/www/ansi/state.txt',
6
6
  :delimiter => '|',
7
- :select => lambda { |record| record['STATE'].to_i < 60 } do
7
+ :select => proc { |record| record['STATE'].to_i < 60 } do
8
8
  key 'postal_abbreviation', :field_name => 'STUSAB'
9
9
  store 'fips_code', :field_name => 'STATE'
10
10
  store 'name', :field_name => 'STATE_NAME'
@@ -15,7 +15,7 @@ State.class_eval do
15
15
  :url => 'http://www.census.gov/popest/about/geo/state_geocodes_v2009.txt',
16
16
  :skip => 8,
17
17
  :headers => ['Region', 'Division', 'State FIPS', 'Name'],
18
- :select => ::Proc.new { |row| row['State FIPS'].to_i > 0 } do
18
+ :select => proc { |row| row['State FIPS'].to_i > 0 } do
19
19
  key 'fips_code', :field_name => 'State FIPS'
20
20
  store 'census_division_number', :field_name => 'Division'
21
21
  end
@@ -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
 
3
3
  class ZipCode < ActiveRecord::Base
4
4
  self.primary_key = "name"
@@ -3,7 +3,7 @@ Breed.class_eval do
3
3
  import "Brighter Planet's list of cat and dog breeds",
4
4
  :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
5
5
  :encoding => 'ISO-8859-1',
6
- :select => lambda { |row| row['gender'].blank? } do
6
+ :select => proc { |row| row['gender'].blank? } do
7
7
  key 'name'
8
8
  store 'species_name', :field_name => 'species'
9
9
  store 'weight', :from_units => :pounds, :to_units => :kilograms
@@ -3,8 +3,8 @@ BreedGender.class_eval do
3
3
  import "Brighter Planet's list of cat and dog breeds, genders, and weights",
4
4
  :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
5
5
  :encoding => 'ISO-8859-1',
6
- :select => lambda { |row| row['gender'].present? } do
7
- key 'name', :synthesize => lambda { |row| row['name'] + ' ' + row['gender'] }
6
+ :select => proc { |row| row['gender'].present? } do
7
+ key 'name', :synthesize => proc { |row| row['name'] + ' ' + row['gender'] }
8
8
  store 'breed_name', :field_name => 'name'
9
9
  store 'gender_name', :field_name => 'gender'
10
10
  store 'weight', :from_units => :pounds, :to_units => :kilograms
@@ -2,7 +2,7 @@ Gender.class_eval do
2
2
  data_miner do
3
3
  import "a list of genders derived from pet breed genders",
4
4
  :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
5
- :select => lambda { |row| row['gender'].present? } do
5
+ :select => proc { |row| row['gender'].present? } do
6
6
  key 'name', :field_name => 'gender'
7
7
  end
8
8
  end
@@ -3,7 +3,7 @@ CountryRailClass.class_eval do
3
3
  data_miner do
4
4
  import "a list of country-specific rail classes and their pre-calculated characteristics",
5
5
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdFg3YVptS2FYdHBsb2kyZFRxSm5FdlE&output=csv' do
6
- key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_class_name']].join(' ') }
6
+ key 'name', :synthesize => proc { |record| [record['country_iso_3166_code'], record['rail_class_name']].join(' ') }
7
7
  store 'country_iso_3166_code'
8
8
  store 'rail_class_name'
9
9
  store 'passengers'
@@ -4,7 +4,7 @@ CountryRailTraction.class_eval do
4
4
  data_miner do
5
5
  import "european rail traction data from the UIC",
6
6
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHA1RmZ0SlN6ZkVOenRodGFBQ1N0Q2c&output=csv' do
7
- key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_traction_name']].join(' ') }
7
+ key 'name', :synthesize => proc { |record| [record['country_iso_3166_code'], record['rail_traction_name']].join(' ') }
8
8
  store 'country_iso_3166_code'
9
9
  store 'rail_traction_name'
10
10
  store 'electricity_intensity', :nullify => :true, :units_field_name => 'electricity_intensity_units'
@@ -4,7 +4,7 @@ CountryRailTractionClass.class_eval do
4
4
  data_miner do
5
5
  import "european rail traction class data from the UIC",
6
6
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBiV0VPdkg2UkNSV0pVdWNNcG9fMHc&output=csv' do
7
- key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_traction_name'], record['rail_class_name']].join(' ') }
7
+ key 'name', :synthesize => proc { |record| [record['country_iso_3166_code'], record['rail_traction_name'], record['rail_class_name']].join(' ') }
8
8
  store 'country_iso_3166_code'
9
9
  store 'rail_traction_name'
10
10
  store 'rail_class_name'
@@ -3,7 +3,7 @@ NationalTransitDatabaseRecord.class_eval do
3
3
  data_miner do
4
4
  import "US National Transit Database service data",
5
5
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdF9Hbktvc3BMNDRWZHhDRU9uMVZfWVE&output=csv' do
6
- key 'name', :synthesize => lambda { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
6
+ key 'name', :synthesize => proc { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
7
7
  store 'company_id', :field_name => 'trs_id'
8
8
  store 'mode_code'
9
9
  store 'service_type', :field_name => 'service_code', :dictionary => { :input => 'code', :output => 'name', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBTZENxb3A1SzJaNTVEVGZ5cTdaMVE&output=csv' }
@@ -15,11 +15,11 @@ NationalTransitDatabaseRecord.class_eval do
15
15
 
16
16
  import "US National Transit Database fuel consumption data",
17
17
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDItVVR5NjA2Y3FCVjgza25Ccy0zS2c&output=csv' do
18
- key 'name', :synthesize => lambda { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
18
+ key 'name', :synthesize => proc { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
19
19
  store 'company_id', :field_name => 'trs_id'
20
20
  store 'mode_code'
21
21
  store 'service_type', :field_name => 'service_code', :dictionary => { :input => 'code', :output => 'name', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBTZENxb3A1SzJaNTVEVGZ5cTdaMVE&output=csv' }
22
- store 'electricity', :synthesize => lambda { |row| row['electricity_kwh'].to_f + row['battery_kwh'].to_f }, :units => 'kilowatt_hours'
22
+ store 'electricity', :synthesize => proc { |row| row['electricity_kwh'].to_f + row['battery_kwh'].to_f }, :units => 'kilowatt_hours'
23
23
  store 'diesel', :field_name => 'diesel_gallons', :from_units => :gallons, :to_units => :litres
24
24
  store 'gasoline', :field_name => 'gasoline_gallons', :from_units => :gallons, :to_units => :litres
25
25
  store 'lpg', :field_name => 'lpg_gallons', :from_units => :gallons, :to_units => :litres
@@ -113,7 +113,7 @@ ResidenceFuelPrice.class_eval do
113
113
  # electricity in dollars per kWh
114
114
  import 'residential electricity prices from the EIA',
115
115
  :url => 'http://www.eia.doe.gov/cneaf/electricity/page/sales_revenue.xls',
116
- :select => lambda { |row| row['Year'].to_s.first(4).to_i > 1989 } do
116
+ :select => proc { |row| row['Year'].to_s.first(4).to_i > 1989 } do
117
117
  key 'row_hash'
118
118
  store 'residence_fuel_type_name', :static => 'electricity'
119
119
  store 'locatable_id', :field_name => 'State' # postal abbrev
@@ -127,10 +127,10 @@ ResidenceFuelPrice.class_eval do
127
127
  # natural gas in dollars per cubic metre
128
128
  # breaks if date-performance is enabled because DateTime.parse(...1899...) dies
129
129
  import 'residential natural gas prices from the EIA',
130
- :url => 'http://tonto.eia.doe.gov/dnav/ng/xls/ng_pri_sum_a_EPG0_FWA_DMcf_a.xls',
130
+ :url => 'http://www.eia.gov/dnav/ng/xls/ng_pri_sum_a_EPG0_FWA_DMcf_a.xls',
131
131
  :sheet => 'Data 1',
132
132
  :skip => 2,
133
- :select => lambda { |row| row['year'].to_i > 1989 },
133
+ :select => proc { |row| row['year'].to_i > 1989 },
134
134
  :transform => { :class => NaturalGasParser } do
135
135
  key 'row_hash'
136
136
  store 'residence_fuel_type_name', :static => 'natural gas'
@@ -150,7 +150,7 @@ ResidenceFuelPrice.class_eval do
150
150
  # :url => 'http://tonto.eia.doe.gov/dnav/pet/xls/PET_PRI_RESID_A_EPPR_PTA_CPGAL_M.xls',
151
151
  # :sheet => 'Data 1',
152
152
  # :skip => 2,
153
- # :select => lambda { |row| row['year'].to_i > 1989 },
153
+ # :select => proc { |row| row['year'].to_i > 1989 },
154
154
  # :transform => { :class => FuelOilParser } do
155
155
  # key 'row_hash'
156
156
  # store 'residence_fuel_type_name', :static => 'fuel oil'
@@ -169,7 +169,7 @@ ResidenceFuelPrice.class_eval do
169
169
  # :url => 'http://tonto.eia.doe.gov/dnav/pet/xls/PET_PRI_PROP_A_EPLLPA_PRT_CPGAL_M.xls',
170
170
  # :sheet => 'Data 1',
171
171
  # :skip => 2,
172
- # :select => lambda { |row| row['year'].to_i > 1989 },
172
+ # :select => proc { |row| row['year'].to_i > 1989 },
173
173
  # :transform => { :class => PropaneParser } do
174
174
  # key 'row_hash'
175
175
  # store 'residence_fuel_type_name', :static => 'propane'
@@ -63,16 +63,16 @@ ResidentialEnergyConsumptionSurveyResponse.class_eval do
63
63
  store 'outdoor_all_night_lights', :field_name => 'NOUTLGTNT'
64
64
  store 'outdoor_all_night_gas_lights', :field_name => 'NGASLIGHT'
65
65
  # integers where we treat anything other than true (for example legitimate skip or "occupied without paying rent") as 0
66
- store 'heated_garage', :synthesize => lambda { |row| row['GARGHEAT'] == '1' ? 1 : 0 }
67
- store 'attached_1car_garage', :synthesize => lambda { |row| row['GARAGE1C'] == '1' ? 1 : 0 }
68
- store 'detached_1car_garage', :synthesize => lambda { |row| row['DGARG1C'] == '1' ? 1 : 0 }
69
- store 'attached_2car_garage', :synthesize => lambda { |row| row['GARAGE2C'] == '1' ? 1 : 0 }
70
- store 'detached_2car_garage', :synthesize => lambda { |row| row['DGARG2C'] == '1' ? 1 : 0 }
71
- store 'attached_3car_garage', :synthesize => lambda { |row| row['GARAGE3C'] == '1' ? 1 : 0 }
72
- store 'detached_3car_garage', :synthesize => lambda { |row| row['DGARG3C'] == '1' ? 1 : 0 }
66
+ store 'heated_garage', :synthesize => proc { |row| row['GARGHEAT'] == '1' ? 1 : 0 }
67
+ store 'attached_1car_garage', :synthesize => proc { |row| row['GARAGE1C'] == '1' ? 1 : 0 }
68
+ store 'detached_1car_garage', :synthesize => proc { |row| row['DGARG1C'] == '1' ? 1 : 0 }
69
+ store 'attached_2car_garage', :synthesize => proc { |row| row['GARAGE2C'] == '1' ? 1 : 0 }
70
+ store 'detached_2car_garage', :synthesize => proc { |row| row['DGARG2C'] == '1' ? 1 : 0 }
71
+ store 'attached_3car_garage', :synthesize => proc { |row| row['GARAGE3C'] == '1' ? 1 : 0 }
72
+ store 'detached_3car_garage', :synthesize => proc { |row| row['DGARG3C'] == '1' ? 1 : 0 }
73
73
  # booleans where we treat anything other than true (for example legitimate skip or "occupied without paying rent") as false
74
- store 'ownership', :synthesize => lambda { |row| row['KOWNRENT'] == '1' }
75
- store 'thermostat_programmability', :synthesize => lambda { |row| row['PROTHERM'] == '1' }
74
+ store 'ownership', :synthesize => proc { |row| row['KOWNRENT'] == '1' }
75
+ store 'thermostat_programmability', :synthesize => proc { |row| row['PROTHERM'] == '1' }
76
76
  end
77
77
 
78
78
  # Rather than nullify the continuous variables that EIA identifies as LEGITIMATE SKIPS, we convert them to zero
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.11.16"
2
+ VERSION = "0.11.17"
3
3
  end
@@ -1,17 +1,23 @@
1
1
  require 'spec_helper'
2
2
  require 'earth/air/aircraft'
3
- require 'earth/air/aircraft/data_miner'
4
3
 
5
4
  describe Aircraft do
5
+ before :all do
6
+ Aircraft.auto_upgrade!
7
+ end
8
+
6
9
  describe 'import', :data_miner => true do
7
- it 'should treat empty cells as null' do
8
- Aircraft.auto_upgrade!
10
+ before do
11
+ require 'earth/air/aircraft/data_miner'
12
+ end
13
+
14
+ it 'should import data' do
9
15
  Aircraft.run_data_miner!
10
- Aircraft.count.should > 1
11
- Aircraft.where(:brighter_planet_aircraft_class_code => nil).should_not be_empty
16
+ Aircraft.all.count.should == 437
12
17
  end
13
18
  end
14
19
 
20
+ # FIXME TODO
15
21
  # describe 'fuzzy matching' do
16
22
  # it 'should match some example aircraft properly' do
17
23
  # user_input = "Boeing 727-100RE"
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'earth/air/airport'
3
+
4
+ describe Airport do
5
+ before :all do
6
+ Airport.auto_upgrade!
7
+ end
8
+
9
+ describe "when importing data", :data_miner => true do
10
+ before do
11
+ require 'earth/air/airport/data_miner'
12
+ end
13
+
14
+ it "imports all airports" do
15
+ Airport.run_data_miner!
16
+ Airport.count.should == 5324
17
+ end
18
+ end
19
+
20
+ describe "verify imported data", :sanity => true do
21
+ it "should have name" do
22
+ Airport.where(:name => nil).count.should == 0
23
+ end
24
+
25
+ it "should have city" do
26
+ Airport.where(:city => nil).count.should == 0
27
+ end
28
+
29
+ it "should have country code" do
30
+ Airport.where(:country_iso_3166_code => nil).count.should == 0
31
+ end
32
+
33
+ it "should have lat/lng" do
34
+ Airport.where(:latitude => nil).count.should == 0
35
+ Airport.where(:longitude => nil).count.should == 0
36
+ end
37
+
38
+ # FIXME TODO check for duplicate cities in same country
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'earth/air/bts_aircraft'
3
+
4
+ describe BtsAircraft do
5
+ before :all do
6
+ BtsAircraft.auto_upgrade!
7
+ end
8
+
9
+ describe 'import', :data_miner => true do
10
+ before do
11
+ require 'earth/air/bts_aircraft/data_miner'
12
+ end
13
+
14
+ it 'should import data' do
15
+ BtsAircraft.run_data_miner!
16
+ BtsAircraft.all.count.should == 378
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'earth/air/flight_segment'
3
+
4
+ describe FlightSegment do
5
+ before :all do
6
+ FlightSegment.auto_upgrade!
7
+ end
8
+
9
+ describe 'import', :data_miner => true do
10
+ before do
11
+ require 'earth/air/flight_segment/data_miner'
12
+ end
13
+
14
+ it 'should import data' do
15
+ FlightSegment.run_data_miner!
16
+ FlightSegment.all.count.should == 1_149_003
17
+ end
18
+ end
19
+
20
+ describe "verify imported data", :sanity => true do
21
+ it "should have year from 2009 to present" do
22
+ FlightSegment.where("year IS NULL OR year < 2009 OR year > #{::Time.now.year}").count.should == 0
23
+ end
24
+
25
+ it "should have origin airport in airports" do
26
+ # FIXME TODO
27
+ end
28
+
29
+ it "should have destination airport in airports" do
30
+ # FIXME TODO
31
+ end
32
+
33
+ it "should have origin country iso code in countries" do
34
+ # FIXME TODO
35
+ end
36
+
37
+ it "should have destination country iso code in countries" do
38
+ # FIXME TODO
39
+ end
40
+
41
+ it "should have airline name" do
42
+ FlightSegment.where(:airline_name => nil).count.should == 0
43
+ end
44
+
45
+ it "should have aircraft description" do
46
+ FlightSegment.where(:aircraft_description => nil).count.should == 0
47
+ end
48
+ end
49
+ end