earth 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/Gemfile.lock +58 -20
- data/features/automobile_fuel_type.feature +44 -0
- data/features/automobile_make.feature +24 -0
- data/features/automobile_make_fleet_year.feature +44 -0
- data/features/automobile_make_model.feature +24 -0
- data/features/automobile_make_model_year.feature +34 -0
- data/features/automobile_make_model_year_variant.feature +46 -0
- data/features/automobile_make_year.feature +44 -0
- data/features/automobile_size_class.feature +59 -0
- data/features/bus_class.feature +69 -0
- data/features/carrier.feature +64 -0
- data/features/carrier_mode.feature +74 -0
- data/features/egrid_region.feature +14 -0
- data/features/egrid_subregion.feature +36 -0
- data/features/rail_class.feature +64 -0
- data/features/shipment_mode.feature +34 -0
- data/features/support/env.rb +7 -0
- data/features/support/imports/automobile_fuel_type_bad.csv +3 -0
- data/features/support/imports/automobile_fuel_type_good.csv +3 -0
- data/features/support/imports/automobile_make_bad.csv +3 -0
- data/features/support/imports/automobile_make_fleet_year_bad.csv +3 -0
- data/features/support/imports/automobile_make_fleet_year_good.csv +3 -0
- data/features/support/imports/automobile_make_good.csv +3 -0
- data/features/support/imports/automobile_make_model_bad.csv +3 -0
- data/features/support/imports/automobile_make_model_good.csv +3 -0
- data/features/support/imports/automobile_make_model_year_bad.csv +3 -0
- data/features/support/imports/automobile_make_model_year_good.csv +3 -0
- data/features/support/imports/automobile_make_model_year_variant_bad.csv +3 -0
- data/features/support/imports/automobile_make_model_year_variant_good.csv +3 -0
- data/features/support/imports/automobile_make_year_bad.csv +3 -0
- data/features/support/imports/automobile_make_year_good.csv +3 -0
- data/features/support/imports/automobile_size_class_bad.csv +3 -0
- data/features/support/imports/automobile_size_class_good.csv +3 -0
- data/features/support/imports/bus_class_bad.csv +3 -0
- data/features/support/imports/bus_class_good.csv +3 -0
- data/features/support/imports/carrier_bad.csv +3 -0
- data/features/support/imports/carrier_good.csv +3 -0
- data/features/support/imports/carrier_mode_bad.csv +3 -0
- data/features/support/imports/carrier_mode_good.csv +3 -0
- data/features/support/imports/egrid_region_bad.csv +3 -0
- data/features/support/imports/egrid_region_good.csv +3 -0
- data/features/support/imports/egrid_subregion_bad.csv +3 -0
- data/features/support/imports/egrid_subregion_good.csv +3 -0
- data/features/support/imports/rail_class_bad.csv +3 -0
- data/features/support/imports/rail_class_good.csv +3 -0
- data/features/support/imports/shipment_mode_bad.csv +3 -0
- data/features/support/imports/shipment_mode_good.csv +3 -0
- data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +35 -14
- data/lib/earth/automobile/automobile_make/data_miner.rb +24 -9
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +32 -1
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +27 -5
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +35 -5
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +80 -39
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +32 -1
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +67 -4
- data/lib/earth/bus/bus_class/data_miner.rb +73 -0
- data/lib/earth/locality/egrid_region/data_miner.rb +8 -0
- data/lib/earth/locality/egrid_subregion/data_miner.rb +26 -0
- data/lib/earth/rail/rail_class/data_miner.rb +51 -0
- data/lib/earth/shipping/carrier/data_miner.rb +47 -8
- data/lib/earth/shipping/carrier_mode/data_miner.rb +57 -8
- data/lib/earth/shipping/shipment_mode/data_miner.rb +23 -4
- metadata +110 -98
@@ -0,0 +1,3 @@
|
|
1
|
+
name,annual_distance,fuel_efficiency_city,fuel_efficiency_highway,annual_distance_units,fuel_efficiency_city_units,fuel_efficiency_highway_units,hybrid_fuel_efficiency_city_multiplier,hybrid_fuel_efficiency_highway_multiplier,conventional_fuel_efficiency_city_multiplier,conventional_fuel_efficiency_highway_multiplier
|
2
|
+
small,1000,10.0,15.0,kilometres,kilometres_per_litre,kilometres_per_litre,1.1,1.2,0.9,0.95
|
3
|
+
large,0.5,0.1,0.5,kilometres,kilometres_per_litre,kilometres_per_litre
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,distance,distance_units,passengers,speed,speed_units,diesel_intensity,diesel_intensity_units,alternative_fuels_intensity,alternative_fuels_intensity_units,air_conditioning_emission_factor,air_conditioning_emission_factor_units
|
2
|
+
transit,10,kilometres,15,20,kilometres_per_hour,0.5,litres_per_kilometre,0,litres_per_kilometre,0,kilograms_per_kilometre
|
3
|
+
regional,-10,distance_units,0,,,-2,diesel_intensity_units,-2,alternative_fuels_intensity_units
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,distance,distance_units,passengers,speed,speed_units,diesel_intensity,diesel_intensity_units,alternative_fuels_intensity,alternative_fuels_intensity_units,air_conditioning_emission_factor,air_conditioning_emission_factor_units
|
2
|
+
transit,10,kilometres,15,20,kilometres_per_hour,0.5,litres_per_kilometre,0,litres_per_kilometre,0,kilograms_per_kilometre
|
3
|
+
regional,100,kilometres,30,80,kilometres_per_hour,0.1,litres_per_kilometre,0.2,litres_per_kilometre,0.5,kilograms_per_kilometre
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,package_volume,route_inefficiency_factor,transport_emission_factor,corporate_emission_factor,transport_emission_factor_units,corporate_emission_factor_units
|
2
|
+
FedEx,100,1.0,0.1,0.1,kilograms_per_kilogram_kilometre,kilograms_per_package
|
3
|
+
UPS,1000,2.0,1.5,2.0,kilograms_per_kilogram_kilometre,kilograms_per_package
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,carrier_name,mode_name,include_in_fallbacks,package_volume,route_inefficiency_factor,transport_emission_factor,transport_emission_factor_units
|
2
|
+
FedEx ground,FedEx,ground,1,100,1.0,1.2,kilograms_per_kilogram_kilometre
|
3
|
+
FedEx air,FedEx,air,0,1,2.0,4.0,kilograms_per_kilogram_kilometre
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,passengers,distance,distance_units,speed,speed_units,electricity_intensity,electricity_intensity_units,diesel_intensity,diesel_intensity_units
|
2
|
+
commuter,100,50,kilometres,100,kilometres_per_hour,0.7,kilowatt_hours_per_kilometre,0,litres_per_kilometre
|
3
|
+
intercity,0,-20,distance_units,-1,speed_units,,elec_intense_units,-1
|
@@ -0,0 +1,3 @@
|
|
1
|
+
name,passengers,distance,distance_units,speed,speed_units,electricity_intensity,electricity_intensity_units,diesel_intensity,diesel_intensity_units
|
2
|
+
commuter,100,50,kilometres,100,kilometres_per_hour,0.7,kilowatt_hours_per_kilometre,0,litres_per_kilometre
|
3
|
+
intercity,150,200,kilometres,150,kilometres_per_hour,0.8,kilowatt_hours_per_kilometre,0.5,litres_per_kilometre
|
@@ -22,24 +22,45 @@ AutomobileFuelType.class_eval do
|
|
22
22
|
key 'code'
|
23
23
|
store 'name'
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
import "a pre-calculated emission factor and average annual distance for each fuel",
|
27
|
-
:url => '
|
28
|
-
key 'code'
|
27
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDlqeU9vQkVkNG1NZXV4WklKTjJkU3c&hl=en&single=true&gid=0&output=csv' do
|
28
|
+
key 'code'
|
29
29
|
store 'name'
|
30
|
-
store 'annual_distance', :
|
31
|
-
store 'emission_factor', :
|
30
|
+
store 'annual_distance', :units_field_name => 'annual_distance_units'
|
31
|
+
store 'emission_factor', :units_field_name => 'emission_factor_units'
|
32
|
+
end
|
33
|
+
|
34
|
+
verify "Annual distance should be greater than zero" do
|
35
|
+
AutomobileFuelType.all.each do |fuel_type|
|
36
|
+
unless fuel_type.annual_distance > 0.0
|
37
|
+
raise "Invalid annual_distance for AutomobileFuelType #{fuel_type.name}: #{fuel_type.annual_distance} (should be > 0)"
|
38
|
+
end
|
39
|
+
end
|
32
40
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
|
42
|
+
verify "Annual distance units should never be missing" do
|
43
|
+
AutomobileFuelType.all.each do |fuel_type|
|
44
|
+
if fuel_type.annual_distance_units.nil?
|
45
|
+
raise "Missing annual distance units for AutomobileFuelType #{fuel_type.name}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
verify "Emission factor should be zero or more" do
|
51
|
+
AutomobileFuelType.all.each do |fuel_type|
|
52
|
+
unless fuel_type.emission_factor >= 0.0
|
53
|
+
raise "Invalid emission_factor for AutomobileFuelType #{fuel_type.name}: #{fuel_type.emission_factor} (should be >= 0)"
|
54
|
+
end
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
|
-
|
58
|
+
verify "Emission factor units should never be missing" do
|
59
|
+
AutomobileFuelType.all.each do |fuel_type|
|
60
|
+
if fuel_type.emission_factor_units.nil?
|
61
|
+
raise "Missing emission factor units for AutomobileFuelType #{fuel_type.name}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
43
65
|
end
|
44
66
|
end
|
45
|
-
|
@@ -11,11 +11,11 @@ AutomobileMake.class_eval do
|
|
11
11
|
string 'fuel_efficiency_units'
|
12
12
|
end
|
13
13
|
|
14
|
-
process "Derive
|
15
|
-
|
14
|
+
process "Derive manufacturer names from automobile make fleet years" do
|
15
|
+
AutomobileMakeFleetYear.run_data_miner!
|
16
16
|
connection.execute %{
|
17
17
|
INSERT IGNORE INTO automobile_makes(name)
|
18
|
-
SELECT
|
18
|
+
SELECT DISTINCT automobile_make_fleet_years.make_name FROM automobile_make_fleet_years
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -25,15 +25,31 @@ AutomobileMake.class_eval do
|
|
25
25
|
store 'major'
|
26
26
|
end
|
27
27
|
|
28
|
-
process "Derive average fuel efficiency from automobile
|
29
|
-
|
30
|
-
|
28
|
+
process "Derive average fuel efficiency from automobile make fleet years" do
|
29
|
+
AutomobileMakeFleetYear.run_data_miner!
|
30
|
+
make_fleet_years = AutomobileMakeFleetYear.arel_table
|
31
31
|
makes = AutomobileMake.arel_table
|
32
|
-
conditional_relation = makes[:name].eq(
|
33
|
-
relation =
|
32
|
+
conditional_relation = makes[:name].eq(make_fleet_years[:make_name])
|
33
|
+
relation = AutomobileMakeFleetYear.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume).where(conditional_relation)
|
34
34
|
update_all "fuel_efficiency = (#{relation.to_sql})"
|
35
35
|
update_all "fuel_efficiency_units = 'kilometres_per_litre'"
|
36
36
|
end
|
37
|
+
|
38
|
+
verify "Fuel efficiency should be greater than zero" do
|
39
|
+
AutomobileMake.all.each do |make|
|
40
|
+
unless make.fuel_efficiency > 0
|
41
|
+
raise "Invalid fuel efficiency for AutomobileMake #{make.name}: #{make.fuel_efficiency} (should be > 0)"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
verify "Fuel efficiency units should be kilometres per litre" do
|
47
|
+
AutomobileMake.all.each do |make|
|
48
|
+
unless make.fuel_efficiency_units == "kilometres_per_litre"
|
49
|
+
raise "Invalid fuel efficiency units for AutomobileMake #{make.name}: #{make.fuel_efficiency_units} (should be kilometres_per_litre)"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
@@ -65,4 +81,3 @@ end
|
|
65
81
|
# 'Maybach' => 'Mercedes',
|
66
82
|
# 'Hummer' => 'GM'
|
67
83
|
# }
|
68
|
-
|
@@ -24,6 +24,37 @@ AutomobileMakeFleetYear.class_eval do
|
|
24
24
|
store 'fuel_efficiency', :from_units => :miles_per_gallon, :to_units => :kilometres_per_litre
|
25
25
|
store 'volume'
|
26
26
|
end
|
27
|
+
|
28
|
+
verify "Year should be between 1978 and 2007" do
|
29
|
+
AutomobileMakeFleetYear.all.each do |fleet_year|
|
30
|
+
unless fleet_year.year > 1977 and fleet_year.year < 2008
|
31
|
+
raise "Invalid year for AutomobileMakeFleetYear #{fleet_year.name}: #{fleet_year.year} (should be between 1978 and 2007)"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
verify "Fuel efficiency should be greater than zero" do
|
37
|
+
AutomobileMakeFleetYear.all.each do |fleet_year|
|
38
|
+
unless fleet_year.fuel_efficiency > 0
|
39
|
+
raise "Invalid fuel efficiency for AutomobileMakeFleetYear #{fleet_year.name}: #{fleet_year.fuel_efficiency} (should be > 0)"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
verify "Fuel efficiency units should be kilometres per litre" do
|
45
|
+
AutomobileMakeFleetYear.all.each do |fleet_year|
|
46
|
+
unless fleet_year.fuel_efficiency_units == "kilometres_per_litre"
|
47
|
+
raise "Invalid fuel efficiency units for AutomobileMakeFleetYear #{fleet_year.name}: #{fleet_year.fuel_efficiency_units} (should be kilometres_per_litre)"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
verify "Volume should be greater than zero" do
|
53
|
+
AutomobileMakeFleetYear.all.each do |fleet_year|
|
54
|
+
unless fleet_year.volume > 0
|
55
|
+
raise "Invalid volume for AutomobileMakeFleetYear #{fleet_year.name}: #{fleet_year.volume} (should be > 0)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
27
59
|
end
|
28
60
|
end
|
29
|
-
|
@@ -24,16 +24,38 @@ AutomobileMakeModel.class_eval do
|
|
24
24
|
# TODO not weighted until we get weightings on auto variants
|
25
25
|
process "Derive average fuel economy from automobile make model year variants" do
|
26
26
|
AutomobileMakeModelYearVariant.run_data_miner!
|
27
|
-
|
28
|
-
|
29
|
-
conditional_relation =
|
27
|
+
models = AutomobileMakeModel.arel_table
|
28
|
+
variants = AutomobileMakeModelYearVariant.arel_table
|
29
|
+
conditional_relation = models[:name].eq(variants[:make_model_name])
|
30
30
|
%w{ city highway }.each do |i|
|
31
|
+
null_check = variants[:"fuel_efficiency_#{i}"].not_eq(nil)
|
31
32
|
# sabshere 12/6/10 careful, don't use AutomobileMakeModelYearVariant.where here or you will be forced into projecting *
|
32
|
-
relation =
|
33
|
+
relation = variants.project(variants[:"fuel_efficiency_#{i}"].average).where(conditional_relation).where(null_check)
|
33
34
|
update_all "fuel_efficiency_#{i} = (#{relation.to_sql})"
|
34
35
|
update_all "fuel_efficiency_#{i}_units = 'kilometres_per_litre'"
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
verify "Fuel efficiencies should be greater than zero" do
|
40
|
+
AutomobileMakeModel.all.each do |model|
|
41
|
+
%w{ city highway }.each do |type|
|
42
|
+
fuel_efficiency = model.send(:"fuel_efficiency_#{type}")
|
43
|
+
unless fuel_efficiency > 0
|
44
|
+
raise "Invalid fuel efficiency #{type} for AutomobileMakeModel #{model.name}: #{fuel_efficiency} (should be > 0)"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
verify "Fuel efficiency units should be kilometres per litre" do
|
51
|
+
AutomobileMakeModel.all.each do |model|
|
52
|
+
%w{ city highway }.each do |type|
|
53
|
+
units = model.send(:"fuel_efficiency_#{type}_units")
|
54
|
+
unless units == "kilometres_per_litre"
|
55
|
+
raise "Invalid fuel efficiency #{type} units for AutomobileMakeModel #{model.name}: #{units} (should be kilometres_per_litre)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
37
60
|
end
|
38
61
|
end
|
39
|
-
|
@@ -32,12 +32,13 @@ AutomobileMakeModelYear.class_eval do
|
|
32
32
|
# for example, 20km/l for a toyota prius 2006 vs. 13km/l if you use make years
|
33
33
|
process "Calculate city and highway fuel efficiency from automobile make model year variants" do
|
34
34
|
AutomobileMakeModelYearVariant.run_data_miner!
|
35
|
-
|
36
|
-
|
37
|
-
conditional_relation =
|
35
|
+
model_years = AutomobileMakeModelYear.arel_table
|
36
|
+
variants = AutomobileMakeModelYearVariant.arel_table
|
37
|
+
conditional_relation = model_years[:name].eq(variants[:make_model_year_name])
|
38
38
|
%w{ city highway }.each do |i|
|
39
|
+
null_check = variants[:"fuel_efficiency_#{i}"].not_eq(nil)
|
39
40
|
# sabshere 12/6/10 careful, don't use AutomobileMakeModelYearVariant.where here or you will be forced into projecting *
|
40
|
-
relation =
|
41
|
+
relation = variants.project(variants[:"fuel_efficiency_#{i}"].average).where(conditional_relation).where(null_check)
|
41
42
|
update_all "fuel_efficiency_#{i} = (#{relation.to_sql})"
|
42
43
|
update_all "fuel_efficiency_#{i}_units = 'kilometres_per_litre'"
|
43
44
|
end
|
@@ -47,6 +48,35 @@ AutomobileMakeModelYear.class_eval do
|
|
47
48
|
update_all "fuel_efficiency = 1 / ((0.43 / fuel_efficiency_city) + (0.57 / fuel_efficiency_highway))"
|
48
49
|
update_all "fuel_efficiency_units = 'kilometres_per_litre'"
|
49
50
|
end
|
51
|
+
|
52
|
+
verify "Year should be between 1985 and 2009" do
|
53
|
+
AutomobileMakeModelYear.all.each do |model_year|
|
54
|
+
unless model_year.year > 1984 and model_year.year < 2010
|
55
|
+
raise "Invalid year for AutomobileMakeModelYear #{model_year.name}: #{model_year.year} (should be between 1985 and 2009)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
verify "Fuel efficiencies should be greater than zero" do
|
61
|
+
AutomobileMakeModelYear.all.each do |model_year|
|
62
|
+
%w{ city highway }.each do |type|
|
63
|
+
fuel_efficiency = model_year.send(:"fuel_efficiency_#{type}")
|
64
|
+
unless fuel_efficiency > 0
|
65
|
+
raise "Invalid fuel efficiency #{type} for AutomobileMakeModelYear #{model_year.name}: #{fuel_efficiency} (should be > 0)"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
verify "Fuel efficiency units should be kilometres per litre" do
|
72
|
+
AutomobileMakeModelYear.all.each do |model_year|
|
73
|
+
%w{ city highway }.each do |type|
|
74
|
+
units = model_year.send(:"fuel_efficiency_#{type}_units")
|
75
|
+
unless units == "kilometres_per_litre"
|
76
|
+
raise "Invalid fuel efficiency #{type} units for AutomobileMakeModelYear #{model_year.name}: #{units} (should be kilometres_per_litre)"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
50
81
|
end
|
51
82
|
end
|
52
|
-
|
@@ -9,7 +9,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def is_a_porsche?(row)
|
12
|
-
row['make'].upcase == 'PORSCHE'
|
12
|
+
row['make'] and row['make'].upcase == 'PORSCHE'
|
13
13
|
end
|
14
14
|
|
15
15
|
def is_not_a_porsche?(row)
|
@@ -17,19 +17,19 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def is_a_mercedes_benz?(row)
|
20
|
-
row['make'] =~ /MERCEDES/i
|
20
|
+
row['make'] and row['make'] =~ /MERCEDES/i
|
21
21
|
end
|
22
22
|
|
23
23
|
def is_a_lexus?(row)
|
24
|
-
row['make'].upcase == 'LEXUS'
|
24
|
+
row['make'] and row['make'].upcase == 'LEXUS'
|
25
25
|
end
|
26
26
|
|
27
27
|
def is_a_bmw?(row)
|
28
|
-
row['make'].upcase == 'BMW'
|
28
|
+
row['make'] and row['make'].upcase == 'BMW'
|
29
29
|
end
|
30
30
|
|
31
31
|
def is_a_ford?(row)
|
32
|
-
row['make'].upcase == 'FORD'
|
32
|
+
row['make'] and row['make'].upcase == 'FORD'
|
33
33
|
end
|
34
34
|
|
35
35
|
def is_a_rolls_royce_and_model_contains_bentley?(row)
|
@@ -37,11 +37,11 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def is_a_bentley?(row)
|
40
|
-
row['make'].upcase == 'BENTLEY'
|
40
|
+
row['make'] and row['make'].upcase == 'BENTLEY'
|
41
41
|
end
|
42
42
|
|
43
43
|
def is_a_rolls_royce?(row)
|
44
|
-
row['make'] =~ /ROLLS/i
|
44
|
+
row['make'] and row['make'] =~ /ROLLS/i
|
45
45
|
end
|
46
46
|
|
47
47
|
def is_a_turbo_brooklands?(row)
|
@@ -139,7 +139,9 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
139
139
|
bus[:format] = :fixed_width
|
140
140
|
bus[:cut] = '13-' if year == 1995
|
141
141
|
bus[:schema_name] = :fuel_economy_guide_b
|
142
|
-
bus[:select] = lambda
|
142
|
+
bus[:select] = lambda do |row|
|
143
|
+
(row['suppress_code'].blank? or row['suppress_code'].to_i == 0) and row['state_code'] == 'F'
|
144
|
+
end
|
143
145
|
Slither.define :fuel_economy_guide_b do |d|
|
144
146
|
d.rows do |row|
|
145
147
|
row.trap { true } # there's only one section
|
@@ -309,7 +311,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
309
311
|
index 'make_model_year_name'
|
310
312
|
end
|
311
313
|
|
312
|
-
#
|
314
|
+
# 1985---1997
|
313
315
|
(85..97).each do |yy|
|
314
316
|
filename = (yy == 96) ? "#{yy}MFGUI.ASC" : "#{yy}MFGUI.DAT"
|
315
317
|
import("19#{ yy } Fuel Economy Guide",
|
@@ -410,34 +412,33 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
410
412
|
end
|
411
413
|
|
412
414
|
# 2010--?
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
# end
|
415
|
+
{
|
416
|
+
2010 => { :url => 'http://www.fueleconomy.gov/FEG/epadata/10data.zip', :filename => '2010FE Guide for DOE-all rel dates-no-sales 4-9-10public.xls' }
|
417
|
+
}.sort { |a, b| a.first <=> b.first }.each do |year, options|
|
418
|
+
import "#{ year } Fuel Economy Guide",
|
419
|
+
options.merge(:transform => { :class => AutomobileMakeModelYearVariant::ParserE, :year => year },
|
420
|
+
:errata => 'http://static.brighterplanet.com/science/data/transport/automobiles/fuel_economy_guide/errata.csv') do
|
421
|
+
key 'row_hash'
|
422
|
+
store 'name', :field_name => 'model'
|
423
|
+
store 'make_name', :field_name => 'make'
|
424
|
+
store 'fuel_type_code'
|
425
|
+
store 'fuel_efficiency_highway', :static => nil, :units => :kilometres_per_litre
|
426
|
+
store 'fuel_efficiency_city', :static => nil, :units => :kilometres_per_litre
|
427
|
+
store 'raw_fuel_efficiency_highway', :field_name => 'Hwy Unadj FE - Conventional Fuel', :from_units => :miles_per_gallon, :to_units => :kilometres_per_litre
|
428
|
+
store 'raw_fuel_efficiency_city', :field_name => 'City Unadj FE - Conventional Fuel', :from_units => :miles_per_gallon, :to_units => :kilometres_per_litre
|
429
|
+
store 'cylinders', :field_name => '# Cyl'
|
430
|
+
store 'displacement', :field_name => 'Eng Displ'
|
431
|
+
store 'carline_class_code', :field_name => 'Carline Class'
|
432
|
+
store 'carline_class_name', :field_name => 'Carline Class Desc'
|
433
|
+
store 'year'
|
434
|
+
store 'transmission'
|
435
|
+
store 'speeds'
|
436
|
+
store 'turbo'
|
437
|
+
store 'supercharger'
|
438
|
+
store 'injection'
|
439
|
+
store 'drive'
|
440
|
+
end
|
441
|
+
end
|
441
442
|
|
442
443
|
process "Derive model and model year names" do
|
443
444
|
update_all "make_model_name = CONCAT(make_name, ' ', name)"
|
@@ -450,11 +451,51 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
450
451
|
update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
|
451
452
|
end
|
452
453
|
|
453
|
-
%w{
|
454
|
+
%w{ AutomobileMakeModelYear AutomobileMakeModel }.each do |synthetic_resource|
|
454
455
|
process "Synthesize #{synthetic_resource}" do
|
455
456
|
synthetic_resource.constantize.run_data_miner!
|
456
457
|
end
|
457
458
|
end
|
459
|
+
|
460
|
+
verify "Year should be between 1985 and 2009" do
|
461
|
+
AutomobileMakeModelYearVariant.all.each do |variant|
|
462
|
+
unless variant.year > 1984 and variant.year < 2010
|
463
|
+
raise "Invalid year for AutomobileMakeModelYearVariant #{variant.row_hash}: #{variant.year} (should be between 1985 and 2009)"
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
# FIXME TODO
|
469
|
+
# verify "Fuel type code should be found in AutomobileFuelType" do
|
470
|
+
# valid_codes = AutomobileFuelType.all.map(&:code)
|
471
|
+
# puts valid_codes
|
472
|
+
# AutomobileMakeModelVariant.all.each do |variant|
|
473
|
+
# unless valid_codes.include? variant.fuel_type_code
|
474
|
+
# raise "Invalid fuel type code for AutomobileMakeModelYearVariant #{variant.row_hash}: #{variant.fuel_type_code} (should be found in AutomobileFuelType)"
|
475
|
+
# end
|
476
|
+
# end
|
477
|
+
# end
|
478
|
+
#
|
479
|
+
verify "Fuel efficiencies should be greater than zero" do
|
480
|
+
AutomobileMakeModelYearVariant.all.each do |variant|
|
481
|
+
%w{ city highway }.each do |type|
|
482
|
+
fuel_efficiency = variant.send(:"fuel_efficiency_#{type}")
|
483
|
+
unless fuel_efficiency > 0
|
484
|
+
raise "Invalid fuel efficiency #{type} for AutomobileMakeModelYearVariant #{variant.row_hash}: #{fuel_efficiency} (should be < 0)"
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
verify "Fuel efficiency units should be kilometres per litre" do
|
491
|
+
AutomobileMakeModelYearVariant.all.each do |variant|
|
492
|
+
%w{ city highway }.each do |type|
|
493
|
+
units = variant.send(:"fuel_efficiency_#{type}_units")
|
494
|
+
unless units == "kilometres_per_litre"
|
495
|
+
raise "Invalid fuel efficiency #{type} units for AutomobileMakeModelYearVariant #{variant.row_hash}: #{units} (should be kilometres_per_litre)"
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
458
500
|
end
|
459
501
|
end
|
460
|
-
|