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
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'earth/fuel'
|
2
|
-
# Not yet in use - for if we want to autocaculate size class stuf - November 10, 2011
|
3
|
-
class AutomobileSizeClassYear < ActiveRecord::Base
|
4
|
-
self.primary_key = "name"
|
5
|
-
|
6
|
-
col :name
|
7
|
-
col :size_class_name
|
8
|
-
col :year, :type => :integer
|
9
|
-
col :type_name
|
10
|
-
col :fuel_efficiency_city, :type => :float
|
11
|
-
col :fuel_efficiency_city_units
|
12
|
-
col :fuel_efficiency_highway, :type => :float
|
13
|
-
col :fuel_efficiency_highway_units
|
14
|
-
|
15
|
-
# verify "Year should be from 1975 to 2010" do
|
16
|
-
# AutomobileSizeClassYear.all.each do |record|
|
17
|
-
# unless record.year > 1974 and record.year < 2011
|
18
|
-
# raise "Invalid year for AutomobileSizeClassYear #{record.name}: #{record.year} (should be from 1975 to 2010)"
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# verify "Fuel efficiencies should be greater than zero" do
|
24
|
-
# AutomobileSizeClassYear.all.each do |year|
|
25
|
-
# %w{ fuel_efficiency_city fuel_efficiency_highway }.each do |attribute|
|
26
|
-
# value = year.send(:"#{attribute}")
|
27
|
-
# unless value > 0
|
28
|
-
# raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be > 0)"
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# verify "Fuel efficiency units should be kilometres per litre" do
|
35
|
-
# AutomobileSizeClassYear.all.each do |year|
|
36
|
-
# %w{ fuel_efficiency_city_units fuel_efficiency_highway_units }.each do |attribute|
|
37
|
-
# value = year.send(:"#{attribute}")
|
38
|
-
# unless value == "kilometres_per_litre"
|
39
|
-
# raise "Invalid #{attribute} for AutomobileSizeClassYear #{year.name}: #{value} (should be kilometres_per_litre)"
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'earth/fuel/data_miner'
|
2
|
-
# Not yet in use - for if we want to autocaculate size class stuf - November 10, 2011
|
3
|
-
AutomobileSizeClassYear.class_eval do
|
4
|
-
data_miner do
|
5
|
-
import "automobile size class year fuel efficiencies from the 2010 EPA Fuel Economy Trends report",
|
6
|
-
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDZOLWdDdlZja04xZkJYc3NjeGxQamc&hl=en&gid=0&output=csv' do
|
7
|
-
key 'name'
|
8
|
-
store 'size_class_name'
|
9
|
-
store 'year'
|
10
|
-
store 'type_name'
|
11
|
-
store 'fuel_efficiency_city', :units_field_name => 'fuel_efficiency_city_units'
|
12
|
-
store 'fuel_efficiency_highway', :units_field_name => 'fuel_efficiency_highway_units'
|
13
|
-
end
|
14
|
-
|
15
|
-
# FIXME TODO verify that size_class_name is never missing?
|
16
|
-
# FIXME TODO verify that type_name appears in AutomobileTypeFuelYearAges
|
17
|
-
end
|
18
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'earth/fuel'
|
2
|
-
class AutomobileTypeFuelYearAge < ActiveRecord::Base
|
3
|
-
self.primary_key = "name"
|
4
|
-
|
5
|
-
col :name
|
6
|
-
col :type_name
|
7
|
-
col :fuel_common_name
|
8
|
-
col :year, :type => :integer
|
9
|
-
col :age, :type => :integer
|
10
|
-
col :total_travel_percent, :type => :float
|
11
|
-
col :annual_distance, :type => :float
|
12
|
-
col :annual_distance_units
|
13
|
-
col :vehicles, :type => :integer
|
14
|
-
|
15
|
-
# %w{ type_name fuel_common_name type_fuel_year_name}.each do |attribute|
|
16
|
-
# verify "#{attribute.humanize} should never be missing" do
|
17
|
-
# AutomobileTypeFuelYearAge.all.each do |record|
|
18
|
-
# value = record.send(:"#{attribute}")
|
19
|
-
# unless value.present?
|
20
|
-
# raise "Missing #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}'"
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# verify "Year should be 2008" do
|
27
|
-
# AutomobileTypeFuelYearAge.all.each do |record|
|
28
|
-
# value = record.send(:year)
|
29
|
-
# unless value == 2008
|
30
|
-
# raise "Invalid year for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be 2008)"
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# [["age", 0, 30], ["total_travel_percent", 0, 1]].each do |triplet|
|
36
|
-
# attribute = triplet[0]
|
37
|
-
# min = triplet[1]
|
38
|
-
# max = triplet[2]
|
39
|
-
# verify "#{attribute.humanize} should be from #{min} to #{max}" do
|
40
|
-
# AutomobileTypeFuelYearAge.all.each do |record|
|
41
|
-
# value = record.send(:"#{attribute}")
|
42
|
-
# unless value >= min and value <= max
|
43
|
-
# raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be from #{min} to #{max})"
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# %w{ annual_distance vehicles }.each do |attribute|
|
50
|
-
# verify "#{attribute.humanize} should be greater than zero" do
|
51
|
-
# AutomobileTypeFuelYearAge.all.each do |record|
|
52
|
-
# value = record.send(:"#{attribute}")
|
53
|
-
# unless value > 0
|
54
|
-
# raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeFuelYearAge '#{record.name}': #{value} (should be > 0)"
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# verify "Annual distance units should be kilometres" do
|
61
|
-
# AutomobileTypeFuelYearAge.all.each do |record|
|
62
|
-
# units = record.send(:annual_distance_units)
|
63
|
-
# unless units == "kilometres"
|
64
|
-
# raise "Invalid annual distance units for AutomobileTypeFuelYearAge '#{record.name}': #{units} (should be kilometres)"
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'earth/fuel/data_miner'
|
2
|
-
AutomobileTypeFuelYearAge.class_eval do
|
3
|
-
data_miner do
|
4
|
-
import "total travel distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
|
5
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
6
|
-
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
7
|
-
:skip => 1,
|
8
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
9
|
-
key 'name', :synthesize => proc { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
|
10
|
-
store 'type_name', :static => 'Passenger cars'
|
11
|
-
store 'fuel_common_name', :static => 'gasoline'
|
12
|
-
store 'year', :static => '2008'
|
13
|
-
store 'age', :field_name => 'Vehicle Age'
|
14
|
-
store 'total_travel_percent', :synthesize => proc { |row| row['LDGV'].to_f / 100 }
|
15
|
-
end
|
16
|
-
|
17
|
-
import "total travel distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
18
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
19
|
-
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
20
|
-
:skip => 1,
|
21
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
22
|
-
key 'name', :synthesize => proc { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
|
23
|
-
store 'type_name', :static => 'Light-duty trucks'
|
24
|
-
store 'fuel_common_name', :static => 'gasoline'
|
25
|
-
store 'year', :static => '2008'
|
26
|
-
store 'age', :field_name => 'Vehicle Age'
|
27
|
-
store 'total_travel_percent', :synthesize => proc { |row| row['LDGT'].to_f / 100 }
|
28
|
-
end
|
29
|
-
|
30
|
-
import "total travel distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
|
31
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
32
|
-
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
33
|
-
:skip => 1,
|
34
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
35
|
-
key 'name', :synthesize => proc { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
|
36
|
-
store 'type_name', :static => 'Passenger cars'
|
37
|
-
store 'fuel_common_name', :static => 'diesel'
|
38
|
-
store 'year', :static => '2008'
|
39
|
-
store 'age', :field_name => 'Vehicle Age'
|
40
|
-
store 'total_travel_percent', :synthesize => proc { |row| row['LDDV'].to_f / 100 }
|
41
|
-
end
|
42
|
-
|
43
|
-
import "total travel distribution of diesel light-duty trucks from the 2010 EPA GHG Inventory",
|
44
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
45
|
-
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
46
|
-
:skip => 1,
|
47
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
48
|
-
key 'name', :synthesize => proc { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
|
49
|
-
store 'type_name', :static => 'Light-duty trucks'
|
50
|
-
store 'fuel_common_name', :static => 'diesel'
|
51
|
-
store 'year', :static => '2008'
|
52
|
-
store 'age', :field_name => 'Vehicle Age'
|
53
|
-
store 'total_travel_percent', :synthesize => proc { |row| row['LDDT'].to_f / 100 }
|
54
|
-
end
|
55
|
-
|
56
|
-
import "average annual distance for gasoline passenger cars from the 2010 EPA GHG Inventory",
|
57
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
58
|
-
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
59
|
-
:skip => 1,
|
60
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
61
|
-
key 'name', :synthesize => proc { |row| "Passenger cars gasoline 2008 age #{row['Vehicle Age']}" }
|
62
|
-
store 'annual_distance', :synthesize => proc { |row| row['LDGV'].to_s.sub(',', '') }, :units => :miles
|
63
|
-
end
|
64
|
-
|
65
|
-
import "average annual distance for gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
66
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
67
|
-
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
68
|
-
:skip => 1,
|
69
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
70
|
-
key 'name', :synthesize => proc { |row| "Light-duty trucks gasoline 2008 age #{row['Vehicle Age']}" }
|
71
|
-
store 'annual_distance', :synthesize => proc { |row| row['LDGT'].to_s.sub(',', '') }, :units => :miles
|
72
|
-
end
|
73
|
-
|
74
|
-
import "average annual distance for diesel passenger cars from the 2010 EPA GHG Inventory",
|
75
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
76
|
-
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
77
|
-
:skip => 1,
|
78
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
79
|
-
key 'name', :synthesize => proc { |row| "Passenger cars diesel 2008 age #{row['Vehicle Age']}" }
|
80
|
-
store 'annual_distance', :synthesize => proc { |row| row['LDDV'].to_s.sub(',', '') }, :units => :miles
|
81
|
-
end
|
82
|
-
|
83
|
-
import "average annual distance for diesel light-duty trucks from the 2010 EPA GHG Inventory",
|
84
|
-
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
85
|
-
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
86
|
-
:skip => 1,
|
87
|
-
:select => proc { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
|
88
|
-
key 'name', :synthesize => proc { |row| "Light-duty trucks diesel 2008 age #{row['Vehicle Age']}" }
|
89
|
-
store 'annual_distance', :synthesize => proc { |row| row['LDDT'].to_s.sub(',', '') }, :units => :miles
|
90
|
-
end
|
91
|
-
|
92
|
-
process "Convert annual distance from miles to kilometres" do
|
93
|
-
conversion_factor = 1.miles.to(:kilometres)
|
94
|
-
where(:annual_distance_units => 'miles').update_all(%{
|
95
|
-
annual_distance = 1.0 * annual_distance * #{conversion_factor},
|
96
|
-
annual_distance_units = 'kilometres'
|
97
|
-
})
|
98
|
-
end
|
99
|
-
|
100
|
-
process "Ensure AutomobileTypeFuelYear is populated" do
|
101
|
-
AutomobileTypeFuelYear.run_data_miner!
|
102
|
-
end
|
103
|
-
|
104
|
-
process "Calculate number of vehicles from total travel percent and AutomobileTypeFuelYear" do
|
105
|
-
total_travel = %{
|
106
|
-
SELECT t1.total_travel
|
107
|
-
FROM #{AutomobileTypeFuelYear.quoted_table_name} AS t1
|
108
|
-
WHERE
|
109
|
-
t1.type_name = #{quoted_table_name}.type_name
|
110
|
-
AND t1.fuel_common_name = #{quoted_table_name}.fuel_common_name
|
111
|
-
AND t1.year = #{quoted_table_name}.year
|
112
|
-
}
|
113
|
-
where("annual_distance > 0").update_all "vehicles = 1.0 * total_travel_percent * (#{total_travel}) / annual_distance"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'earth/fuel'
|
2
|
-
class AutomobileTypeYear < ActiveRecord::Base
|
3
|
-
self.primary_key = "name"
|
4
|
-
|
5
|
-
# FIXME TODO keep this until fix AutomobileFuel fallback hfc emission factor so that it doesn't call type_year.type_fuel_year
|
6
|
-
has_many :type_fuel_years, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_year_name'
|
7
|
-
|
8
|
-
col :name
|
9
|
-
col :type_name
|
10
|
-
col :year, :type => :integer
|
11
|
-
col :hfc_emissions, :type => :float
|
12
|
-
col :hfc_emissions_units
|
13
|
-
col :hfc_emission_factor, :type => :float
|
14
|
-
col :hfc_emission_factor_units
|
15
|
-
|
16
|
-
# verify "Type name should never be missing" do
|
17
|
-
# AutomobileTypeYear.all.each do |record|
|
18
|
-
# value = record.send(:type_name)
|
19
|
-
# unless value.present?
|
20
|
-
# raise "Missing type name for AutomobileTypeYear '#{record.name}'"
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# verify "Year should be from 1990 to 2008" do
|
26
|
-
# AutomobileTypeYear.all.each do |record|
|
27
|
-
# year = record.send(:year)
|
28
|
-
# unless year > 1989 and year < 2009
|
29
|
-
# raise "Invalid year for AutomobileTypeYear '#{record.name}': #{year} (should be from 1990 to 2008)"
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# %w{ hfc_emissions hfc_emission_factor }.each do |attribute|
|
35
|
-
# verify "#{attribute.humanize} should be zero or more" do
|
36
|
-
# AutomobileTypeYear.all.each do |record|
|
37
|
-
# value = record.send(:"#{attribute}")
|
38
|
-
# unless value >= 0
|
39
|
-
# raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{value} (should be zero or more)"
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# [["hfc_emissions_units", "kilograms_co2e"], ["hfc_emission_factor_units", "kilograms_co2e_per_litre"]].each do |pair|
|
46
|
-
# attribute = pair[0]
|
47
|
-
# proper_units = pair[1]
|
48
|
-
# verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
|
49
|
-
# AutomobileTypeYear.all.each do |record|
|
50
|
-
# units = record.send(:"#{attribute}")
|
51
|
-
# unless units == proper_units
|
52
|
-
# raise "Invalid #{attribute.humanize.downcase} for AutomobileTypeYear '#{record.name}': #{units} (should be #{proper_units})"
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
|
58
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'earth/fuel/data_miner'
|
2
|
-
AutomobileTypeYear.class_eval do
|
3
|
-
data_miner do
|
4
|
-
import "automobile type year air conditioning emissions derived from the 2010 EPA GHG Inventory",
|
5
|
-
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFoyTWhDeHpndTV5Ny1aX0sxR1ljSFE&hl=en&gid=0&output=csv' do
|
6
|
-
key 'name'
|
7
|
-
store 'type_name'
|
8
|
-
store 'year'
|
9
|
-
store 'hfc_emissions', :units_field_name => 'hfc_emissions_units'
|
10
|
-
end
|
11
|
-
|
12
|
-
process "Ensure AutomobileTypeFuelYear is populated" do
|
13
|
-
AutomobileTypeFuelYear.run_data_miner!
|
14
|
-
end
|
15
|
-
|
16
|
-
process "Calculate HFC emission factor from AutomobileTypeFuelYear" do
|
17
|
-
total_fuel_consumption = %{
|
18
|
-
SELECT SUM(src.fuel_consumption)
|
19
|
-
FROM #{AutomobileTypeFuelYear.quoted_table_name} AS src
|
20
|
-
WHERE
|
21
|
-
src.type_name = #{quoted_table_name}.type_name
|
22
|
-
AND src.year = #{quoted_table_name}.year
|
23
|
-
}
|
24
|
-
where("(#{total_fuel_consumption}) > 0").update_all(%{
|
25
|
-
hfc_emission_factor = 1.0 * hfc_emissions / (#{total_fuel_consumption}),
|
26
|
-
hfc_emission_factor_units = 'kilograms_co2e_per_litre'
|
27
|
-
})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'earth/automobile/automobile_type_fuel_year_age'
|
3
|
-
|
4
|
-
describe AutomobileTypeFuelYearAge do
|
5
|
-
describe 'import', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => :true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'imports and processes data successfully' do
|
11
|
-
AutomobileTypeFuelYearAge.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'verify imported data', :sanity => true do
|
16
|
-
it 'should have all the data' do
|
17
|
-
AutomobileTypeFuelYearAge.count.should == 124
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|