earth 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -21
- data/data/rail/ntd_companies.csv +1 -0
- data/data/rail/ntd_fuel_consumption.csv +1 -0
- data/data/rail/ntd_modes.csv +1 -0
- data/data/rail/ntd_service.csv +1 -0
- data/errata/flight_segment/bts_errata.csv +6 -0
- data/lib/earth.rb +1 -0
- data/lib/earth/air/aircraft.rb +3 -5
- data/lib/earth/air/airline.rb +2 -3
- data/lib/earth/air/airport.rb +4 -5
- data/lib/earth/air/bts_aircraft.rb +1 -1
- data/lib/earth/air/flight_distance_class.rb +0 -1
- data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
- data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
- data/lib/earth/air/flight_segment.rb +12 -13
- data/lib/earth/air/flight_segment/data_miner.rb +13 -0
- data/lib/earth/automobile/automobile_activity_year.rb +0 -1
- data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_make.rb +0 -1
- data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
- data/lib/earth/automobile/automobile_make_model.rb +1 -2
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
- data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
- data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
- data/lib/earth/automobile/automobile_model.rb +0 -1
- data/lib/earth/automobile/automobile_size_class.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
- data/lib/earth/automobile/automobile_year.rb +0 -1
- data/lib/earth/bus/bus_class.rb +0 -1
- data/lib/earth/bus/bus_fuel.rb +1 -72
- data/lib/earth/bus/bus_fuel_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
- data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
- data/lib/earth/computation/computation_carrier.rb +1 -11
- data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
- data/lib/earth/computation/computation_carrier_region.rb +0 -1
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
- data/lib/earth/diet/diet_class.rb +0 -1
- data/lib/earth/diet/food_group.rb +1 -1
- data/lib/earth/electricity/electric_market.rb +2 -0
- data/lib/earth/electricity/electric_utility.rb +11 -4
- data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
- data/lib/earth/electricity/green_button_adoption.rb +2 -1
- data/lib/earth/fuel/fuel.rb +20 -81
- data/lib/earth/fuel/fuel_year.rb +0 -44
- data/lib/earth/fuel/greenhouse_gas.rb +0 -40
- data/lib/earth/hospitality/lodging_class.rb +0 -1
- data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
- data/lib/earth/industry/industry.rb +1 -2
- data/lib/earth/industry/mecs_energy.rb +9 -10
- data/lib/earth/industry/mecs_ratio.rb +2 -1
- data/lib/earth/industry/merchant_category.rb +1 -0
- data/lib/earth/industry/naics_2002.rb +2 -0
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
- data/lib/earth/industry/naics_2007.rb +1 -0
- data/lib/earth/industry/sic_1987.rb +1 -0
- data/lib/earth/locality/census_division.rb +1 -3
- data/lib/earth/locality/climate_division.rb +0 -1
- data/lib/earth/locality/country.rb +1 -2
- data/lib/earth/locality/country/data_miner.rb +4 -0
- data/lib/earth/locality/egrid_country.rb +0 -1
- data/lib/earth/locality/egrid_region.rb +1 -3
- data/lib/earth/locality/egrid_subregion.rb +1 -3
- data/lib/earth/locality/electricity_mix.rb +2 -4
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
- data/lib/earth/locality/state.rb +0 -1
- data/lib/earth/locality/zip_code.rb +0 -1
- data/lib/earth/model.rb +1 -1
- data/lib/earth/pet/breed.rb +0 -1
- data/lib/earth/pet/breed_gender.rb +0 -1
- data/lib/earth/pet/gender.rb +0 -1
- data/lib/earth/pet/species.rb +1 -3
- data/lib/earth/rail/country_rail_class.rb +0 -1
- data/lib/earth/rail/country_rail_traction.rb +0 -1
- data/lib/earth/rail/country_rail_traction_class.rb +0 -1
- data/lib/earth/rail/national_transit_database_company.rb +1 -3
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_mode.rb +0 -1
- data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_record.rb +0 -1
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
- data/lib/earth/rail/rail_class.rb +0 -1
- data/lib/earth/rail/rail_class/data_miner.rb +5 -4
- data/lib/earth/rail/rail_company.rb +0 -1
- data/lib/earth/rail/rail_fuel.rb +0 -1
- data/lib/earth/rail/rail_traction.rb +0 -1
- data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
- data/lib/earth/residence/air_conditioner_use.rb +0 -1
- data/lib/earth/residence/clothes_machine_use.rb +0 -1
- data/lib/earth/residence/dishwasher_use.rb +0 -1
- data/lib/earth/residence/residence_appliance.rb +0 -1
- data/lib/earth/residence/residence_class.rb +0 -1
- data/lib/earth/residence/residence_fuel_price.rb +1 -2
- data/lib/earth/residence/urbanity.rb +0 -1
- data/lib/earth/shipping/carrier.rb +1 -52
- data/lib/earth/shipping/carrier_mode.rb +0 -34
- data/lib/earth/shipping/shipment_mode.rb +0 -26
- data/lib/earth/tasks.rb +14 -4
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/aircraft_spec.rb +9 -1
- data/spec/earth/air/airline_spec.rb +2 -2
- data/spec/earth/air/airport_spec.rb +1 -2
- data/spec/earth/air/bts_aircraft_spec.rb +2 -2
- data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
- data/spec/earth/air/flight_distance_class_spec.rb +26 -18
- data/spec/earth/air/flight_seat_class_spec.rb +12 -0
- data/spec/earth/air/flight_segment_spec.rb +38 -33
- data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
- data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
- data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
- data/spec/earth/automobile/automobile_make_spec.rb +8 -8
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
- data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
- data/spec/earth/automobile/automobile_model_spec.rb +3 -0
- data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
- data/spec/earth/automobile/automobile_year_spec.rb +4 -2
- data/spec/earth/bus/bus_class_spec.rb +10 -0
- data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
- data/spec/earth/bus/bus_fuel_spec.rb +16 -8
- data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
- data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
- data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
- data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
- data/spec/earth/diet/diet_class_spec.rb +14 -0
- data/spec/earth/diet/food_group_spec.rb +26 -0
- data/spec/earth/electricity/electric_market_spec.rb +4 -5
- data/spec/earth/electricity/electric_utility_spec.rb +30 -19
- data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
- data/spec/earth/fuel/fuel_spec.rb +88 -14
- data/spec/earth/fuel/fuel_year_spec.rb +21 -0
- data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
- data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
- data/spec/earth/industry/industry_spec.rb +16 -9
- data/spec/earth/industry/mecs_energy_spec.rb +76 -72
- data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
- data/spec/earth/industry/merchant_category_spec.rb +7 -5
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
- data/spec/earth/industry/naics_2002_spec.rb +1 -11
- data/spec/earth/industry/naics_2007_spec.rb +2 -11
- data/spec/earth/industry/sic_1987_spec.rb +3 -14
- data/spec/earth/locality/census_division_spec.rb +25 -0
- data/spec/earth/locality/census_region_spec.rb +8 -0
- data/spec/earth/locality/climate_division_spec.rb +13 -0
- data/spec/earth/locality/country_spec.rb +24 -23
- data/spec/earth/locality/egrid_country_spec.rb +7 -6
- data/spec/earth/locality/egrid_region_spec.rb +6 -6
- data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
- data/spec/earth/locality/electricity_mix_spec.rb +17 -17
- data/spec/earth/locality/padd_spec.rb +21 -0
- data/spec/earth/locality/state_spec.rb +8 -11
- data/spec/earth/locality/zip_code_spec.rb +29 -22
- data/spec/earth/pet/breed_gender_spec.rb +8 -0
- data/spec/earth/pet/breed_spec.rb +8 -0
- data/spec/earth/pet/gender_spec.rb +8 -0
- data/spec/earth/pet/species_spec.rb +11 -5
- data/spec/earth/rail/country_rail_class_spec.rb +16 -0
- data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
- data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
- data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
- data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
- data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
- data/spec/earth/rail/rail_class_spec.rb +8 -0
- data/spec/earth/rail/rail_company_spec.rb +20 -0
- data/spec/earth/rail/rail_fuel_spec.rb +19 -0
- data/spec/earth/rail/rail_traction_spec.rb +8 -0
- data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
- data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
- data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
- data/spec/earth/residence/residence_appliance_spec.rb +19 -0
- data/spec/earth/residence/residence_class_spec.rb +15 -0
- data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
- data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
- data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
- data/spec/earth/residence/urbanity_spec.rb +8 -0
- data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
- data/spec/earth/shipping/carrier_spec.rb +27 -0
- data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
- data/spec/earth_spec.rb +1 -1
- data/spec/factories/airline.rb +0 -1
- data/spec/factories/airport.rb +0 -1
- data/spec/factories/automobile_activity_year.rb +8 -0
- data/spec/factories/automobile_activity_year_type.rb +8 -0
- data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
- data/spec/factories/automobile_fuel.rb +15 -0
- data/spec/factories/automobile_make.rb +9 -0
- data/spec/factories/automobile_make_model.rb +10 -0
- data/spec/factories/automobile_make_model_year.rb +9 -0
- data/spec/factories/automobile_model.rb +9 -0
- data/spec/factories/automobile_type_fuel.rb +7 -0
- data/spec/factories/automobile_type_fuel_control.rb +16 -0
- data/spec/factories/automobile_type_fuel_year.rb +9 -0
- data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
- data/spec/factories/bus_fuel.rb +7 -0
- data/spec/factories/bus_fuel_year_control.rb +9 -0
- data/spec/factories/cbecs_energy_intensity.rb +15 -0
- data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
- data/spec/factories/electric_utility.rb +8 -0
- data/spec/factories/flight_distance_class.rb +8 -0
- data/spec/factories/flight_segment.rb +0 -1
- data/spec/factories/food_group.rb +8 -0
- data/spec/factories/fuel.rb +8 -0
- data/spec/factories/fuel_year.rb +8 -0
- data/spec/factories/green_button_adoption.rb +8 -0
- data/spec/factories/greenhouse_gas.rb +7 -0
- data/spec/factories/industry.rb +9 -0
- data/spec/factories/mecs_energy.rb +15 -0
- data/spec/factories/mecs_ratio.rb +15 -0
- data/spec/factories/national_transit_database_company.rb +8 -0
- data/spec/factories/national_transit_database_mode.rb +8 -0
- data/spec/factories/national_transit_database_record.rb +9 -0
- data/spec/factories/residence_appliance.rb +7 -0
- data/spec/factories/zip_code.rb +9 -0
- data/spec/spec_helper.rb +36 -19
- metadata +346 -66
- data/lib/earth/acronyms.rb +0 -12
- data/lib/earth/rail/rail_company_traction.rb +0 -24
- data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
- data/lib/earth/rail/rail_company_traction_class.rb +0 -26
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
@@ -1,23 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_activity_year"
|
3
3
|
|
4
4
|
describe AutomobileActivityYear do
|
5
|
-
|
6
|
-
|
5
|
+
let(:aay) { AutomobileActivityYear }
|
6
|
+
|
7
|
+
describe '.find_by_closest_year' do
|
8
|
+
it "returns the closest year" do
|
9
|
+
aay.delete_all
|
10
|
+
twenty_nine = FactoryGirl.create :aay, :twenty_nine
|
11
|
+
twenty_ten = FactoryGirl.create :aay, :twenty_ten
|
12
|
+
|
13
|
+
aay.find_by_closest_year(2011).should == twenty_ten
|
14
|
+
aay.find_by_closest_year(2009).should == twenty_nine
|
15
|
+
aay.find_by_closest_year(2005).should == twenty_nine
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
|
-
describe '
|
10
|
-
|
11
|
-
|
19
|
+
describe 'Sanity check', :sanity => true do
|
20
|
+
let(:total) { aay.count }
|
21
|
+
|
22
|
+
it { total.should == 15 }
|
23
|
+
it { aay.where("hfc_emission_factor > 0").count.should == total }
|
12
24
|
|
13
25
|
# spot check
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.find_by_closest_year' do
|
19
|
-
it { AAY.find_by_closest_year(1994).should == AAY.find(1995) }
|
20
|
-
it { AAY.find_by_closest_year(2005).should == AAY.find(2005) }
|
21
|
-
it { AAY.find_by_closest_year(2010).should == AAY.find(2009) }
|
26
|
+
it { aay.first.hfc_emission_factor.should be_within(1e-5).of(0.01656) }
|
27
|
+
it { aay.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
22
28
|
end
|
23
29
|
end
|
@@ -1,18 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
|
3
3
|
|
4
4
|
describe AutomobileActivityYearTypeFuel do
|
5
|
-
|
6
|
-
require 'earth/acronyms'
|
7
|
-
end
|
5
|
+
let(:aaytf) { AutomobileActivityYearTypeFuel }
|
8
6
|
|
9
|
-
describe '
|
10
|
-
it
|
11
|
-
|
12
|
-
|
7
|
+
describe '.latest' do
|
8
|
+
it "returns all records from the latest year" do
|
9
|
+
FactoryGirl.create :aaytf, :gas_car_2009
|
10
|
+
d = FactoryGirl.create :aaytf, :diesel_car_2010
|
11
|
+
g = FactoryGirl.create :aaytf, :gas_car_2010
|
12
|
+
|
13
|
+
aaytf.latest.should == [d, g]
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
|
-
describe '
|
16
|
-
it {
|
17
|
+
describe 'Sanity check', :sanity => true do
|
18
|
+
it { aaytf.count.should == 120 }
|
19
|
+
it { aaytf.where(:distance => nil).count.should == 0 }
|
20
|
+
it { aaytf.where("fuel_family != 'alternative' AND fuel_consumption IS NULL").count.should == 0 }
|
17
21
|
end
|
18
22
|
end
|
@@ -1,31 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_activity_year_type"
|
3
|
+
require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
|
3
4
|
|
4
5
|
describe AutomobileActivityYearType do
|
5
|
-
|
6
|
-
require 'earth/acronyms'
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'verify', :sanity => true do
|
10
|
-
it { AAYT.count.should == 30 }
|
11
|
-
it { AAYT.where("hfc_emissions > 0").count.should == AAYT.count }
|
12
|
-
it { AAYT.where("hfc_emission_factor > 0").count.should == AAYT.count }
|
13
|
-
|
14
|
-
# spot check
|
15
|
-
it { AAYT.first.hfc_emissions.should be_within(0.1).of(31000000000) }
|
16
|
-
it { AAYT.first.hfc_emission_factor.should be_within(1e-5).of(0.02438) }
|
17
|
-
it { AAYT.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
18
|
-
end
|
6
|
+
let(:aayt) { AutomobileActivityYearType }
|
19
7
|
|
20
8
|
describe '.find_by_type_name_and_closest_year' do
|
21
|
-
it
|
22
|
-
|
23
|
-
|
9
|
+
it 'returns the AAYT with the closest year' do
|
10
|
+
cars_2009 = FactoryGirl.create :aayt, :cars_2009
|
11
|
+
cars_2010 = FactoryGirl.create :aayt, :cars_2010
|
12
|
+
|
13
|
+
aayt.find_by_type_name_and_closest_year('cars', 2011).should == cars_2010
|
14
|
+
aayt.find_by_type_name_and_closest_year('cars', 2009).should == cars_2009
|
15
|
+
aayt.find_by_type_name_and_closest_year('cars', 2000).should == cars_2009
|
16
|
+
end
|
24
17
|
end
|
25
18
|
|
26
19
|
describe '#activity_year_type_fuels' do
|
27
|
-
it '
|
28
|
-
|
20
|
+
it 'returns activity year type fuels with the same activity year and type name' do
|
21
|
+
d = FactoryGirl.create :aaytf, :diesel_car_2010
|
22
|
+
g = FactoryGirl.create :aaytf, :gas_car_2010
|
23
|
+
cars_2010 = FactoryGirl.create :aayt, :cars_2010
|
24
|
+
cars_2010.activity_year_type_fuels.should == [d,g]
|
29
25
|
end
|
30
26
|
end
|
27
|
+
|
28
|
+
describe 'Sanity check', :sanity => true do
|
29
|
+
let(:total) { aayt.count }
|
30
|
+
it { total.should == 30 }
|
31
|
+
it { aayt.where("hfc_emissions > 0").count.should == total }
|
32
|
+
it { aayt.where("hfc_emission_factor > 0").count.should == total }
|
33
|
+
|
34
|
+
# spot check
|
35
|
+
it { aayt.first.hfc_emissions.should be_within(0.1).of(31000000000) }
|
36
|
+
it { aayt.first.hfc_emission_factor.should be_within(1e-5).of(0.02438) }
|
37
|
+
it { aayt.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
38
|
+
end
|
31
39
|
end
|
@@ -1,18 +1,93 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_fuel"
|
3
3
|
|
4
4
|
describe AutomobileFuel do
|
5
|
-
|
5
|
+
describe '.diesel' do
|
6
|
+
it "should return diesel" do
|
7
|
+
AutomobileFuel.delete_all
|
8
|
+
diesel = FactoryGirl.create :automobile_fuel, :diesel
|
9
|
+
AutomobileFuel.diesel.should == diesel
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.gasoline' do
|
14
|
+
it "should return gasoline" do
|
15
|
+
AutomobileFuel.delete_all
|
16
|
+
gas = FactoryGirl.create :automobile_fuel, :gas
|
17
|
+
AutomobileFuel.gasoline.should == gas
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.fallback_blend_portion' do
|
22
|
+
it "should return diesel's share of total US gasoline and diesel consumption" do
|
23
|
+
AutomobileFuel.delete_all
|
24
|
+
diesel = FactoryGirl.create :automobile_fuel, :diesel
|
25
|
+
gas = FactoryGirl.create :automobile_fuel, :gas
|
26
|
+
AutomobileFuel.fallback_blend_portion.should be_within(5e-2).of(0.1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#non_liquid?' do
|
31
|
+
it "should return true if energy content units are megajoules per litre" do
|
32
|
+
AutomobileFuel.delete_all
|
33
|
+
gas = FactoryGirl.create :automobile_fuel, :gas
|
34
|
+
cng = FactoryGirl.create :automobile_fuel, :cng
|
35
|
+
|
36
|
+
gas.non_liquid?.should == false
|
37
|
+
cng.non_liquid?.should == true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#same_as?(other_auto_fuel)' do
|
42
|
+
it "should consider all grades of gasoline as the same" do
|
43
|
+
AutomobileFuel.delete_all
|
44
|
+
gas = FactoryGirl.create :automobile_fuel, :gas
|
45
|
+
regular = FactoryGirl.create :automobile_fuel, :regular
|
46
|
+
premium = FactoryGirl.create :automobile_fuel, :premium
|
47
|
+
|
48
|
+
gas.same_as?(gas).should == true
|
49
|
+
gas.same_as?(regular).should == true
|
50
|
+
gas.same_as?(premium).should == true
|
51
|
+
regular.same_as?(premium).should == true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should consider identical non-gasoline fuels as the same" do
|
55
|
+
AutomobileFuel.delete_all
|
56
|
+
b5 = FactoryGirl.create :automobile_fuel, :b5
|
57
|
+
b20 = FactoryGirl.create :automobile_fuel, :b20
|
58
|
+
|
59
|
+
b5.same_as?(b5).should == true
|
60
|
+
b5.same_as?(b20).should == false
|
61
|
+
end
|
62
|
+
end
|
6
63
|
|
7
|
-
describe '
|
8
|
-
it
|
64
|
+
describe '#suffix' do
|
65
|
+
it "returns 'DIESEL' for diesel and biodiesel fuels" do
|
66
|
+
%w{ D BP-B5 BP-B20 BP-B100 }.each do |fuel_code|
|
67
|
+
AutomobileFuel.new(:code => fuel_code).suffix.should == 'DIESEL'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns 'FFV' for ethanol" do
|
72
|
+
AutomobileFuel.new(:code => 'E').suffix.should == 'FFV'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns 'CNG' for cng" do
|
76
|
+
AutomobileFuel.new(:code => 'C').suffix.should == 'CNG'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'Sanity check', :sanity => true do
|
81
|
+
let(:total) { AutomobileFuel.count }
|
82
|
+
|
83
|
+
it { total.should == 12 }
|
9
84
|
it { AutomobileFuel.where(:distance_key => nil).count.should == 0 }
|
10
|
-
it { AutomobileFuel.where("annual_distance >= 0").count.should ==
|
11
|
-
it { AutomobileFuel.where("energy_content >= 0").count.should ==
|
12
|
-
it { AutomobileFuel.where("co2_emission_factor >= 0").count.should ==
|
13
|
-
it { AutomobileFuel.where("co2_biogenic_emission_factor >= 0").count.should ==
|
14
|
-
it { AutomobileFuel.where("ch4_emission_factor >= 0").count.should ==
|
15
|
-
it { AutomobileFuel.where("n2o_emission_factor >= 0").count.should ==
|
85
|
+
it { AutomobileFuel.where("annual_distance >= 0").count.should == total }
|
86
|
+
it { AutomobileFuel.where("energy_content >= 0").count.should == total }
|
87
|
+
it { AutomobileFuel.where("co2_emission_factor >= 0").count.should == total - 1 }
|
88
|
+
it { AutomobileFuel.where("co2_biogenic_emission_factor >= 0").count.should == total - 1 }
|
89
|
+
it { AutomobileFuel.where("ch4_emission_factor >= 0").count.should == total }
|
90
|
+
it { AutomobileFuel.where("n2o_emission_factor >= 0").count.should == total }
|
16
91
|
it { AutomobileFuel.where("total_consumption >= 0").count.should == 2 }
|
17
92
|
|
18
93
|
it { AutomobileFuel.find('gasoline').annual_distance.should be_within(0.1).of(17568.6) }
|
@@ -51,48 +126,27 @@ describe AutomobileFuel do
|
|
51
126
|
fuel.n2o_emission_factor.should == AutomobileFuel.gasoline.n2o_emission_factor
|
52
127
|
end
|
53
128
|
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.diesel' do
|
57
|
-
it { AutomobileFuel.diesel.should == AutomobileFuel.find('diesel') }
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '.gasoline' do
|
61
|
-
it { AutomobileFuel.gasoline.should == AutomobileFuel.find('gasoline') }
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '.fallback_blend_portion' do
|
65
|
-
it { AutomobileFuel.fallback_blend_portion.should be_within(1e-5).of(0.01260) }
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '.fallback' do
|
69
|
-
it { AutomobileFuel.fallback.name.should == 'fallback' }
|
70
|
-
it { fallback.base_fuel.should == Fuel.find('Motor Gasoline') }
|
71
|
-
it { fallback.blend_fuel.should == Fuel.find('Distillate Fuel Oil No. 2') }
|
72
|
-
it { fallback.blend_portion.should be_within(1e-5).of(0.01260) }
|
73
|
-
|
74
|
-
it { fallback.annual_distance.should be_within(0.1).of(17629.6) }
|
75
|
-
it { fallback.energy_content.should be_within(1e-6).of(34.6766) }
|
76
|
-
it { fallback.co2_emission_factor.should be_within(1e-6).of(2.34637) }
|
77
|
-
it { fallback.co2_biogenic_emission_factor.should == 0.0 }
|
78
|
-
it { fallback.ch4_emission_factor.should be_within(1e-8).of(4.203e-4) }
|
79
|
-
it { fallback.n2o_emission_factor.should be_within(1e-8).of(5.665e-3) }
|
80
129
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
130
|
+
describe '.fallback' do
|
131
|
+
let(:fallback) { AutomobileFuel.fallback }
|
132
|
+
|
133
|
+
it { fallback.name.should == 'fallback' }
|
134
|
+
it { fallback.base_fuel.should == Fuel.find('Motor Gasoline') }
|
135
|
+
it { fallback.blend_fuel.should == Fuel.find('Distillate Fuel Oil No. 2') }
|
136
|
+
it { fallback.blend_portion.should be_within(1e-5).of(0.01260) }
|
137
|
+
|
138
|
+
it { fallback.annual_distance.should be_within(0.1).of(17629.6) }
|
139
|
+
it { fallback.energy_content.should be_within(1e-6).of(34.6766) }
|
140
|
+
it { fallback.co2_emission_factor.should be_within(1e-6).of(2.34637) }
|
141
|
+
it { fallback.co2_biogenic_emission_factor.should == 0.0 }
|
142
|
+
it { fallback.ch4_emission_factor.should be_within(1e-8).of(4.203e-4) }
|
143
|
+
it { fallback.n2o_emission_factor.should be_within(1e-8).of(5.665e-3) }
|
144
|
+
|
145
|
+
it { fallback.energy_content_units.should == 'megajoules_per_litre' }
|
146
|
+
it { fallback.co2_emission_factor_units.should == 'kilograms_per_litre' }
|
147
|
+
it { fallback.co2_biogenic_emission_factor_units.should == 'kilograms_per_litre' }
|
148
|
+
it { fallback.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
149
|
+
it { fallback.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
150
|
+
end
|
97
151
|
end
|
98
152
|
end
|
@@ -1,28 +1,113 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_fuel"
|
3
|
+
require "#{Earth::FACTORY_DIR}/automobile_make"
|
4
|
+
require "#{Earth::FACTORY_DIR}/automobile_make_model"
|
5
|
+
require "#{Earth::FACTORY_DIR}/automobile_make_model_year"
|
6
|
+
require "#{Earth::FACTORY_DIR}/automobile_model"
|
3
7
|
|
4
8
|
describe AutomobileMakeModel do
|
5
|
-
let(:
|
6
|
-
let(:
|
9
|
+
let(:amm) { AutomobileMakeModel }
|
10
|
+
let(:ammy) { AutomobileMakeModelYear }
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
describe '.custom_find' do
|
13
|
+
it 'finds diesel models' do
|
14
|
+
amm.delete_all
|
15
|
+
AutomobileMake.delete_all
|
16
|
+
AutomobileModel.delete_all
|
17
|
+
AutomobileFuel.delete_all
|
18
|
+
|
19
|
+
FactoryGirl.create :amm, :vw_jetta
|
20
|
+
FactoryGirl.create :amm, :vw_jetta_diesel
|
21
|
+
vw = FactoryGirl.create :automobile_make, :vw
|
22
|
+
jetta = FactoryGirl.create :automobile_model, :jetta
|
23
|
+
|
24
|
+
%w{ diesel b5 b20 b100 }.each do |fuel|
|
25
|
+
f = FactoryGirl.create :automobile_fuel, fuel.to_sym
|
26
|
+
amm.custom_find(
|
27
|
+
{ :make => vw, :model => jetta, :automobile_fuel => f }
|
28
|
+
).name.should == 'Volkswagen JETTA DIESEL'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'finds flex-fuel models' do
|
33
|
+
amm.delete_all
|
34
|
+
AutomobileMake.delete_all
|
35
|
+
AutomobileModel.delete_all
|
36
|
+
AutomobileFuel.delete_all
|
37
|
+
|
38
|
+
FactoryGirl.create :amm, :ford_f150_ffv
|
39
|
+
ford = FactoryGirl.create :automobile_make, :ford
|
40
|
+
f150 = FactoryGirl.create :automobile_model, :f150
|
41
|
+
e85 = FactoryGirl.create :automobile_fuel, :e85
|
42
|
+
|
43
|
+
amm.custom_find(
|
44
|
+
{ :make => ford, :model => f150, :automobile_fuel => e85 }
|
45
|
+
).name.should == 'Ford F150 FFV'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'finds cng models' do
|
49
|
+
amm.delete_all
|
50
|
+
AutomobileMake.delete_all
|
51
|
+
AutomobileModel.delete_all
|
52
|
+
AutomobileFuel.delete_all
|
53
|
+
|
54
|
+
FactoryGirl.create :amm, :honda_civic_cng
|
55
|
+
honda = FactoryGirl.create :automobile_make, :honda
|
56
|
+
civic = FactoryGirl.create :automobile_model, :civic
|
57
|
+
cng = FactoryGirl.create :automobile_fuel, :cng
|
58
|
+
|
59
|
+
amm.custom_find(
|
60
|
+
{ :make => honda, :model => civic, :automobile_fuel => cng }
|
61
|
+
).name.should == 'Honda CIVIC CNG'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'ignores fuel if it does not help' do
|
65
|
+
amm.delete_all
|
66
|
+
AutomobileMake.delete_all
|
67
|
+
AutomobileModel.delete_all
|
68
|
+
AutomobileFuel.delete_all
|
69
|
+
|
70
|
+
FactoryGirl.create :amm, :vw_jetta
|
71
|
+
FactoryGirl.create :amm, :vw_jetta_diesel
|
72
|
+
vw = FactoryGirl.create :automobile_make, :vw
|
73
|
+
jetta = FactoryGirl.create :automobile_model, :jetta
|
74
|
+
cng = FactoryGirl.create :automobile_fuel, :cng
|
75
|
+
|
76
|
+
amm.custom_find(
|
77
|
+
{ :make => vw, :model => jetta, :automobile_fuel => cng }
|
78
|
+
).name.should == 'Volkswagen JETTA'
|
79
|
+
end
|
80
|
+
end
|
13
81
|
|
14
|
-
|
15
|
-
|
82
|
+
describe '#model_years' do
|
83
|
+
it "returns all the associated model years" do
|
84
|
+
ammy.delete_all
|
85
|
+
amm.delete_all
|
86
|
+
|
87
|
+
FactoryGirl.create :ammy, :honda_civic_2000
|
88
|
+
FactoryGirl.create :ammy, :honda_civic_cng_2000
|
89
|
+
FactoryGirl.create :ammy, :honda_civic_cng_2001
|
90
|
+
|
91
|
+
amm = FactoryGirl.create :amm, :honda_civic_cng
|
92
|
+
amm.model_years.should == ammy.where(:make_name => 'Honda', :model_name => 'CIVIC CNG')
|
93
|
+
end
|
16
94
|
end
|
17
95
|
|
18
|
-
describe '
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
it {
|
25
|
-
|
96
|
+
describe 'Sanity check', :sanity => true do
|
97
|
+
let(:total) { amm.count }
|
98
|
+
let(:civic) { amm.where(:name => "Honda Civic").first }
|
99
|
+
let(:civic_cng) { amm.where(:name => "Honda Civic CNG").first }
|
100
|
+
let(:f150_ffv) { amm.where(:name => "Ford F150 FFV").first }
|
101
|
+
|
102
|
+
it { total.should == 2353 }
|
103
|
+
|
104
|
+
it { amm.where(:fuel_code => nil).count.should == 0 }
|
105
|
+
it { amm.where("fuel_efficiency_city > 0").count.should == total }
|
106
|
+
it { amm.where("fuel_efficiency_highway > 0").count.should == total }
|
107
|
+
it { amm.where("alt_fuel_code IS NOT NULL").count.should == 157 }
|
108
|
+
it { amm.where("alt_fuel_efficiency_city > 0").count.should == 157 }
|
109
|
+
it { amm.where("alt_fuel_efficiency_highway > 0").count.should == 157 }
|
110
|
+
it { amm.where(:type_name => nil).count.should == 0 }
|
26
111
|
|
27
112
|
# spot checks
|
28
113
|
it { civic.fuel_code.should == 'G' }
|
@@ -59,48 +144,4 @@ describe AutomobileMakeModel do
|
|
59
144
|
|
60
145
|
it { f150_ffv.type_name.should == 'Light-duty trucks' }
|
61
146
|
end
|
62
|
-
|
63
|
-
describe '.custom_find' do
|
64
|
-
it 'considers fuel' do
|
65
|
-
%w{ diesel B5 B20 B100 }.each do |fuel|
|
66
|
-
AMM.custom_find(
|
67
|
-
{
|
68
|
-
:make => AutomobileMake.find('Volkswagen'),
|
69
|
-
:model => AutomobileModel.find('Jetta'),
|
70
|
-
:automobile_fuel => AutomobileFuel.find(fuel)
|
71
|
-
}
|
72
|
-
).name.should == 'Volkswagen JETTA DIESEL'
|
73
|
-
end
|
74
|
-
|
75
|
-
AMM.custom_find(
|
76
|
-
{
|
77
|
-
:make => AutomobileMake.find('Ford'),
|
78
|
-
:model => AutomobileModel.find('F150'),
|
79
|
-
:automobile_fuel => AutomobileFuel.find('E85')
|
80
|
-
}
|
81
|
-
).name.should == 'Ford F150 FFV'
|
82
|
-
|
83
|
-
AMM.custom_find(
|
84
|
-
{
|
85
|
-
:make => AutomobileMake.find('Honda'),
|
86
|
-
:model => AutomobileModel.find('Civic'),
|
87
|
-
:automobile_fuel => AutomobileFuel.find('CNG')
|
88
|
-
}
|
89
|
-
).name.should == 'Honda CIVIC CNG'
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'ignores fuel if it does not help' do
|
93
|
-
AMM.custom_find(
|
94
|
-
{
|
95
|
-
:make => AutomobileMake.find('Volkswagen'),
|
96
|
-
:model => AutomobileModel.find('Jetta'),
|
97
|
-
:automobile_fuel => AutomobileFuel.find('CNG')
|
98
|
-
}
|
99
|
-
).name.should == 'Volkswagen JETTA'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#model_years' do
|
104
|
-
it { civic.model_years.sort.should == civic_years.sort }
|
105
|
-
end
|
106
147
|
end
|