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
@@ -2,11 +2,15 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/automobile/automobile_make_year_fleet'
|
3
3
|
|
4
4
|
describe AutomobileMakeYearFleet do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
it {
|
5
|
+
let(:amyf) { AutomobileMakeYearFleet }
|
6
|
+
|
7
|
+
describe 'Sanity check', :sanity => true do
|
8
|
+
let(:total) { amyf.count }
|
9
|
+
|
10
|
+
it { total.should == 1349 }
|
11
|
+
it { amyf.where('year >= 1978 AND year <= 2011').count.should == total }
|
12
|
+
it { amyf.where('volume > 0').count.should == total }
|
13
|
+
it { amyf.where('fuel_efficiency > 0').count.should == total }
|
14
|
+
it { amyf.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == total }
|
11
15
|
end
|
12
16
|
end
|
@@ -2,18 +2,19 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/automobile/automobile_make_year'
|
3
3
|
|
4
4
|
describe AutomobileMakeYear do
|
5
|
-
|
6
|
-
require 'earth/acronyms'
|
7
|
-
end
|
5
|
+
let(:amy) { AutomobileMakeYear }
|
8
6
|
|
9
|
-
describe '
|
10
|
-
|
11
|
-
|
12
|
-
it {
|
7
|
+
describe 'Sanity check', :sanity => true do
|
8
|
+
let(:total) { amy.count }
|
9
|
+
|
10
|
+
it { total.should == 1276 }
|
11
|
+
it { amy.where("fuel_efficiency > 0").count.should == total }
|
12
|
+
it { amy.find("Honda 2011").fuel_efficiency.should be_within(1e-4).of(13.34186) }
|
13
|
+
it { amy.find("Honda 2012").fuel_efficiency.should be_within(1e-5).of(12.17321) }
|
13
14
|
|
14
15
|
it 'has proper weightings' do
|
15
|
-
|
16
|
-
|
16
|
+
amy.connection.select_values("SELECT DISTINCT year FROM #{amy.quoted_table_name}").each do |year|
|
17
|
+
amy.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -2,20 +2,21 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/automobile/automobile_size_class'
|
3
3
|
|
4
4
|
describe AutomobileSizeClass do
|
5
|
-
describe '
|
6
|
-
|
7
|
-
it {
|
8
|
-
it { AutomobileSizeClass.where("
|
5
|
+
describe 'Sanity check', :sanity => true do
|
6
|
+
let(:total) { AutomobileSizeClass.count }
|
7
|
+
it { total.should == 15 }
|
8
|
+
it { AutomobileSizeClass.where("fuel_efficiency_city > 0").count.should == total }
|
9
|
+
it { AutomobileSizeClass.where("fuel_efficiency_highway > 0").count.should == total }
|
9
10
|
it { AutomobileSizeClass.where("hybrid_fuel_efficiency_city_multiplier > 1.0").count.should == 7 }
|
10
11
|
it { AutomobileSizeClass.where("hybrid_fuel_efficiency_highway_multiplier > 1.0").count.should == 7 }
|
11
12
|
it { AutomobileSizeClass.where("conventional_fuel_efficiency_city_multiplier < 1.0").count.should == 7 }
|
12
13
|
it { AutomobileSizeClass.where("conventional_fuel_efficiency_highway_multiplier < 1.0").count.should == 7 }
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
|
15
|
+
describe '.fallback' do
|
16
|
+
it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_city_multiplier.should == 1.651 }
|
17
|
+
it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_highway_multiplier.should == 1.213 }
|
18
|
+
it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_city_multiplier.should == 0.987 }
|
19
|
+
it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_highway_multiplier.should == 0.996 }
|
20
|
+
end
|
20
21
|
end
|
21
22
|
end
|
@@ -2,17 +2,17 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/automobile/automobile_type_fuel_control'
|
3
3
|
|
4
4
|
describe AutomobileTypeFuelControl do
|
5
|
-
|
6
|
-
require 'earth/acronyms'
|
7
|
-
end
|
5
|
+
let(:atfc) { AutomobileTypeFuelControl }
|
8
6
|
|
9
|
-
describe '
|
10
|
-
|
11
|
-
|
12
|
-
it {
|
7
|
+
describe 'Sanity check', :sanity => true do
|
8
|
+
let(:total) { atfc.count }
|
9
|
+
|
10
|
+
it { total.should == 20 }
|
11
|
+
it { atfc.where("ch4_emission_factor > 0").count.should == total }
|
12
|
+
it { atfc.where("n2o_emission_factor > 0").count.should == total }
|
13
13
|
|
14
14
|
# spot checks
|
15
|
-
it {
|
16
|
-
it {
|
15
|
+
it { atfc.first.ch4_emission_factor.should be_within(1e-9).of(1.5534e-5) }
|
16
|
+
it { atfc.first.n2o_emission_factor.should be_within(1e-8).of(2.7775e-4) }
|
17
17
|
end
|
18
18
|
end
|
@@ -1,15 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_type_fuel"
|
3
|
+
require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
|
3
4
|
|
4
5
|
describe AutomobileTypeFuel do
|
5
|
-
let(:
|
6
|
+
let(:atf) { AutomobileTypeFuel }
|
7
|
+
let(:aaytf) { AutomobileActivityYearTypeFuel }
|
6
8
|
|
7
|
-
describe '
|
8
|
-
it
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
describe '#latest_activity_year_type_fuel' do
|
10
|
+
it 'should always be a match from the latest activity year' do
|
11
|
+
FactoryGirl.create :aaytf, :gas_car_2009
|
12
|
+
FactoryGirl.create :aaytf, :gas_car_2010
|
13
|
+
car_gas = FactoryGirl.create :atf, :car_gas
|
14
|
+
latest_year = aaytf.maximum :activity_year
|
15
|
+
car_gas.latest_activity_year_type_fuel.activity_year.should == latest_year
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Sanity check', :sanity => true do
|
20
|
+
let(:total) { atf.count }
|
21
|
+
let(:test_type_fuel) { AutomobileTypeFuel.find('Light-duty trucks gasoline') }
|
22
|
+
|
23
|
+
it { total.should == 4 }
|
24
|
+
it { atf.where("annual_distance > 0").count.should == total }
|
25
|
+
it { atf.where("ch4_emission_factor > 0").count.should == total }
|
26
|
+
it { atf.where("n2o_emission_factor > 0").count.should == total }
|
27
|
+
it { atf.where("vehicles > 0").count.should == total }
|
13
28
|
|
14
29
|
# spot checks
|
15
30
|
it { test_type_fuel.annual_distance.should be_within(0.1).of(19626.6) }
|
@@ -22,14 +37,4 @@ describe AutomobileTypeFuel do
|
|
22
37
|
it { test_type_fuel.fuel_consumption.should be_within(1).of(129_881_000_000) }
|
23
38
|
it { test_type_fuel.fuel_consumption_units.should == 'litres' }
|
24
39
|
end
|
25
|
-
|
26
|
-
describe '#latest_activity_year_type_fuel' do
|
27
|
-
it 'should always be a match from 2009' do
|
28
|
-
AutomobileTypeFuel.safe_find_each do |atf|
|
29
|
-
atf.latest_activity_year_type_fuel.type_name.should == atf.type_name
|
30
|
-
atf.latest_activity_year_type_fuel.fuel_family.should == atf.fuel_family
|
31
|
-
atf.latest_activity_year_type_fuel.activity_year.should == 2009
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
40
|
end
|
@@ -1,44 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_type_fuel_control"
|
3
|
+
require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year_control"
|
3
4
|
|
4
5
|
describe AutomobileTypeFuelYearControl do
|
5
|
-
let(:
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
require 'earth/acronyms'
|
9
|
-
end
|
10
|
-
|
11
|
-
describe 'verify imported data', :sanity => true do
|
12
|
-
it { ATFYC.count.should == 142 }
|
13
|
-
|
14
|
-
it 'total travel percent should sum to 1' do
|
15
|
-
ATFYC.group([:type_name, :fuel_family, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
|
16
|
-
total.should be_within(1e-5).of(1.0)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it { ATFYC.where(:type_fuel_control_name => nil).count.should == 0 }
|
21
|
-
end
|
6
|
+
let(:atfyc) { AutomobileTypeFuelYearControl }
|
22
7
|
|
23
8
|
describe '.find_all_by_type_name_and_fuel_family_and_closest_year' do
|
24
|
-
it
|
25
|
-
|
26
|
-
|
9
|
+
it "should return all ATFYCs from the closest year" do
|
10
|
+
cars_2009_1 = FactoryGirl.create :atfyc, :cars_2009_1
|
11
|
+
cars_2009_2 = FactoryGirl.create :atfyc, :cars_2009_2
|
12
|
+
cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
|
13
|
+
cars_2010_2 = FactoryGirl.create :atfyc, :cars_2010_2
|
14
|
+
|
15
|
+
atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2011).should == [cars_2010_1, cars_2010_2]
|
16
|
+
atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2009).should == [cars_2009_1, cars_2009_2]
|
17
|
+
atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2005).should == [cars_2009_1, cars_2009_2]
|
18
|
+
end
|
27
19
|
end
|
28
20
|
|
29
21
|
describe '#ch4_emission_factor' do
|
30
|
-
it {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
it {
|
23
|
+
FactoryGirl.create :atfc, :car_tier_1
|
24
|
+
cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
|
25
|
+
|
26
|
+
cars_2010_1.ch4_emission_factor.should be_within(5e-3).of(0.04)
|
27
|
+
cars_2010_1.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre'
|
28
|
+
}
|
35
29
|
end
|
36
30
|
|
37
31
|
describe '#n2o_emission_factor' do
|
38
|
-
it {
|
32
|
+
it {
|
33
|
+
FactoryGirl.create :atfc, :car_tier_1
|
34
|
+
cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
|
35
|
+
|
36
|
+
cars_2010_1.n2o_emission_factor.should be_within(5e-3).of(0.08)
|
37
|
+
cars_2010_1.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre'
|
38
|
+
}
|
39
39
|
end
|
40
40
|
|
41
|
-
describe '
|
42
|
-
it {
|
41
|
+
describe 'Sanity check', :sanity => true do
|
42
|
+
it { atfyc.count.should == 142 }
|
43
|
+
|
44
|
+
it 'total travel percent should sum to 1' do
|
45
|
+
atfyc.group([:type_name, :fuel_family, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
|
46
|
+
total.should be_within(1e-5).of(1.0)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it { atfyc.where(:type_fuel_control_name => nil).count.should == 0 }
|
43
51
|
end
|
44
52
|
end
|
@@ -1,25 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year"
|
3
|
+
require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year_control"
|
3
4
|
|
4
5
|
describe AutomobileTypeFuelYear, :data_miner => true do
|
5
|
-
let(:
|
6
|
+
let(:atfy) { AutomobileTypeFuelYear }
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
describe '.find_by_type_name_and_fuel_family_and_closest_year' do
|
9
|
+
it "should return the ATFY from the closest year" do
|
10
|
+
cars_1984 = FactoryGirl.create :atfy, :cars_1984
|
11
|
+
cars_2009 = FactoryGirl.create :atfy, :cars_2009
|
12
|
+
cars_2011 = FactoryGirl.create :atfy, :cars_2011
|
13
|
+
|
14
|
+
atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 1970).should == cars_1984
|
15
|
+
atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2009).should == cars_2009
|
16
|
+
atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2012).should == cars_2011
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#type_fuel_year_controls' do
|
21
|
+
it "should return the controls from the closest year" do
|
22
|
+
FactoryGirl.create :atfyc, :cars_1985_1
|
23
|
+
FactoryGirl.create :atfyc, :cars_2009_1
|
24
|
+
FactoryGirl.create :atfyc, :cars_2009_2
|
25
|
+
FactoryGirl.create :atfyc, :cars_2010_1
|
26
|
+
FactoryGirl.create :atfyc, :cars_2010_2
|
27
|
+
|
28
|
+
FactoryGirl.create(:atfy, :cars_1984).type_fuel_year_controls.first.year.should == 1985
|
29
|
+
FactoryGirl.create(:atfy, :cars_2009).type_fuel_year_controls.first.year.should == 2009
|
30
|
+
FactoryGirl.create(:atfy, :cars_2011).type_fuel_year_controls.first.year.should == 2010
|
31
|
+
end
|
9
32
|
end
|
10
33
|
|
11
|
-
describe '
|
12
|
-
|
34
|
+
describe 'Sanity check', :sanity => true do
|
35
|
+
let(:test_atfy) { atfy.where(:type_name => 'Passenger cars', :fuel_family => 'gasoline', :year => 2005).first }
|
36
|
+
|
37
|
+
it { atfy.count.should == 124 }
|
13
38
|
|
14
39
|
it 'shares should sum to 1' do
|
15
|
-
|
40
|
+
atfy.sum(:share_of_type, :group => [:type_name, :fuel_family]).each do |groupers, total|
|
16
41
|
total.should be_within(1e-2).of(1.0)
|
17
42
|
end
|
18
43
|
end
|
19
44
|
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
45
|
+
it { atfy.where("annual_distance > 0").count.should == atfy.count }
|
46
|
+
it { atfy.where("ch4_emission_factor > 0").count.should == atfy.count }
|
47
|
+
it { atfy.where("n2o_emission_factor > 0").count.should == atfy.count }
|
23
48
|
|
24
49
|
# spot checks
|
25
50
|
it { test_atfy.annual_distance.should be_within(0.05).of(19598.6) }
|
@@ -29,30 +54,4 @@ describe AutomobileTypeFuelYear, :data_miner => true do
|
|
29
54
|
it { test_atfy.n2o_emission_factor.should be_within(5e-6).of(0.00147) }
|
30
55
|
it { test_atfy.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
|
31
56
|
end
|
32
|
-
|
33
|
-
describe '.find_by_type_name_and_fuel_family_and_closest_year' do
|
34
|
-
it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 1970).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 1979) }
|
35
|
-
it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2005).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2005) }
|
36
|
-
it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2012).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2009) }
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#type_fuel_year_controls' do
|
40
|
-
it "should find controls from 1985 when year < 1985" do
|
41
|
-
ATFY.where("year < 1985").each do |atfy|
|
42
|
-
atfy.type_fuel_year_controls.first.year.should == 1985
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should find controls from year when year from 1985 to 2010" do
|
47
|
-
ATFY.where("year >= 1985 AND year <= 2010").each do |atfy|
|
48
|
-
atfy.type_fuel_year_controls.first.year.should == atfy.year
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should find controls from 2010 when year > 2010" do
|
53
|
-
ATFY.where("year > 2010").each do |atfy|
|
54
|
-
atfy.type_fuel_year_controls.first.year.should == 2010
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
57
|
end
|
@@ -3,12 +3,14 @@ require 'earth/automobile/automobile_year'
|
|
3
3
|
|
4
4
|
describe AutomobileYear do
|
5
5
|
describe ".weighting(year)" do
|
6
|
-
pending 'test data factories'
|
7
|
-
|
8
6
|
(1985..2012).each do |year|
|
9
7
|
it "returns a weighting between 0 and 1 for #{year}" do
|
10
8
|
AutomobileYear.weighting(year).should > 0.0 and AutomobileYear.weighting(year).should < 1.0
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
12
|
+
|
13
|
+
describe 'Sanity check', :sanity => true do
|
14
|
+
it { AutomobileYear.count.should == 28 }
|
15
|
+
end
|
14
16
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'earth/bus/bus_fuel_control'
|
3
3
|
|
4
|
-
describe
|
5
|
-
describe '
|
6
|
-
it
|
7
|
-
BusFuelControl.count.should == 9
|
8
|
-
end
|
4
|
+
describe BusFuelControl do
|
5
|
+
describe 'Sanity check', :sanity => true do
|
6
|
+
it { BusFuelControl.count.should == 9 }
|
9
7
|
end
|
10
8
|
end
|
@@ -1,13 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require
|
2
|
+
require "#{Earth::FACTORY_DIR}/bus_fuel"
|
3
|
+
require "#{Earth::FACTORY_DIR}/bus_fuel_year_control"
|
3
4
|
|
4
|
-
describe
|
5
|
-
describe '
|
6
|
-
it '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
describe BusFuel do
|
6
|
+
describe '#latest_fuel_year_controls' do
|
7
|
+
it 'returns the latest fuel year controls' do
|
8
|
+
FactoryGirl.create :bfyc, :gas_2009_1
|
9
|
+
a = FactoryGirl.create :bfyc, :gas_2010_1
|
10
|
+
b = FactoryGirl.create :bfyc, :gas_2010_2
|
11
|
+
gas = FactoryGirl.create :bus_fuel, :gas
|
12
|
+
gas.latest_fuel_year_controls.should == [a,b]
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
16
|
+
describe 'Sanity check', :sanity => true do
|
17
|
+
it { BusFuel.count.should == 7 }
|
18
|
+
|
19
|
+
# FIXME TODO more sanity checks
|
20
|
+
end
|
13
21
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'earth/bus/bus_fuel_year_control'
|
3
3
|
|
4
|
-
describe
|
5
|
-
describe '
|
6
|
-
it
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
describe BusFuelYearControl do
|
5
|
+
describe 'Sanity check', :sanity => true do
|
6
|
+
it { BusFuelYearControl.count.should == 67 }
|
7
|
+
it 'total travel percent should sum to 1' do
|
8
|
+
BusFuelYearControl.group([:bus_fuel_name, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
|
9
|
+
total.should be_within(5e-2).of(1.0)
|
10
|
+
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|