earth 0.11.20 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/data/automobile/annual_emission_controls.csv +143 -0
- data/data/automobile/annual_fuel_consumption.csv +81 -0
- data/data/automobile/annual_sizes.csv +541 -0
- data/data/automobile/auto_fuel_data.csv +13 -0
- data/data/automobile/auto_fuel_efs.csv +9 -0
- data/data/automobile/cafe_data.csv +1449 -0
- data/data/automobile/emission_control_techs.csv +21 -0
- data/data/automobile/hfc_emissions.csv +31 -0
- data/data/automobile/hybridity_multipliers.csv +8 -0
- data/data/automobile/sizes.csv +16 -0
- data/earth.gemspec +3 -2
- data/errata/aircraft/faa_errata.csv +1 -1
- data/errata/airline/bts_carrier_codes_errata.csv +44 -0
- data/errata/airport/openflights_errata.csv +450 -1
- data/errata/automobile_make_model_year_variant/feg_errata.csv +363 -1
- data/errata/automobile_make_year_fleet/cafe_errata.csv +69 -1
- data/errata/bts_aircraft/bts_errata.csv +1 -1
- data/errata/country/wri_errata.csv +1 -1
- data/errata/electricity/electric_market/nrel_errata.csv +13 -1
- data/errata/electricity/electric_utility/eia_errata.csv +18 -1
- data/errata/flight_segment/bts_errata.csv +4 -1
- data/lib/earth.rb +1 -0
- data/lib/earth/acronyms.rb +12 -0
- data/lib/earth/air/aircraft.rb +16 -0
- data/lib/earth/air/airline.rb +3 -0
- data/lib/earth/air/airline/data_miner.rb +18 -3
- data/lib/earth/air/airport.rb +2 -0
- data/lib/earth/air/bts_aircraft.rb +2 -0
- data/lib/earth/air/flight_distance_class.rb +2 -0
- data/lib/earth/air/flight_distance_class_seat_class.rb +2 -0
- data/lib/earth/air/flight_seat_class.rb +2 -0
- data/lib/earth/air/flight_segment.rb +10 -0
- data/lib/earth/air/flight_segment/data_miner.rb +10 -13
- data/lib/earth/automobile/automobile_activity_year.rb +21 -0
- data/lib/earth/automobile/automobile_activity_year/data_miner.rb +27 -0
- data/lib/earth/automobile/automobile_activity_year_type.rb +27 -0
- data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +27 -0
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +19 -0
- data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +57 -0
- data/lib/earth/automobile/automobile_fuel.rb +93 -86
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +64 -70
- data/lib/earth/automobile/automobile_make.rb +5 -1
- data/lib/earth/automobile/automobile_make/data_miner.rb +10 -37
- data/lib/earth/automobile/automobile_make_model.rb +22 -3
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +41 -15
- data/lib/earth/automobile/automobile_make_model_year.rb +18 -7
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +43 -27
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +44 -8
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +182 -8
- data/lib/earth/automobile/automobile_make_year.rb +4 -2
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +16 -15
- data/lib/earth/automobile/automobile_make_year_fleet.rb +2 -1
- data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +5 -2
- data/lib/earth/automobile/automobile_model.rb +2 -1
- data/lib/earth/automobile/automobile_model/data_miner.rb +1 -2
- data/lib/earth/automobile/automobile_size_class.rb +7 -68
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +16 -51
- data/lib/earth/automobile/automobile_type_fuel.rb +23 -0
- data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +52 -0
- data/lib/earth/automobile/automobile_type_fuel_control.rb +2 -33
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +19 -4
- data/lib/earth/automobile/automobile_type_fuel_year.rb +17 -54
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +40 -94
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +25 -23
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +6 -2
- data/lib/earth/automobile/automobile_year.rb +38 -1
- data/lib/earth/automobile/automobile_year/data_miner.rb +1 -2
- data/lib/earth/automobile/dependencies.txt +22 -36
- data/lib/earth/bus/bus_class.rb +2 -0
- data/lib/earth/bus/bus_fuel.rb +2 -0
- data/lib/earth/bus/bus_fuel_control.rb +2 -0
- data/lib/earth/bus/bus_fuel_year_control.rb +2 -0
- data/lib/earth/computation/computation_carrier.rb +2 -0
- data/lib/earth/computation/computation_carrier_instance_class.rb +2 -0
- data/lib/earth/computation/computation_carrier_region.rb +2 -0
- data/lib/earth/conversions_ext.rb +6 -0
- data/lib/earth/diet/diet_class.rb +2 -0
- data/lib/earth/diet/food_group.rb +2 -0
- data/lib/earth/fuel/fuel.rb +2 -0
- data/lib/earth/fuel/fuel/data_miner.rb +15 -0
- data/lib/earth/fuel/fuel_price.rb +2 -0
- data/lib/earth/fuel/fuel_type.rb +2 -0
- data/lib/earth/fuel/fuel_year.rb +2 -0
- data/lib/earth/fuel/greenhouse_gas.rb +2 -0
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +7 -7
- data/lib/earth/hospitality/lodging_class.rb +2 -0
- data/lib/earth/industry/industry.rb +2 -0
- data/lib/earth/industry/mecs_energy/data_miner.rb +1 -1
- data/lib/earth/industry/mecs_ratio/data_miner.rb +1 -1
- data/lib/earth/locality/census_division.rb +2 -0
- data/lib/earth/locality/census_region.rb +2 -0
- data/lib/earth/locality/climate_division.rb +2 -0
- data/lib/earth/locality/country.rb +4 -0
- data/lib/earth/locality/egrid_region.rb +3 -0
- data/lib/earth/locality/egrid_subregion.rb +2 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +7 -0
- data/lib/earth/locality/state.rb +7 -0
- data/lib/earth/locality/zip_code.rb +4 -0
- data/lib/earth/pet/breed.rb +7 -0
- data/lib/earth/pet/breed/data_miner.rb +1 -1
- data/lib/earth/pet/breed_gender.rb +2 -0
- data/lib/earth/pet/gender.rb +2 -0
- data/lib/earth/pet/species.rb +2 -0
- data/lib/earth/rail/country_rail_class.rb +2 -0
- data/lib/earth/rail/country_rail_traction.rb +2 -0
- data/lib/earth/rail/country_rail_traction_class.rb +2 -0
- data/lib/earth/rail/national_transit_database_company.rb +7 -0
- data/lib/earth/rail/national_transit_database_mode.rb +2 -0
- data/lib/earth/rail/national_transit_database_record.rb +22 -0
- data/lib/earth/rail/rail_class.rb +2 -0
- data/lib/earth/rail/rail_company.rb +16 -0
- data/lib/earth/rail/rail_fuel.rb +2 -0
- data/lib/earth/rail/rail_traction.rb +2 -0
- data/lib/earth/residence/air_conditioner_use.rb +2 -0
- data/lib/earth/residence/clothes_machine_use.rb +2 -0
- data/lib/earth/residence/dishwasher_use.rb +2 -0
- data/lib/earth/residence/residence_appliance.rb +2 -0
- data/lib/earth/residence/residence_class.rb +2 -0
- data/lib/earth/residence/residence_fuel_price.rb +2 -0
- data/lib/earth/residence/residence_fuel_type.rb +2 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +2 -0
- data/lib/earth/residence/urbanity.rb +2 -0
- data/lib/earth/shipping/carrier.rb +2 -0
- data/lib/earth/shipping/carrier_mode.rb +2 -0
- data/lib/earth/shipping/shipment_mode.rb +2 -0
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/airline_spec.rb +20 -0
- data/spec/earth/air/flight_segment_spec.rb +9 -4
- data/spec/earth/automobile/automobile_activity_year_spec.rb +30 -0
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +25 -0
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +38 -0
- data/spec/earth/automobile/automobile_fuel_spec.rb +91 -6
- data/spec/earth/automobile/automobile_make_model_spec.rb +74 -0
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +90 -0
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +139 -90
- data/spec/earth/automobile/automobile_make_spec.rb +27 -0
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +8 -21
- data/spec/earth/automobile/automobile_make_year_spec.rb +28 -0
- data/spec/earth/automobile/automobile_model_spec.rb +15 -0
- data/spec/earth/automobile/automobile_size_class_spec.rb +31 -0
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +25 -0
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +45 -0
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +51 -0
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +65 -0
- data/spec/earth/automobile/automobile_year_spec.rb +23 -0
- data/spec/earth/fuel/fuel_spec.rb +1 -1
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +11 -3
- data/spec/earth_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +78 -25
- data/lib/earth/automobile/automobile_size_class_year.rb +0 -44
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -18
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +0 -68
- data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -116
- data/lib/earth/automobile/automobile_type_year.rb +0 -58
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -30
- data/spec/earth/automobile/automobile_type_fuel_year_age_spec.rb +0 -20
@@ -11,31 +11,67 @@ class AutomobileMakeModelYearVariant < ActiveRecord::Base
|
|
11
11
|
col :row_hash
|
12
12
|
col :make_name
|
13
13
|
col :model_name
|
14
|
-
col :year,
|
14
|
+
col :year, :type => :integer
|
15
15
|
col :transmission
|
16
16
|
col :speeds
|
17
17
|
col :drive
|
18
18
|
col :fuel_code
|
19
|
-
col :fuel_efficiency,
|
19
|
+
col :fuel_efficiency, :type => :float
|
20
20
|
col :fuel_efficiency_units
|
21
|
-
col :fuel_efficiency_city,
|
21
|
+
col :fuel_efficiency_city, :type => :float
|
22
22
|
col :fuel_efficiency_city_units
|
23
|
-
col :fuel_efficiency_highway,
|
23
|
+
col :fuel_efficiency_highway, :type => :float
|
24
24
|
col :fuel_efficiency_highway_units
|
25
25
|
col :alt_fuel_code
|
26
|
-
col :alt_fuel_efficiency,
|
26
|
+
col :alt_fuel_efficiency, :type => :float
|
27
27
|
col :alt_fuel_efficiency_units
|
28
|
-
col :alt_fuel_efficiency_city,
|
28
|
+
col :alt_fuel_efficiency_city, :type => :float
|
29
29
|
col :alt_fuel_efficiency_city_units
|
30
|
-
col :alt_fuel_efficiency_highway,
|
30
|
+
col :alt_fuel_efficiency_highway, :type => :float
|
31
31
|
col :alt_fuel_efficiency_highway_units
|
32
32
|
col :cylinders, :type => :integer
|
33
33
|
col :displacement, :type => :float
|
34
34
|
col :turbo, :type => :boolean
|
35
35
|
col :supercharger, :type => :boolean
|
36
36
|
col :injection, :type => :boolean
|
37
|
-
col :
|
37
|
+
col :size_class
|
38
|
+
col :type_name
|
38
39
|
add_index :make_name
|
39
40
|
add_index :model_name
|
40
41
|
add_index :year
|
42
|
+
|
43
|
+
warn_unless_size 28433
|
44
|
+
warn_unless_size 1152, :conditions => { :year => 1985 }
|
45
|
+
warn_unless_size 1183, :conditions => { :year => 1986 }
|
46
|
+
warn_unless_size 1206, :conditions => { :year => 1987 }
|
47
|
+
warn_unless_size 1104, :conditions => { :year => 1988 }
|
48
|
+
warn_unless_size 1137, :conditions => { :year => 1989 }
|
49
|
+
warn_unless_size 1049, :conditions => { :year => 1990 }
|
50
|
+
warn_unless_size 1062, :conditions => { :year => 1991 }
|
51
|
+
warn_unless_size 1055, :conditions => { :year => 1992 }
|
52
|
+
warn_unless_size 986, :conditions => { :year => 1993 }
|
53
|
+
warn_unless_size 963, :conditions => { :year => 1994 }
|
54
|
+
warn_unless_size 917, :conditions => { :year => 1995 }
|
55
|
+
warn_unless_size 750, :conditions => { :year => 1996 }
|
56
|
+
warn_unless_size 727, :conditions => { :year => 1997 }
|
57
|
+
warn_unless_size 794, :conditions => { :year => 1998 }
|
58
|
+
warn_unless_size 800, :conditions => { :year => 1999 }
|
59
|
+
warn_unless_size 834, :conditions => { :year => 2000 }
|
60
|
+
warn_unless_size 846, :conditions => { :year => 2001 }
|
61
|
+
warn_unless_size 933, :conditions => { :year => 2002 }
|
62
|
+
warn_unless_size 995, :conditions => { :year => 2003 }
|
63
|
+
warn_unless_size 1091, :conditions => { :year => 2004 }
|
64
|
+
warn_unless_size 1069, :conditions => { :year => 2005 }
|
65
|
+
warn_unless_size 1043, :conditions => { :year => 2006 }
|
66
|
+
warn_unless_size 1126, :conditions => { :year => 2007 }
|
67
|
+
warn_unless_size 1186, :conditions => { :year => 2008 }
|
68
|
+
warn_unless_size 1092, :conditions => { :year => 2009 }
|
69
|
+
warn_unless_size 1107, :conditions => { :year => 2010 }
|
70
|
+
warn_unless_size 1097, :conditions => { :year => 2011 }
|
71
|
+
warn_unless_size 1129, :conditions => { :year => 2012 }
|
72
|
+
warn_if_nulls_except(
|
73
|
+
:alt_fuel_code,
|
74
|
+
:cylinders
|
75
|
+
)
|
76
|
+
warn_if_nulls /alt_fuel_efficiency/, :conditions => 'alt_fuel_code IS NOT NULL'
|
41
77
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
AutomobileMakeModelYearVariant.class_eval do
|
2
2
|
# For errata
|
3
3
|
class AutomobileMakeModelYearVariant::Guru
|
4
|
-
%w{ alpina bentley chevrolet dodge ferrari ford jaguar kia lexus maybach mercedes-benz mitsubishi porsche toyota tvr volvo yugo }.each do |make|
|
4
|
+
%w{ alpina bentley chevrolet chrysler dodge ferrari ford gmc jaguar kia lexus maybach mercedes-benz mitsubishi porsche toyota tvr volvo yugo }.each do |make|
|
5
5
|
method_name = :"is_a_#{make.gsub('-', '_')}?"
|
6
6
|
define_method method_name do |row|
|
7
7
|
row['make_name'].downcase == make
|
@@ -37,6 +37,46 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
37
37
|
def is_a_2005_mercedes_benz_slk55_amg?(row)
|
38
38
|
row['make_name'].downcase == 'mercedes-benz' and row['model_name'].downcase == 'slk55 amg' and row['year'] == 2005
|
39
39
|
end
|
40
|
+
|
41
|
+
def is_a_1995_ffv?(row)
|
42
|
+
row['year'] == 1995 and row['model_name'] =~ / ffv$/i
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_a_1999_ffv?(row)
|
46
|
+
row['year'] == 1999 and row['model_name'] =~ / ffv$/i
|
47
|
+
end
|
48
|
+
|
49
|
+
def is_a_2000_ford_4wd_ffv?(row)
|
50
|
+
row['year'] == 2000 and row['make_name'].downcase == 'ford' and row['drive'] == '4WD' and row['model_name'] =~ / ffv$/i
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_2000_b3000_5_spd_4wd_ethanol_ucity_19?(row)
|
54
|
+
row['year'] == 2000 and
|
55
|
+
row['model_name'] =~ /b3000 ffv/i and
|
56
|
+
row['speeds'] == '5' and
|
57
|
+
row['drive'] == '4WD' and
|
58
|
+
row['fuel_code'] == 'E' and
|
59
|
+
row['ucty'].to_i == 19
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_a_station_wagon?(row)
|
63
|
+
row['size_class'] =~ /station wagons/i
|
64
|
+
end
|
65
|
+
|
66
|
+
%w{ 5 hatchback justy loyale loyale_wagon odyssey pt_cruiser_convertible space_wagon stanza_wagon wagon xt }.each do |model_name|
|
67
|
+
method_name = :"is_a_#{model_name}?"
|
68
|
+
define_method method_name do |row|
|
69
|
+
row['model_name'] =~ /^#{model_name.gsub('_', ' ')}$/i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_a_colt_vista_or_wagon?(row)
|
74
|
+
row['model_name'] =~ /^colt [vw].+$/i
|
75
|
+
end
|
76
|
+
|
77
|
+
def is_a_subaru_sedan?(row)
|
78
|
+
row['make_name'] =~ /subaru/i and row['model_name'] =~ /^sedan(\/.+)?$/i
|
79
|
+
end
|
40
80
|
end
|
41
81
|
|
42
82
|
# To parse the FEG files
|
@@ -101,6 +141,28 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
101
141
|
'PE' => 'EL' # plug-in electric
|
102
142
|
}
|
103
143
|
|
144
|
+
CLASS_CODES = {
|
145
|
+
'1' => 'Two seaters',
|
146
|
+
'2' => 'Minicompact cars',
|
147
|
+
'3' => 'Subcompact cars',
|
148
|
+
'4' => 'Compact cars',
|
149
|
+
'5' => 'Midsize cars',
|
150
|
+
'6' => 'Large cars',
|
151
|
+
'7' => 'Small station wagons',
|
152
|
+
'8' => 'Midsize station wagons',
|
153
|
+
'9' => 'Large station wagons',
|
154
|
+
'10' => 'Small pickup trucks 2WD',
|
155
|
+
'11' => 'Small pickup trucks 4WD',
|
156
|
+
'12' => 'Standard pickup trucks 2WD',
|
157
|
+
'13' => 'Standard pickup trucks 4WD',
|
158
|
+
'14' => 'Cargo vans',
|
159
|
+
'15' => 'Passenger vans',
|
160
|
+
'16' => nil,
|
161
|
+
'17' => 'Special purpose vehicles 2WD',
|
162
|
+
'18' => 'Special purpose vehicles 4WD',
|
163
|
+
'19' => 'Special purpose vehicles'
|
164
|
+
}
|
165
|
+
|
104
166
|
def initialize(options = {})
|
105
167
|
options = options.stringify_keys
|
106
168
|
@year = options['year']
|
@@ -119,7 +181,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
119
181
|
'model_name' => row['carline_name'],
|
120
182
|
'year' => year,
|
121
183
|
'transmission' => TRANSMISSIONS[row['model_trans'][0,1].to_s],
|
122
|
-
'speeds' => row['model_trans'][1,1] == 'V' ? 'variable' : row['model_trans'][1,1],
|
184
|
+
'speeds' => (row['model_trans'][1,1] == 'V') ? 'variable' : row['model_trans'][1,1],
|
123
185
|
'drive' => row['drive_system'],
|
124
186
|
'fuel_code' => row['fuel_type'],
|
125
187
|
'fuel_efficiency_city' => 1.0 / (0.003259 + (1.1805 / row['unadj_city_mpg'].to_f)), # adjust for real-world driving
|
@@ -128,7 +190,8 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
128
190
|
'displacement' => _displacement(row),
|
129
191
|
'turbo' => _turbo(row),
|
130
192
|
'supercharger' => [ENGINE_TYPES[row['engine_desc1'].to_s], ENGINE_TYPES[row['engine_desc2'].to_s]].flatten.include?('supercharger'),
|
131
|
-
'injection' => row['fuel_system'] == 'FI' ? true : false
|
193
|
+
'injection' => (row['fuel_system'] == 'FI') ? true : false,
|
194
|
+
'size_class' => CLASS_CODES[row['size_class']]
|
132
195
|
})
|
133
196
|
when (1998..2009)
|
134
197
|
row.merge!({
|
@@ -146,7 +209,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
146
209
|
'turbo' => ((row['T'] || row['TURBO']) == 'T' || (row['carline name'] || row['CAR LINE']).downcase.include?('turbo')) ? true : false,
|
147
210
|
'supercharger' => (row['S'] || row['SPCHGR']) == 'S',
|
148
211
|
'injection' => true,
|
149
|
-
'
|
212
|
+
'size_class' => row['Class'] || row['CLASS']
|
150
213
|
})
|
151
214
|
else # 2010..present
|
152
215
|
row.merge!({
|
@@ -167,7 +230,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
167
230
|
'turbo' => row['Air Aspir Method'] == 'TC',
|
168
231
|
'supercharger' => row['Air Aspir Method'] == 'SC',
|
169
232
|
'injection' => row['# Cyl'].present? ? true : false,
|
170
|
-
'
|
233
|
+
'size_class' => row['Carline Class Desc']
|
171
234
|
})
|
172
235
|
end
|
173
236
|
end
|
@@ -195,7 +258,7 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
195
258
|
row.trap { true } # there's only one section
|
196
259
|
row.column 'active_year', 4, :type => :integer # ACTIVE YEAR
|
197
260
|
row.column 'state_code', 1, :type => :string # STATE CODE: F=49-STATE,C=CALIFORNIA
|
198
|
-
row.column '
|
261
|
+
row.column 'size_class', 2, :type => :integer # CARLINE CLASS CODE
|
199
262
|
row.column 'carline_mfr_code', 3, :type => :integer # CARLINE MANUFACTURER CODE
|
200
263
|
row.column 'carline_name', 28, :type => :string # CARLINE NAME
|
201
264
|
row.column 'disp_cub_in', 4, :type => :integer # DISP CUBIC INCHES
|
@@ -283,6 +346,10 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
283
346
|
end
|
284
347
|
|
285
348
|
fuel_economy_guides.each do |year, options|
|
349
|
+
process "Clear old data from #{year}" do
|
350
|
+
where(:year => year).delete_all
|
351
|
+
end
|
352
|
+
|
286
353
|
import "#{year} Fuel Economy Guide", options do
|
287
354
|
key 'row_hash'
|
288
355
|
store 'make_name'
|
@@ -302,11 +369,103 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
302
369
|
store 'turbo'
|
303
370
|
store 'supercharger'
|
304
371
|
store 'injection'
|
305
|
-
store '
|
372
|
+
store 'size_class'
|
306
373
|
end
|
307
374
|
end
|
308
375
|
|
309
|
-
#
|
376
|
+
# FIXME TODO hybrids listed on FEG website but not in downloadable files
|
377
|
+
# 2001 Honda Insight (automatic, variable transmission) - listed twice on FEG website
|
378
|
+
# 2003 Honda Civic Hybrid (manual, 5-speed, lower mpg)
|
379
|
+
# 2003 Honda Civic Hybrid (automatic, variable transmission, higher mpg)
|
380
|
+
# 2005 Honda Accord Hybrid
|
381
|
+
# 2006 Honda Accord Hybrid
|
382
|
+
# 2009 Chrysler Aspen HEV
|
383
|
+
# 2009 Dodge Durango HEV
|
384
|
+
# 2009 Saturn Vue Hybrid (automatic, variable transmission)
|
385
|
+
process "Update the model names of certain hybrid variants" do
|
386
|
+
hybrids = []
|
387
|
+
if where(:make_name => 'Buick', :model_name => 'LACROSSE HYBRID', :year => 2012).none? and where(:make_name => 'Buick', :model_name => 'LACROSSE', :year => 2012, :alt_fuel_code => nil).any?
|
388
|
+
hybrids << where(:make_name => 'Buick', :model_name => 'LACROSSE', :year => 2012, :alt_fuel_code => nil).first
|
389
|
+
end
|
390
|
+
if where(:make_name => 'Buick', :model_name => 'REGAL HYBRID', :year => 2012).none? and where(:make_name => 'Buick', :model_name => 'REGAL', :year => 2012, :alt_fuel_code => nil).any?
|
391
|
+
hybrids << where(:make_name => 'Buick', :model_name => 'REGAL', :year => 2012, :alt_fuel_code => nil).sort_by!(&:fuel_efficiency_city).last
|
392
|
+
end
|
393
|
+
hybrids.each do |hybrid|
|
394
|
+
hybrid.model_name += ' HYBRID'
|
395
|
+
hybrid.save!
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
process "Merge rows for dual-fuel Chevy Cavaliers (these are listed once for each fuel type)" do
|
400
|
+
where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'C').each do |cng_variant|
|
401
|
+
gasoline_variant = where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => ['R', 'P'], :alt_fuel_code => nil).find_by_year(cng_variant.year)
|
402
|
+
%w{ fuel_code fuel_efficiency_city fuel_efficiency_city_units fuel_efficiency_highway fuel_efficiency_highway_units }.each do |attribute|
|
403
|
+
gasoline_variant.send("alt_#{attribute}=", cng_variant.send(attribute))
|
404
|
+
end
|
405
|
+
gasoline_variant.save!
|
406
|
+
cng_variant.destroy
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
process "Update model name to indicate CNG variants" do
|
411
|
+
where("fuel_code = 'C' AND model_name NOT LIKE '% CNG'").update_all "model_name = model_name || ' CNG'"
|
412
|
+
end
|
413
|
+
|
414
|
+
process "Merge rows for flex-fuel vehicles (these are listed once for each fuel type)" do
|
415
|
+
where(:fuel_code => 'E').each do |ethanol_variant|
|
416
|
+
gasoline_variant = where(%{
|
417
|
+
(fuel_code = 'R' OR fuel_code = 'P')
|
418
|
+
AND alt_fuel_code IS NULL
|
419
|
+
AND make_name = ?
|
420
|
+
AND model_name = ?
|
421
|
+
AND year = ?
|
422
|
+
AND transmission = ?
|
423
|
+
AND speeds = ?
|
424
|
+
AND drive = ?
|
425
|
+
AND cylinders = ?
|
426
|
+
AND displacement < ?
|
427
|
+
AND displacement > ?
|
428
|
+
},
|
429
|
+
ethanol_variant.make_name,
|
430
|
+
ethanol_variant.model_name,
|
431
|
+
ethanol_variant.year,
|
432
|
+
ethanol_variant.transmission,
|
433
|
+
ethanol_variant.speeds,
|
434
|
+
ethanol_variant.drive,
|
435
|
+
ethanol_variant.cylinders,
|
436
|
+
(ethanol_variant.displacement + 0.01),
|
437
|
+
(ethanol_variant.displacement - 0.01)
|
438
|
+
).first
|
439
|
+
|
440
|
+
if gasoline_variant.present?
|
441
|
+
%w{ fuel_code fuel_efficiency_city fuel_efficiency_city_units fuel_efficiency_highway fuel_efficiency_highway_units }.each do |attribute|
|
442
|
+
gasoline_variant.send("alt_#{attribute}=", ethanol_variant.send(attribute))
|
443
|
+
end
|
444
|
+
gasoline_variant.save!
|
445
|
+
ethanol_variant.destroy
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
process "Update model name to indicate flex-fuel variants of models where variants in some years are not flex-fuel" do
|
451
|
+
where("alt_fuel_code = 'E' AND model_name NOT LIKE '% FFV'").each do |variant|
|
452
|
+
if where(:make_name => variant.make_name, :model_name => variant.model_name, :alt_fuel_code => nil).any?
|
453
|
+
variant.model_name += ' FFV'
|
454
|
+
variant.save!
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
process "Update model name to indicate diesel variants of models where variants in some years are not diesel" do
|
460
|
+
where("fuel_code = 'D' AND model_name NOT LIKE '% DIESEL'").each do |variant|
|
461
|
+
if where("make_name = ? AND model_name = ? AND fuel_code != 'D'", variant.make_name, variant.model_name).any?
|
462
|
+
variant.model_name += ' DIESEL'
|
463
|
+
variant.save!
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
# Combined fuel efficiency will be useful for deriving fuel efficiency for other classes
|
310
469
|
# NOTE: we use a 43/57 city/highway weighting per the latest EPA analysis of real-world driving behavior
|
311
470
|
# This results in a deviation from EPA fuel economy label values which use a historical 55/45 weighting
|
312
471
|
process "Calculate combined adjusted fuel efficiency using the latest EPA equation" do
|
@@ -319,5 +478,20 @@ AutomobileMakeModelYearVariant.class_eval do
|
|
319
478
|
alt_fuel_efficiency_units = 'kilometres_per_litre'
|
320
479
|
})
|
321
480
|
end
|
481
|
+
|
482
|
+
process "Derive type name from size class" do
|
483
|
+
where(:size_class => [
|
484
|
+
'Two seaters',
|
485
|
+
'Minicompact cars',
|
486
|
+
'Subcompact cars',
|
487
|
+
'Compact cars',
|
488
|
+
'Midsize cars',
|
489
|
+
'Large cars',
|
490
|
+
'Small station wagons',
|
491
|
+
'Midsize station wagons',
|
492
|
+
'Large station wagons'
|
493
|
+
]).update_all "type_name = 'Passenger cars'"
|
494
|
+
where(:type_name => nil).update_all "type_name = 'Light-duty trucks'"
|
495
|
+
end
|
322
496
|
end
|
323
497
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'earth/fuel'
|
2
1
|
class AutomobileMakeYear < ActiveRecord::Base
|
3
2
|
self.primary_key = "name"
|
4
3
|
|
@@ -7,5 +6,8 @@ class AutomobileMakeYear < ActiveRecord::Base
|
|
7
6
|
col :year, :type => :integer
|
8
7
|
col :fuel_efficiency, :type => :float
|
9
8
|
col :fuel_efficiency_units
|
10
|
-
col :
|
9
|
+
col :weighting, :type => :float # for calculating AutomobileMake fuel efficiences
|
10
|
+
|
11
|
+
warn_unless_size 1276
|
12
|
+
warn_if_any_nulls
|
11
13
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'earth/fuel/data_miner'
|
2
1
|
AutomobileMakeYear.class_eval do
|
3
2
|
data_miner do
|
4
3
|
process "Start from scratch" do
|
@@ -10,7 +9,7 @@ AutomobileMakeYear.class_eval do
|
|
10
9
|
AutomobileMakeYearFleet.run_data_miner!
|
11
10
|
end
|
12
11
|
|
13
|
-
process "Derive manufacturer names and years from
|
12
|
+
process "Derive manufacturer names and years from AutomobileMakeModelYearVariant" do
|
14
13
|
::Earth::Utils.insert_ignore(
|
15
14
|
:src => AutomobileMakeModelYearVariant,
|
16
15
|
:dest => AutomobileMakeYear,
|
@@ -22,28 +21,30 @@ AutomobileMakeYear.class_eval do
|
|
22
21
|
)
|
23
22
|
end
|
24
23
|
|
25
|
-
process "Calculate fuel efficiency and sales volume from
|
24
|
+
process "Calculate fuel efficiency and sales volume from AutomobileMakeYearFleet for makes with CAFE data" do
|
26
25
|
make_years = arel_table
|
27
26
|
year_fleets = AutomobileMakeYearFleet.arel_table
|
28
|
-
|
29
|
-
fuel_efficiency_relation = AutomobileMakeYearFleet.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume)
|
30
|
-
|
31
|
-
update_all
|
32
|
-
fuel_efficiency = (#{fuel_efficiency_relation.to_sql}),
|
33
|
-
fuel_efficiency_units = 'kilometres_per_litre',
|
34
|
-
volume = (#{volume_relation.to_sql})
|
35
|
-
})
|
27
|
+
join_relation = make_years[:make_name].eq(year_fleets[:make_name]).and(make_years[:year].eq(year_fleets[:year]))
|
28
|
+
fuel_efficiency_relation = AutomobileMakeYearFleet.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume)
|
29
|
+
update_all("fuel_efficiency = (#{fuel_efficiency_relation.where(join_relation).to_sql})")
|
30
|
+
where("fuel_efficiency IS NOT NULL").update_all "fuel_efficiency_units = 'kilometres_per_litre'"
|
36
31
|
end
|
37
32
|
|
38
|
-
process "Calculate fuel effeciency from
|
33
|
+
process "Calculate fuel effeciency from AutomobileMakeModelYearVariant for makes without CAFE data" do
|
39
34
|
make_years = arel_table
|
40
35
|
variants = AutomobileMakeModelYearVariant.arel_table
|
41
|
-
|
42
|
-
|
36
|
+
join_relation = make_years[:make_name].eq(variants[:make_name]).and(make_years[:year].eq(variants[:year]))
|
37
|
+
fuel_efficiency_relation = variants.project(variants[:fuel_efficiency].average)
|
43
38
|
where(:fuel_efficiency => nil).update_all(%{
|
44
|
-
fuel_efficiency = (#{
|
39
|
+
fuel_efficiency = (#{fuel_efficiency_relation.where(join_relation).to_sql}),
|
45
40
|
fuel_efficiency_units = 'kilometres_per_litre'
|
46
41
|
})
|
47
42
|
end
|
43
|
+
|
44
|
+
process "Derive weighting from AutomobileYear" do
|
45
|
+
connection.select_values("SELECT DISTINCT year FROM #{quoted_table_name}").each do |year|
|
46
|
+
where(:year => year).update_all "weighting = #{AutomobileYear.weighting(year)}"
|
47
|
+
end
|
48
|
+
end
|
48
49
|
end
|
49
50
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'earth/fuel'
|
2
1
|
class AutomobileMakeYearFleet < ActiveRecord::Base
|
3
2
|
self.primary_key = "name"
|
4
3
|
|
@@ -9,4 +8,6 @@ class AutomobileMakeYearFleet < ActiveRecord::Base
|
|
9
8
|
col :fuel_efficiency, :type => :float
|
10
9
|
col :fuel_efficiency_units
|
11
10
|
col :volume, :type => :integer
|
11
|
+
|
12
|
+
warn_unless_size 1349
|
12
13
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require 'earth/fuel/data_miner'
|
2
1
|
AutomobileMakeYearFleet.class_eval do
|
3
2
|
data_miner do
|
3
|
+
process "Start from scratch" do
|
4
|
+
delete_all
|
5
|
+
end
|
6
|
+
|
4
7
|
import "annual corporate average fuel economy data for domestic and imported vehicle fleets from the NHTSA",
|
5
|
-
:url =>
|
8
|
+
:url => "file://#{Earth::DATA_DIR}/automobile/cafe_data.csv",
|
6
9
|
:errata => { :url => "file://#{Earth::ERRATA_DIR}/automobile_make_year_fleet/cafe_errata.csv", :encoding => 'ISO-8859-1' },
|
7
10
|
:select => proc { |row| row['volume'].to_i > 0 } do
|
8
11
|
key 'name', :synthesize => proc { |row| [ row['manufacturer_name'], row['year_content'], row['fleet'][2,2] ].join ' ' }
|