Class: AutomobileMakeModelYearVariant::Parser
- Inherits:
-
Object
- Object
- AutomobileMakeModelYearVariant::Parser
- Defined in:
- lib/earth/automobile/automobile_make_model_year_variant/parser.rb
Overview
To parse the FEG files
Constant Summary collapse
- TRANSMISSIONS =
{ 'A' => 'Automatic', 'L' => 'Automatic', 'M' => 'Manual', 'S' => 'Semi-Automatic', 'C' => 'Continuously Variable', 'AM' => 'Automated Manual', 'SA' => 'Semi-Automatic', 'CVT' => 'Continuously Variable', 'SCV' => 'Selectable Continuously Variable', 'OT' => 'Other' }
- ENGINE_TYPES =
{ '(GUZZLER)' => nil, # "gas guzzler" '(POLICE)' => nil, # police automobile_variant '(MPFI)' => 'injection', '(MPI*)' => 'injection', '(SPFI)' => 'injection', '(FFS)' => nil, # doesn't necessarily mean fuel injection '(TURBO)' => 'turbo', '(TRBO)' => 'turbo', '(TC*)' => 'turbo', '(FFS,TRBO)' => 'turbo', '(S-CHARGE)' => 'supercharger', '(SC*)' => 'supercharger', '(DIESEL)' => nil, # diesel '(DSL)' => nil, # diesel '(ROTARY)' => nil, # rotary '(VARIABLE)' => nil, # variable displacement '(NO-CAT)' => nil, # no catalytic converter '(OHC)' => nil, # overhead camshaft '(OHV)' => nil, # overhead valves '(16-VALVE)' => nil, # 16V '(305)' => nil, # 305 cubic inch displacement '(307)' => nil, # 307 cubic inch displacement '(M-ENG)' => nil, '(W-ENG)' => nil, '(GM-BUICK)' => nil, '(GM-CHEV)' => nil, '(GM-OLDS)' => nil, '(GM-PONT)' => nil }
- FUEL_CODES =
{ 'BE' => 'EL', # battery electric 'CNG' => 'C', # CNG 'DU' => 'D', # diesel (ultra-low sulphur) 'E' => 'E', # ethanol 'EL' => 'EL', # electric 'G' => 'R', # regular gasoline 'GP' => 'P', # premium gasoline recommended 'GPR' => 'P', # premium gasoline required 'GM' => 'P', # midgrade gasoline recommended 'H' => 'H', # hydrogen 'PE' => 'EL' # plug-in electric }
- CLASS_CODES =
{ '1' => 'Two seaters', '2' => 'Minicompact cars', '3' => 'Subcompact cars', '4' => 'Compact cars', '5' => 'Midsize cars', '6' => 'Large cars', '7' => 'Small station wagons', '8' => 'Midsize station wagons', '9' => 'Large station wagons', '10' => 'Small pickup trucks 2WD', '11' => 'Small pickup trucks 4WD', '12' => 'Standard pickup trucks 2WD', '13' => 'Standard pickup trucks 4WD', '14' => 'Cargo vans', '15' => 'Passenger vans', '16' => nil, '17' => 'Special purpose vehicles 2WD', '18' => 'Special purpose vehicles 4WD', '19' => 'Special purpose vehicles' }
Instance Attribute Summary collapse
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #_displacement(row) ⇒ Object
- #_turbo(row) ⇒ Object
- #apply(row) ⇒ Object
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
87 88 89 90 |
# File 'lib/earth/automobile/automobile_make_model_year_variant/parser.rb', line 87 def initialize( = {}) = .stringify_keys @year = ['year'] end |
Instance Attribute Details
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/earth/automobile/automobile_make_model_year_variant/parser.rb', line 5 def year @year end |
Instance Method Details
#_displacement(row) ⇒ Object
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/earth/automobile/automobile_make_model_year_variant/parser.rb', line 159 def _displacement(row) optional_displacement = row['opt_disp'].gsub(/[\(\)]/, '').strip.to_s if optional_displacement =~ /^(\d\.\d)L$/ $1.to_f elsif optional_displacement =~ /^(\d{4})CC$/ ($1.to_f / 1000).round(1) else row['disp_cub_in'].to_f.cubic_inches.to(:litres).round(1) end end |
#_turbo(row) ⇒ Object
170 171 172 173 174 |
# File 'lib/earth/automobile/automobile_make_model_year_variant/parser.rb', line 170 def _turbo(row) engine_types = [ENGINE_TYPES[row['engine_desc1'].to_s], ENGINE_TYPES[row['engine_desc2'].to_s]] engine_types << (row['model_name'].to_s.downcase.include?('turbo') ? 'turbo' : nil) engine_types.flatten.include?('turbo') end |
#apply(row) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/earth/automobile/automobile_make_model_year_variant/parser.rb', line 92 def apply(row) # Pre-2010 fuel efficiencies need to be adjusted downwards to reflect real-world driving # We do this by applying equations to the *unadjusted* city and highway fuel efficiency # Source for the equations is EPA Fuel Economy Trends report Appendix A # Starting in 2008 we could use the *adjusted* values from the FEG but this would require writing a new case for 2008 and 2009 # Starting in 2010 we use the *adjusted* fuel efficiencies from the FEG case year when (1985..1997) row.merge!({ 'make_name' => row['carline_mfr_name'], 'model_name' => row['carline_name'], 'year' => year, 'transmission' => TRANSMISSIONS[row['model_trans'][0,1].to_s], 'speeds' => (row['model_trans'][1,1] == 'V') ? 'variable' : row['model_trans'][1,1], 'drive' => row['drive_system'], 'fuel_code' => row['fuel_type'], 'fuel_efficiency_city' => 1.0 / (0.003259 + (1.1805 / row['unadj_city_mpg'].to_f)), # adjust for real-world driving 'fuel_efficiency_highway' => 1.0 / (0.001376 + (1.3466 / row['unadj_hwy_mpg'].to_f)), # adjust for real-world driving 'cylinders' => row['no_cyl'], 'displacement' => _displacement(row), 'turbo' => _turbo(row), 'supercharger' => [ENGINE_TYPES[row['engine_desc1'].to_s], ENGINE_TYPES[row['engine_desc2'].to_s]].flatten.include?('supercharger'), 'injection' => (row['fuel_system'] == 'FI') ? true : false, 'size_class' => CLASS_CODES[row['size_class']] }) when (1998..2009) row.merge!({ 'make_name' => row['Manufacturer'] || row['MFR'], 'model_name' => (row['carline name'] || row['CAR LINE']).upcase, 'year' => year, 'transmission' => TRANSMISSIONS[(row['trans'] || row['TRANS'])[-3,1]], 'speeds' => ((row['trans'] || row['TRANS'])[-2,1] == 'V') ? 'variable' : (row['trans'] || row['TRANS'])[-2,1], 'drive' => ((row['drv'] || row['DRIVE SYS']) + 'WD').gsub('.0', ''), 'fuel_code' => row['fl'] || row['FUEL TYPE'], 'fuel_efficiency_city' => 1.0 / (0.003259 + (1.1805 / (row['ucty'] || row['UNRND CITY (EPA)']).to_f)), # adjust for real-world driving 'fuel_efficiency_highway' => 1.0 / (0.001376 + (1.3466 / (row['uhwy'] || row['UNRND HWY (EPA)']).to_f)), # adjust for real-world driving 'cylinders' => row['cyl'] || row['NUMB CYL'], 'displacement' => row['displ'] || row['DISPLACEMENT'], 'turbo' => ((row['T'] || row['TURBO']) == 'T' || (row['carline name'] || row['CAR LINE']).downcase.include?('turbo')) ? true : false, 'supercharger' => (row['S'] || row['SPCHGR']) == 'S', 'injection' => true, 'size_class' => row['Class'] || row['CLASS'] }) else # 2010..present row.merge!({ 'make_name' => row['Division'], 'model_name' => row['Carline'].upcase, 'year' => year, 'transmission' => TRANSMISSIONS[row['Trans']], 'speeds' => row['# Gears'].to_i, 'drive' => row['Drive Sys'] + 'WD', 'fuel_code' => FUEL_CODES[row['Fuel Usage - Conventional Fuel']], 'fuel_efficiency_city' => row['City FE (Guide) - Conventional Fuel'], 'fuel_efficiency_highway' => row['Hwy FE (Guide) - Conventional Fuel'], 'alt_fuel_code' => FUEL_CODES[row[' Fuel2 Usage - Alternative Fuel']], 'alt_fuel_efficiency_city' => row['City2 FE (Guide) - Alternative Fuel'], 'alt_fuel_efficiency_highway' => row['Hwy2 Fuel FE (Guide) - Alternative Fuel'], 'cylinders' => row['# Cyl'], 'displacement' => row['Eng Displ'], 'turbo' => row['Air Aspir Method'] == 'TC', 'supercharger' => row['Air Aspir Method'] == 'SC', 'injection' => row['# Cyl'].present? ? true : false, 'size_class' => row['Carline Class Desc'] }) end end |