earth 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -5
- data/README.markdown +0 -8
- data/Rakefile +14 -10
- data/bin/earth_tester.rb +12 -12
- data/earth.gemspec +2 -1
- data/features/automobile_make_fleet_year.feature +9 -19
- data/features/automobile_make_model_year.feature +4 -4
- data/features/support/env.rb +11 -7
- data/features/support/imports/automobile_make_fleet_year_bad.csv +1 -1
- data/features/support/imports/automobile_make_fleet_year_good.csv +1 -1
- data/features/support/imports/automobile_make_model_year_bad.csv +1 -1
- data/features/support/imports/automobile_make_model_year_good.csv +1 -1
- data/lib/earth/air/aircraft/data_miner.rb +63 -15
- data/lib/earth/air/aircraft.rb +0 -11
- data/lib/earth/air/aircraft_class/data_miner.rb +0 -13
- data/lib/earth/air/aircraft_class.rb +12 -3
- data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
- data/lib/earth/air/aircraft_fuel_use_equation.rb +12 -3
- data/lib/earth/air/airline/data_miner.rb +0 -7
- data/lib/earth/air/airline.rb +6 -3
- data/lib/earth/air/airport/data_miner.rb +5 -14
- data/lib/earth/air/airport.rb +9 -7
- data/lib/earth/air/bts_aircraft/data_miner.rb +0 -5
- data/lib/earth/air/bts_aircraft.rb +3 -3
- data/lib/earth/air/data_miner.rb +2 -3
- data/lib/earth/air/flight_distance_class/data_miner.rb +0 -6
- data/lib/earth/air/flight_distance_class.rb +4 -3
- data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
- data/lib/earth/air/flight_seat_class.rb +6 -3
- data/lib/earth/air/flight_segment/data_miner.rb +30 -112
- data/lib/earth/air/flight_segment.rb +47 -13
- data/lib/earth/air.rb +2 -1
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -25
- data/lib/earth/automobile/automobile_fuel.rb +24 -8
- data/lib/earth/automobile/automobile_make/data_miner.rb +3 -16
- data/lib/earth/automobile/automobile_make.rb +5 -3
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +16 -30
- data/lib/earth/automobile/automobile_make_fleet_year.rb +10 -7
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -11
- data/lib/earth/automobile/automobile_make_model.rb +9 -7
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +4 -17
- data/lib/earth/automobile/automobile_make_model_year.rb +11 -6
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +37 -65
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +36 -6
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +3 -15
- data/lib/earth/automobile/automobile_make_year.rb +8 -7
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -15
- data/lib/earth/automobile/automobile_size_class.rb +13 -2
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_size_class_year.rb +10 -3
- data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -12
- data/lib/earth/automobile/automobile_type_fuel_age.rb +10 -2
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_type_fuel_control.rb +9 -3
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -17
- data/lib/earth/automobile/automobile_type_fuel_year.rb +14 -6
- data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -13
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +12 -7
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +9 -6
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -10
- data/lib/earth/automobile/automobile_type_year.rb +9 -3
- data/lib/earth/bus/bus_class/data_miner.rb +0 -29
- data/lib/earth/bus/bus_class.rb +27 -2
- data/lib/earth/bus/bus_fuel/data_miner.rb +1 -16
- data/lib/earth/bus/bus_fuel.rb +15 -8
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -10
- data/lib/earth/bus/bus_fuel_control.rb +8 -3
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -10
- data/lib/earth/bus/bus_fuel_year_control.rb +8 -7
- data/lib/earth/bus/data_miner.rb +2 -0
- data/lib/earth/bus.rb +2 -0
- data/lib/earth/computation/computation_carrier/data_miner.rb +0 -5
- data/lib/earth/computation/computation_carrier.rb +3 -2
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -8
- data/lib/earth/computation/computation_carrier_instance_class.rb +6 -6
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -7
- data/lib/earth/computation/computation_carrier_region.rb +6 -7
- data/lib/earth/computation/data_miner.rb +2 -0
- data/lib/earth/computation.rb +2 -0
- data/lib/earth/diet/diet_class/data_miner.rb +0 -16
- data/lib/earth/diet/diet_class.rb +16 -4
- data/lib/earth/diet/food_group/data_miner.rb +0 -9
- data/lib/earth/diet/food_group.rb +7 -2
- data/lib/earth/fuel/fuel/data_miner.rb +0 -16
- data/lib/earth/fuel/fuel.rb +14 -2
- data/lib/earth/fuel/fuel_price/data_miner.rb +0 -6
- data/lib/earth/fuel/fuel_price.rb +4 -6
- data/lib/earth/fuel/fuel_type/data_miner.rb +0 -14
- data/lib/earth/fuel/fuel_type.rb +14 -4
- data/lib/earth/fuel/fuel_year/data_miner.rb +0 -16
- data/lib/earth/fuel/fuel_year.rb +14 -2
- data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -9
- data/lib/earth/fuel/greenhouse_gas.rb +10 -5
- data/lib/earth/hospitality/lodging_class/data_miner.rb +0 -12
- data/lib/earth/hospitality/lodging_class.rb +10 -2
- data/lib/earth/industry/data_miner.rb +0 -0
- data/lib/earth/industry/industry.rb +3 -10
- data/lib/earth/industry/industry_product.rb +6 -13
- data/lib/earth/industry/industry_product_line.rb +5 -12
- data/lib/earth/industry/industry_sector.rb +5 -12
- data/lib/earth/industry/merchant.rb +4 -11
- data/lib/earth/industry/merchant_category.rb +3 -10
- data/lib/earth/industry/merchant_category_industry.rb +5 -12
- data/lib/earth/industry/product_line.rb +5 -12
- data/lib/earth/industry/product_line_industry_product.rb +5 -12
- data/lib/earth/industry/sector.rb +5 -12
- data/lib/earth/locality/census_division/data_miner.rb +0 -23
- data/lib/earth/locality/census_division.rb +21 -6
- data/lib/earth/locality/census_region/data_miner.rb +0 -5
- data/lib/earth/locality/census_region.rb +3 -2
- data/lib/earth/locality/climate_division/data_miner.rb +0 -7
- data/lib/earth/locality/climate_division.rb +5 -7
- data/lib/earth/locality/country/data_miner.rb +16 -29
- data/lib/earth/locality/country.rb +15 -4
- data/lib/earth/locality/data_miner.rb +3 -0
- data/lib/earth/locality/egrid_region/data_miner.rb +0 -5
- data/lib/earth/locality/egrid_region.rb +5 -8
- data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -20
- data/lib/earth/locality/egrid_subregion.rb +17 -6
- data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +4 -13
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +8 -4
- data/lib/earth/locality/state/data_miner.rb +0 -8
- data/lib/earth/locality/state.rb +6 -7
- data/lib/earth/locality/urbanity/data_miner.rb +0 -4
- data/lib/earth/locality/urbanity.rb +2 -2
- data/lib/earth/locality/zip_code/data_miner.rb +0 -10
- data/lib/earth/locality/zip_code.rb +8 -6
- data/lib/earth/locality.rb +3 -0
- data/lib/earth/pet/breed/data_miner.rb +0 -7
- data/lib/earth/pet/breed.rb +5 -6
- data/lib/earth/pet/breed_gender/data_miner.rb +0 -8
- data/lib/earth/pet/breed_gender.rb +6 -6
- data/lib/earth/pet/gender/data_miner.rb +0 -3
- data/lib/earth/pet/gender.rb +2 -2
- data/lib/earth/pet/species/data_miner.rb +0 -17
- data/lib/earth/pet/species.rb +17 -4
- data/lib/earth/rail/rail_class/data_miner.rb +0 -14
- data/lib/earth/rail/rail_class.rb +12 -3
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +0 -6
- data/lib/earth/residence/air_conditioner_use.rb +5 -3
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +0 -6
- data/lib/earth/residence/clothes_machine_use.rb +4 -2
- data/lib/earth/residence/data_miner.rb +2 -0
- data/lib/earth/residence/dishwasher_use/data_miner.rb +0 -6
- data/lib/earth/residence/dishwasher_use.rb +5 -3
- data/lib/earth/residence/residence_appliance/data_miner.rb +0 -6
- data/lib/earth/residence/residence_appliance.rb +4 -2
- data/lib/earth/residence/residence_class/data_miner.rb +0 -4
- data/lib/earth/residence/residence_class.rb +2 -2
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -14
- data/lib/earth/residence/residence_fuel_price.rb +12 -7
- data/lib/earth/residence/residence_fuel_type/data_miner.rb +0 -8
- data/lib/earth/residence/residence_fuel_type.rb +6 -2
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -94
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +92 -6
- data/lib/earth/residence.rb +2 -0
- data/lib/earth/shipping/carrier/data_miner.rb +0 -10
- data/lib/earth/shipping/carrier.rb +8 -2
- data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -10
- data/lib/earth/shipping/carrier_mode.rb +9 -3
- data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -7
- data/lib/earth/shipping/shipment_mode.rb +5 -2
- data/lib/earth/version.rb +1 -1
- data/lib/earth.rb +92 -84
- data/spec/earth/air/aircraft_spec.rb +1 -1
- data/spec/earth_spec.rb +15 -15
- data/spec/spec_helper.rb +12 -9
- metadata +175 -171
- data/lib/earth/active_record_ext.rb +0 -9
- data/lib/earth/air/aircraft_manufacturer/data_miner.rb +0 -21
- data/lib/earth/air/aircraft_manufacturer.rb +0 -7
- data/lib/earth/base.rb +0 -7
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
AutomobileMakeModelYearVariant.class_eval do
|
|
2
|
-
|
|
2
|
+
# For errata
|
|
3
|
+
class AutomobileMakeModelYearVariant::Guru
|
|
3
4
|
def transmission_is_blank?(row)
|
|
4
5
|
row['transmission'].blank?
|
|
5
6
|
end
|
|
6
|
-
|
|
7
|
+
|
|
7
8
|
def is_a_2007_gmc_or_chevrolet?(row)
|
|
8
9
|
row['year'] == 2007 and %w(GMC CHEVROLET).include? row['MFR'].upcase
|
|
9
10
|
end
|
|
10
|
-
|
|
11
|
+
|
|
11
12
|
def is_a_porsche?(row)
|
|
12
13
|
row['make'].to_s.upcase == 'PORSCHE'
|
|
13
14
|
end
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
def is_not_a_porsche?(row)
|
|
16
17
|
!is_a_porsche? row
|
|
17
18
|
end
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
def is_a_mercedes_benz?(row)
|
|
20
21
|
row['make'].to_s =~ /MERCEDES/i
|
|
21
22
|
end
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
def is_a_lexus?(row)
|
|
24
25
|
row['make'].to_s.upcase == 'LEXUS'
|
|
25
26
|
end
|
|
26
|
-
|
|
27
|
+
|
|
27
28
|
def is_a_bmw?(row)
|
|
28
29
|
row['make'].to_s.upcase == 'BMW'
|
|
29
30
|
end
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
def is_a_ford?(row)
|
|
32
33
|
row['make'].to_s.upcase == 'FORD'
|
|
33
34
|
end
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
def is_a_rolls_royce_and_model_contains_bentley?(row)
|
|
36
37
|
is_a_rolls_royce?(row) and model_contains_bentley?(row)
|
|
37
38
|
end
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
def is_a_bentley?(row)
|
|
40
41
|
row['make'].to_s.upcase == 'BENTLEY'
|
|
41
42
|
end
|
|
42
|
-
|
|
43
|
+
|
|
43
44
|
def is_a_rolls_royce?(row)
|
|
44
45
|
row['make'].to_s =~ /ROLLS/i
|
|
45
46
|
end
|
|
46
|
-
|
|
47
|
+
|
|
47
48
|
def is_a_turbo_brooklands?(row)
|
|
48
49
|
row['model'] =~ /TURBO R\/RL BKLDS/i
|
|
49
50
|
end
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
def model_contains_maybach?(row)
|
|
52
53
|
row['model'] =~ /MAYBACH/i
|
|
53
54
|
end
|
|
@@ -56,6 +57,10 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
56
57
|
row['model'] =~ /BENTLEY/i
|
|
57
58
|
end
|
|
58
59
|
|
|
60
|
+
def name_contains_smart?(row)
|
|
61
|
+
row['model'] =~ / smart /i
|
|
62
|
+
end
|
|
63
|
+
|
|
59
64
|
def source_code
|
|
60
65
|
IO.read __FILE__
|
|
61
66
|
end
|
|
@@ -260,44 +265,6 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
260
265
|
end
|
|
261
266
|
|
|
262
267
|
data_miner do
|
|
263
|
-
schema Earth.database_options do
|
|
264
|
-
string 'row_hash'
|
|
265
|
-
string 'name' # short name!
|
|
266
|
-
string 'make_name'
|
|
267
|
-
string 'make_model_name' # make + model
|
|
268
|
-
string 'make_year_name' # make + year
|
|
269
|
-
string 'make_model_year_name' # make + model + year
|
|
270
|
-
integer 'year'
|
|
271
|
-
float 'fuel_efficiency'
|
|
272
|
-
string 'fuel_efficiency_units'
|
|
273
|
-
float 'fuel_efficiency_city'
|
|
274
|
-
string 'fuel_efficiency_city_units'
|
|
275
|
-
float 'fuel_efficiency_highway'
|
|
276
|
-
string 'fuel_efficiency_highway_units'
|
|
277
|
-
string 'fuel_code'
|
|
278
|
-
string 'transmission'
|
|
279
|
-
string 'drive'
|
|
280
|
-
boolean 'turbo'
|
|
281
|
-
boolean 'supercharger'
|
|
282
|
-
integer 'cylinders'
|
|
283
|
-
float 'displacement'
|
|
284
|
-
float 'raw_fuel_efficiency_city'
|
|
285
|
-
string 'raw_fuel_efficiency_city_units'
|
|
286
|
-
float 'raw_fuel_efficiency_highway'
|
|
287
|
-
string 'raw_fuel_efficiency_highway_units'
|
|
288
|
-
integer 'carline_mfr_code'
|
|
289
|
-
integer 'vi_mfr_code'
|
|
290
|
-
integer 'carline_code'
|
|
291
|
-
integer 'carline_class_code'
|
|
292
|
-
boolean 'injection'
|
|
293
|
-
string 'carline_class_name'
|
|
294
|
-
string 'speeds'
|
|
295
|
-
index 'make_name'
|
|
296
|
-
index 'make_model_name'
|
|
297
|
-
index 'make_year_name'
|
|
298
|
-
index 'make_model_year_name'
|
|
299
|
-
end
|
|
300
|
-
|
|
301
268
|
# 1985---1997
|
|
302
269
|
# FIXME TODO one Jaguar in the 1990 FEG has no model name
|
|
303
270
|
# FIXME TODO 14 records in the 1995 FEG are missing fuel efficiencies
|
|
@@ -312,7 +279,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
312
279
|
:select => lambda { |row| row['model'].present? and (row['suppress_code'].blank? or row['suppress_code'].to_f == 0) and row['state_code'] == 'F' },
|
|
313
280
|
:filename => filename,
|
|
314
281
|
:transform => { :class => AutomobileMakeModelYearVariant::ParserB, :year => "19#{yy}".to_i },
|
|
315
|
-
:errata => {
|
|
282
|
+
:errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEFqVXRvQjRGNUpxNHFCOXhqSjRmdlE&output=csv', :responder => AutomobileMakeModelYearVariant::Guru.new }) do
|
|
316
283
|
key 'row_hash'
|
|
317
284
|
store 'name', :field_name => 'model'
|
|
318
285
|
store 'make_name', :field_name => 'make'
|
|
@@ -350,7 +317,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
350
317
|
}.sort { |a, b| a.first <=> b.first }.each do |year, options|
|
|
351
318
|
import "#{ year } Fuel Economy Guide",
|
|
352
319
|
options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserC, :year => year },
|
|
353
|
-
:errata => {
|
|
320
|
+
:errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEFqVXRvQjRGNUpxNHFCOXhqSjRmdlE&output=csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
|
|
354
321
|
:select => lambda { |row| row['model'].present? }) do
|
|
355
322
|
key 'row_hash'
|
|
356
323
|
store 'name', :field_name => 'model'
|
|
@@ -384,7 +351,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
384
351
|
}.sort { |a, b| a.first <=> b.first }.each do |year, options|
|
|
385
352
|
import "#{ year } Fuel Economy Guide",
|
|
386
353
|
options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserD, :year => year },
|
|
387
|
-
:errata => {
|
|
354
|
+
:errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEFqVXRvQjRGNUpxNHFCOXhqSjRmdlE&output=csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
|
|
388
355
|
:select => lambda { |row| row['model'].present? }) do
|
|
389
356
|
key 'row_hash'
|
|
390
357
|
store 'name', :field_name => 'model'
|
|
@@ -411,11 +378,11 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
411
378
|
# 2010--?
|
|
412
379
|
{
|
|
413
380
|
2010 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/10data.zip', :filename => '2010FE Guide for DOE-all rel dates-no-sales 4-9-10public.xls' },
|
|
414
|
-
2011 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/11data.zip', :filename => '2011FEGuide-for DOE rel-dates before 1-23-2011-no-sales-01-10-
|
|
381
|
+
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' }
|
|
415
382
|
}.sort { |a, b| a.first <=> b.first }.each do |year, options|
|
|
416
383
|
import "#{ year } Fuel Economy Guide",
|
|
417
384
|
options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserE, :year => year },
|
|
418
|
-
:errata => {
|
|
385
|
+
:errata => { :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdEFqVXRvQjRGNUpxNHFCOXhqSjRmdlE&output=csv', :responder => AutomobileMakeModelYearVariant::Guru.new },
|
|
419
386
|
:select => lambda { |row| row['model'].present? }) do
|
|
420
387
|
key 'row_hash'
|
|
421
388
|
store 'name', :field_name => 'model'
|
|
@@ -452,12 +419,15 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
452
419
|
end
|
|
453
420
|
|
|
454
421
|
# Note: need to divide by 0.425143707 b/c equation is designed for miles / gallon not km / l
|
|
422
|
+
# Note: EPA seems to adjust differently for plug-in hybrid electric vehicles (e.g. Leaf and Volt)
|
|
455
423
|
process "Calculate adjusted fuel efficiency using the latest EPA equations from EPA Fuel Economy Trends report Appendix A including conversion from miles per gallon to kilometres per litre" do
|
|
456
424
|
update_all 'fuel_efficiency_city = 1 / ((0.003259 / 0.425143707) + (1.1805 / raw_fuel_efficiency_city))'
|
|
457
425
|
update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
|
|
458
426
|
end
|
|
459
427
|
|
|
460
428
|
# This will be useful later for calculating MakeModel and Make fuel efficiency based on Variant
|
|
429
|
+
# NOTE: we use a 43/57 city/highway weighting per the latest EPA analysis of real-world driving behavior
|
|
430
|
+
# This results in a deviation from EPA fuel economy label values which use a historical 55/45 weighting
|
|
461
431
|
process "Calculate combined adjusted fuel efficiency using the latest EPA equation" do
|
|
462
432
|
update_all "fuel_efficiency = 1 / ((0.43 / fuel_efficiency_city) + (0.57 / fuel_efficiency_highway))"
|
|
463
433
|
update_all "fuel_efficiency_units = 'kilometres_per_litre'"
|
|
@@ -471,7 +441,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
471
441
|
end
|
|
472
442
|
|
|
473
443
|
verify "Year should be from 1985 to 2011" do
|
|
474
|
-
|
|
444
|
+
connection.select_values("SELECT DISTINCT year FROM automobile_make_model_year_variants").each do |year|
|
|
475
445
|
unless year > 1984 and year < 2012
|
|
476
446
|
raise "Invalid year in automobile_make_model_year_variants: #{year} is not from 1985 to 2011"
|
|
477
447
|
end
|
|
@@ -483,8 +453,8 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
483
453
|
end
|
|
484
454
|
|
|
485
455
|
verify "Fuel code should appear in AutomobileFuel" do
|
|
486
|
-
valid_codes =
|
|
487
|
-
|
|
456
|
+
valid_codes = connection.select_values("SELECT DISTINCT code FROM automobile_fuels")
|
|
457
|
+
connection.select_values("SELECT DISTINCT fuel_code FROM automobile_make_model_year_variants").each do |fuel_code|
|
|
488
458
|
unless valid_codes.include?(fuel_code)
|
|
489
459
|
raise "Invalide fuel code in automobile_make_model_year_variants: #{fuel_code} is not in #{valid_codes}"
|
|
490
460
|
end
|
|
@@ -493,18 +463,20 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
|
493
463
|
|
|
494
464
|
verify "Fuel efficiencies should be greater than zero" do
|
|
495
465
|
[:fuel_efficiency, :fuel_efficiency_city, :fuel_efficiency_highway].each do |field|
|
|
496
|
-
|
|
497
|
-
raise "Invalid
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
466
|
+
if AutomobileMakeModelYearVariant.where(field => nil).any?
|
|
467
|
+
raise "Invalid #{field} in automobile_make_model_year_variants: nil is not > 0"
|
|
468
|
+
else
|
|
469
|
+
min = AutomobileMakeModelYearVariant.minimum(field)
|
|
470
|
+
unless min > 0
|
|
471
|
+
raise "Invalid #{field} in automobile_make_model_year_variants: #{min} is not > 0"
|
|
472
|
+
end
|
|
501
473
|
end
|
|
502
474
|
end
|
|
503
475
|
end
|
|
504
476
|
|
|
505
477
|
verify "Fuel efficiency units should be kilometres per litre" do
|
|
506
478
|
%w{ fuel_efficiency_units fuel_efficiency_city_units fuel_efficiency_highway_units }.each do |field|
|
|
507
|
-
|
|
479
|
+
connection.select_values("SELECT DISTINCT #{field} FROM automobile_make_model_year_variants").each do |value|
|
|
508
480
|
unless value == 'kilometres_per_litre'
|
|
509
481
|
raise "Invalid #{field} in automobile_make_model_year_variants: #{value} is not 'kilometres_per_litre'"
|
|
510
482
|
end
|
|
@@ -6,11 +6,41 @@ class AutomobileMakeModelYearVariant < ActiveRecord::Base
|
|
|
6
6
|
belongs_to :make_model_year, :class_name => 'AutomobileMakeModelYear', :foreign_key => 'make_model_year_name'
|
|
7
7
|
belongs_to :fuel, :class_name => 'AutomobileFuel', :foreign_key => 'fuel_code', :primary_key => 'code'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
create_table do
|
|
10
|
+
string 'row_hash'
|
|
11
|
+
string 'name' # short name!
|
|
12
|
+
string 'make_name'
|
|
13
|
+
string 'make_model_name' # make + model
|
|
14
|
+
string 'make_year_name' # make + year
|
|
15
|
+
string 'make_model_year_name' # make + model + year
|
|
16
|
+
integer 'year'
|
|
17
|
+
float 'fuel_efficiency'
|
|
18
|
+
string 'fuel_efficiency_units'
|
|
19
|
+
float 'fuel_efficiency_city'
|
|
20
|
+
string 'fuel_efficiency_city_units'
|
|
21
|
+
float 'fuel_efficiency_highway'
|
|
22
|
+
string 'fuel_efficiency_highway_units'
|
|
23
|
+
string 'fuel_code'
|
|
24
|
+
string 'transmission'
|
|
25
|
+
string 'drive'
|
|
26
|
+
boolean 'turbo'
|
|
27
|
+
boolean 'supercharger'
|
|
28
|
+
integer 'cylinders'
|
|
29
|
+
float 'displacement'
|
|
30
|
+
float 'raw_fuel_efficiency_city'
|
|
31
|
+
string 'raw_fuel_efficiency_city_units'
|
|
32
|
+
float 'raw_fuel_efficiency_highway'
|
|
33
|
+
string 'raw_fuel_efficiency_highway_units'
|
|
34
|
+
integer 'carline_mfr_code'
|
|
35
|
+
integer 'vi_mfr_code'
|
|
36
|
+
integer 'carline_code'
|
|
37
|
+
integer 'carline_class_code'
|
|
38
|
+
boolean 'injection'
|
|
39
|
+
string 'carline_class_name'
|
|
40
|
+
string 'speeds'
|
|
41
|
+
index 'make_name'
|
|
42
|
+
index 'make_model_name'
|
|
43
|
+
index 'make_year_name'
|
|
44
|
+
index 'make_model_year_name'
|
|
15
45
|
end
|
|
16
46
|
end
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
AutomobileMakeYear.class_eval do
|
|
2
2
|
data_miner do
|
|
3
3
|
process "Start from scratch" do
|
|
4
|
-
|
|
4
|
+
delete_all
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
string 'name'
|
|
9
|
-
string 'make_name'
|
|
10
|
-
integer 'year'
|
|
11
|
-
float 'fuel_efficiency'
|
|
12
|
-
string 'fuel_efficiency_units'
|
|
13
|
-
integer 'volume' # This will sometimes be null because not all make_years have CAFE data
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
process "Ensure AutomobileMakeModelYearVariant is populated" do
|
|
7
|
+
process "Ensure AutomobileMakeModelYearVariant and AutomobileMakeFleetYear are populated" do
|
|
17
8
|
AutomobileMakeModelYearVariant.run_data_miner!
|
|
9
|
+
AutomobileMakeFleetYear.run_data_miner!
|
|
18
10
|
end
|
|
19
11
|
|
|
20
12
|
process "Derive manufacturer names and years from automobile make model year variants" do
|
|
@@ -33,10 +25,6 @@ AutomobileMakeYear.class_eval do
|
|
|
33
25
|
}
|
|
34
26
|
end
|
|
35
27
|
|
|
36
|
-
process "Ensure AutomobileMakeFleetYear is populated" do
|
|
37
|
-
AutomobileMakeFleetYear.run_data_miner!
|
|
38
|
-
end
|
|
39
|
-
|
|
40
28
|
# FIXME TODO make this a method on AutomobileMakeYear?
|
|
41
29
|
process "Calculate fuel efficiency from make fleet years for makes with CAFE data" do
|
|
42
30
|
make_fleet_years = AutomobileMakeFleetYear.arel_table
|
|
@@ -3,12 +3,13 @@ class AutomobileMakeYear < ActiveRecord::Base
|
|
|
3
3
|
|
|
4
4
|
belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
|
|
5
5
|
has_many :fleet_years, :class_name => 'AutomobileMakeFleetYear', :foreign_key => 'make_year_name'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
|
|
7
|
+
create_table do
|
|
8
|
+
string 'name'
|
|
9
|
+
string 'make_name'
|
|
10
|
+
integer 'year'
|
|
11
|
+
float 'fuel_efficiency'
|
|
12
|
+
string 'fuel_efficiency_units'
|
|
13
|
+
integer 'volume' # This will sometimes be null because not all make_years have CAFE data
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
AutomobileSizeClass.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
float 'annual_distance'
|
|
7
|
-
string 'annual_distance_units'
|
|
8
|
-
float 'fuel_efficiency_city'
|
|
9
|
-
string 'fuel_efficiency_city_units'
|
|
10
|
-
float 'fuel_efficiency_highway'
|
|
11
|
-
string 'fuel_efficiency_highway_units'
|
|
12
|
-
float 'hybrid_fuel_efficiency_city_multiplier'
|
|
13
|
-
float 'hybrid_fuel_efficiency_highway_multiplier'
|
|
14
|
-
float 'conventional_fuel_efficiency_city_multiplier'
|
|
15
|
-
float 'conventional_fuel_efficiency_highway_multiplier'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
3
|
# FIXME TODO pull this from AutomobileSizeClassYear
|
|
19
4
|
import "a list of size classes and pre-calculated fuel efficiencies",
|
|
20
5
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHlRUE5IcWlrRENhN0EtUldPTy1rX1E&gid=0&output=csv' do
|
|
@@ -6,7 +6,18 @@ class AutomobileSizeClass < ActiveRecord::Base
|
|
|
6
6
|
:conventional_fuel_efficiency_city_multiplier => 0.987,
|
|
7
7
|
:conventional_fuel_efficiency_highway_multiplier => 0.996
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
create_table do
|
|
10
|
+
string 'name'
|
|
11
|
+
string 'type_name'
|
|
12
|
+
float 'annual_distance'
|
|
13
|
+
string 'annual_distance_units'
|
|
14
|
+
float 'fuel_efficiency_city'
|
|
15
|
+
string 'fuel_efficiency_city_units'
|
|
16
|
+
float 'fuel_efficiency_highway'
|
|
17
|
+
string 'fuel_efficiency_highway_units'
|
|
18
|
+
float 'hybrid_fuel_efficiency_city_multiplier'
|
|
19
|
+
float 'hybrid_fuel_efficiency_highway_multiplier'
|
|
20
|
+
float 'conventional_fuel_efficiency_city_multiplier'
|
|
21
|
+
float 'conventional_fuel_efficiency_highway_multiplier'
|
|
11
22
|
end
|
|
12
23
|
end
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
AutomobileSizeClassYear.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'size_class_name'
|
|
6
|
-
integer 'year'
|
|
7
|
-
string 'type_name'
|
|
8
|
-
float 'fuel_efficiency_city'
|
|
9
|
-
string 'fuel_efficiency_city_units'
|
|
10
|
-
float 'fuel_efficiency_highway'
|
|
11
|
-
string 'fuel_efficiency_highway_units'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
3
|
import "automobile size class year fuel efficiencies from the 2010 EPA Fuel Economy Trends report",
|
|
15
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDZOLWdDdlZja04xZkJYc3NjeGxQamc&hl=en&gid=0&output=csv' do
|
|
16
5
|
key 'name'
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
class AutomobileSizeClassYear < ActiveRecord::Base
|
|
2
2
|
set_primary_key :name
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
|
|
4
|
+
create_table do
|
|
5
|
+
string 'name'
|
|
6
|
+
string 'size_class_name'
|
|
7
|
+
integer 'year'
|
|
8
|
+
string 'type_name'
|
|
9
|
+
float 'fuel_efficiency_city'
|
|
10
|
+
string 'fuel_efficiency_city_units'
|
|
11
|
+
float 'fuel_efficiency_highway'
|
|
12
|
+
string 'fuel_efficiency_highway_units'
|
|
6
13
|
end
|
|
7
14
|
end
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
# DEPRECATED - use AutomobileTypeFuelYearAge
|
|
2
2
|
AutomobileTypeFuelAge.class_eval do
|
|
3
3
|
data_miner do
|
|
4
|
-
schema Earth.database_options do
|
|
5
|
-
string 'name'
|
|
6
|
-
string 'type_name'
|
|
7
|
-
string 'fuel_common_name'
|
|
8
|
-
integer 'age'
|
|
9
|
-
float 'age_percent'
|
|
10
|
-
float 'total_travel_percent'
|
|
11
|
-
float 'annual_distance'
|
|
12
|
-
string 'annual_distance_units'
|
|
13
|
-
integer 'vehicles'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
4
|
import "age distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
|
|
17
5
|
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
|
18
6
|
:filename => 'Annex Tables/Annex 3/Table A-91.csv',
|
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
class AutomobileTypeFuelAge < ActiveRecord::Base
|
|
3
3
|
set_primary_key :name
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
create_table do
|
|
6
|
+
string 'name'
|
|
7
|
+
string 'type_name'
|
|
8
|
+
string 'fuel_common_name'
|
|
9
|
+
integer 'age'
|
|
10
|
+
float 'age_percent'
|
|
11
|
+
float 'total_travel_percent'
|
|
12
|
+
float 'annual_distance'
|
|
13
|
+
string 'annual_distance_units'
|
|
14
|
+
integer 'vehicles'
|
|
7
15
|
end
|
|
8
16
|
end
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
AutomobileTypeFuelControl.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
string 'fuel_common_name'
|
|
7
|
-
string 'control_name'
|
|
8
|
-
float 'ch4_emission_factor'
|
|
9
|
-
string 'ch4_emission_factor_units'
|
|
10
|
-
float 'n2o_emission_factor'
|
|
11
|
-
string 'n2o_emission_factor_units'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
3
|
import "automobile type fuel control data derived from the 2010 EPA GHG Inventory",
|
|
15
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEloSTU5YUNOUXRFRUcxWHlTUi1GMkE&hl=en&gid=0&output=csv' do
|
|
16
5
|
key 'name'
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
class AutomobileTypeFuelControl < ActiveRecord::Base
|
|
2
2
|
set_primary_key :name
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
create_table do
|
|
4
|
+
string 'name'
|
|
5
|
+
string 'type_name'
|
|
6
|
+
string 'fuel_common_name'
|
|
7
|
+
string 'control_name'
|
|
8
|
+
float 'ch4_emission_factor'
|
|
9
|
+
string 'ch4_emission_factor_units'
|
|
10
|
+
float 'n2o_emission_factor'
|
|
11
|
+
string 'n2o_emission_factor_units'
|
|
6
12
|
end
|
|
7
13
|
end
|
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
AutomobileTypeFuelYear.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
string 'fuel_common_name'
|
|
7
|
-
integer 'year'
|
|
8
|
-
string 'type_year_name'
|
|
9
|
-
float 'total_travel'
|
|
10
|
-
string 'total_travel_units'
|
|
11
|
-
float 'fuel_consumption'
|
|
12
|
-
string 'fuel_consumption_units'
|
|
13
|
-
float 'ch4_emission_factor'
|
|
14
|
-
string 'ch4_emission_factor_units'
|
|
15
|
-
float 'n2o_emission_factor'
|
|
16
|
-
string 'n2o_emission_factor_units'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
3
|
import "total vehicle miles travelled by gasoline passenger cars from the 2010 EPA GHG Inventory",
|
|
20
4
|
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
|
21
5
|
:filename => 'Annex Tables/Annex 3/Table A-87.csv',
|
|
@@ -88,7 +72,7 @@ AutomobileTypeFuelYear.class_eval do
|
|
|
88
72
|
end
|
|
89
73
|
end
|
|
90
74
|
|
|
91
|
-
process "Ensure
|
|
75
|
+
process "Ensure AutomobileTypeFuelYearControl and AutomobileTypeFuelControl are populated" do
|
|
92
76
|
AutomobileTypeFuelYearControl.run_data_miner!
|
|
93
77
|
AutomobileTypeFuelControl.run_data_miner!
|
|
94
78
|
end
|
|
@@ -4,11 +4,19 @@ class AutomobileTypeFuelYear < ActiveRecord::Base
|
|
|
4
4
|
has_many :year_controls, :class_name => 'AutomobileTypeFuelYearControl', :foreign_key => 'type_fuel_year_name'
|
|
5
5
|
belongs_to :type_year, :class_name => 'AutomobileTypeYear', :foreign_key => 'type_year_name'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
create_table do
|
|
8
|
+
string 'name'
|
|
9
|
+
string 'type_name'
|
|
10
|
+
string 'fuel_common_name'
|
|
11
|
+
integer 'year'
|
|
12
|
+
string 'type_year_name'
|
|
13
|
+
float 'total_travel'
|
|
14
|
+
string 'total_travel_units'
|
|
15
|
+
float 'fuel_consumption'
|
|
16
|
+
string 'fuel_consumption_units'
|
|
17
|
+
float 'ch4_emission_factor'
|
|
18
|
+
string 'ch4_emission_factor_units'
|
|
19
|
+
float 'n2o_emission_factor'
|
|
20
|
+
string 'n2o_emission_factor_units'
|
|
13
21
|
end
|
|
14
22
|
end
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
AutomobileTypeFuelYearAge.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
string 'fuel_common_name'
|
|
7
|
-
integer 'year'
|
|
8
|
-
integer 'age'
|
|
9
|
-
string 'type_fuel_year_name'
|
|
10
|
-
float 'total_travel_percent'
|
|
11
|
-
float 'annual_distance'
|
|
12
|
-
string 'annual_distance_units'
|
|
13
|
-
integer 'vehicles'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
3
|
import "total travel distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
|
|
17
4
|
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
|
18
5
|
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
|
@@ -2,12 +2,17 @@ class AutomobileTypeFuelYearAge < ActiveRecord::Base
|
|
|
2
2
|
set_primary_key :name
|
|
3
3
|
|
|
4
4
|
belongs_to :type_fuel_year, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_fuel_year_name'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
|
|
6
|
+
create_table do
|
|
7
|
+
string 'name'
|
|
8
|
+
string 'type_name'
|
|
9
|
+
string 'fuel_common_name'
|
|
10
|
+
integer 'year'
|
|
11
|
+
integer 'age'
|
|
12
|
+
string 'type_fuel_year_name'
|
|
13
|
+
float 'total_travel_percent'
|
|
14
|
+
float 'annual_distance'
|
|
15
|
+
string 'annual_distance_units'
|
|
16
|
+
integer 'vehicles'
|
|
12
17
|
end
|
|
13
18
|
end
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
AutomobileTypeFuelYearControl.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
string 'fuel_common_name'
|
|
7
|
-
integer 'year'
|
|
8
|
-
string 'control_name'
|
|
9
|
-
string 'type_fuel_control_name'
|
|
10
|
-
string 'type_fuel_year_name'
|
|
11
|
-
float 'total_travel_percent'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
3
|
import "automobile type fuel year control data derived from the 2010 EPA GHG Inventory",
|
|
15
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGpQV2xMdlZkV1JzVlVTeU5ZalF6elE&hl=en&gid=0&output=csv' do
|
|
16
5
|
key 'name'
|
|
@@ -3,11 +3,14 @@ class AutomobileTypeFuelYearControl < ActiveRecord::Base
|
|
|
3
3
|
|
|
4
4
|
belongs_to :control, :class_name => 'AutomobileTypeFuelControl', :foreign_key => 'type_fuel_control_name'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
create_table do
|
|
7
|
+
string 'name'
|
|
8
|
+
string 'type_name'
|
|
9
|
+
string 'fuel_common_name'
|
|
10
|
+
integer 'year'
|
|
11
|
+
string 'control_name'
|
|
12
|
+
string 'type_fuel_control_name'
|
|
13
|
+
string 'type_fuel_year_name'
|
|
14
|
+
float 'total_travel_percent'
|
|
12
15
|
end
|
|
13
16
|
end
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
AutomobileTypeYear.class_eval do
|
|
2
2
|
data_miner do
|
|
3
|
-
schema Earth.database_options do
|
|
4
|
-
string 'name'
|
|
5
|
-
string 'type_name'
|
|
6
|
-
integer 'year'
|
|
7
|
-
float 'hfc_emissions'
|
|
8
|
-
string 'hfc_emissions_units'
|
|
9
|
-
float 'hfc_emission_factor'
|
|
10
|
-
string 'hfc_emission_factor_units'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
3
|
import "automobile type year air conditioning emissions derived from the 2010 EPA GHG Inventory",
|
|
14
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFoyTWhDeHpndTV5Ny1aX0sxR1ljSFE&hl=en&gid=0&output=csv' do
|
|
15
5
|
key 'name'
|