earth 0.7.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/certification_changelog.markdown +21 -0
  2. data/lib/earth/air.rb +0 -2
  3. data/lib/earth/air/aircraft.rb +77 -27
  4. data/lib/earth/air/aircraft/data_miner.rb +12 -19
  5. data/lib/earth/air/aircraft_instance.rb +2 -0
  6. data/lib/earth/air/aircraft_instance_seat_class.rb +1 -0
  7. data/lib/earth/air/airport/data_miner.rb +1 -1
  8. data/lib/earth/air/data_miner.rb +0 -2
  9. data/lib/earth/air/flight_distance_class.rb +2 -3
  10. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -13
  11. data/lib/earth/air/flight_distance_class_seat_class.rb +3 -2
  12. data/lib/earth/air/flight_seat_class.rb +0 -6
  13. data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
  14. data/lib/earth/air/flight_segment.rb +47 -53
  15. data/lib/earth/air/flight_segment/data_miner.rb +2 -2
  16. data/lib/earth/automobile.rb +4 -3
  17. data/lib/earth/automobile/automobile_fuel.rb +56 -119
  18. data/lib/earth/automobile/automobile_fuel/data_miner.rb +17 -4
  19. data/lib/earth/automobile/automobile_make.rb +1 -16
  20. data/lib/earth/automobile/automobile_make/data_miner.rb +25 -25
  21. data/lib/earth/automobile/automobile_make_model.rb +0 -26
  22. data/lib/earth/automobile/automobile_make_model/data_miner.rb +12 -13
  23. data/lib/earth/automobile/automobile_make_model_year.rb +6 -37
  24. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +34 -18
  25. data/lib/earth/automobile/automobile_make_model_year_variant.rb +27 -49
  26. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +111 -140
  27. data/lib/earth/automobile/automobile_make_year.rb +0 -12
  28. data/lib/earth/automobile/automobile_make_year/data_miner.rb +22 -23
  29. data/lib/earth/automobile/automobile_make_year_fleet.rb +11 -0
  30. data/lib/earth/automobile/{automobile_make_fleet_year → automobile_make_year_fleet}/data_miner.rb +1 -2
  31. data/lib/earth/automobile/automobile_model.rb +5 -0
  32. data/lib/earth/automobile/automobile_model/data_miner.rb +19 -0
  33. data/lib/earth/automobile/automobile_size_class.rb +1 -0
  34. data/lib/earth/automobile/automobile_size_class/data_miner.rb +30 -4
  35. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
  36. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +30 -19
  37. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +0 -3
  38. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +13 -15
  39. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +0 -4
  40. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -8
  41. data/lib/earth/automobile/automobile_type_year.rb +2 -1
  42. data/lib/earth/automobile/automobile_type_year/data_miner.rb +12 -10
  43. data/lib/earth/automobile/automobile_year.rb +5 -0
  44. data/lib/earth/automobile/automobile_year/data_miner.rb +15 -0
  45. data/lib/earth/automobile/data_miner.rb +5 -3
  46. data/lib/earth/automobile/dependencies.txt +45 -0
  47. data/lib/earth/bus/bus_class.rb +1 -87
  48. data/lib/earth/bus/bus_class/data_miner.rb +0 -1
  49. data/lib/earth/bus/bus_fuel/data_miner.rb +12 -19
  50. data/lib/earth/bus/bus_fuel_control/data_miner.rb +8 -12
  51. data/lib/earth/conversions_ext.rb +1 -0
  52. data/lib/earth/fuel/fuel/data_miner.rb +28 -38
  53. data/lib/earth/fuel/fuel_year/data_miner.rb +36 -47
  54. data/lib/earth/hospitality/lodging_class/data_miner.rb +12 -6
  55. data/lib/earth/locality.rb +1 -0
  56. data/lib/earth/locality/country.rb +1 -1
  57. data/lib/earth/locality/country/data_miner.rb +36 -28
  58. data/lib/earth/locality/data_miner.rb +1 -0
  59. data/lib/earth/locality/egrid_subregion/data_miner.rb +19 -14
  60. data/lib/earth/locality/urbanity/data_miner.rb +1 -3
  61. data/lib/earth/locality/zip_code/data_miner.rb +1 -1
  62. data/lib/earth/rail/national_transit_database_record/data_miner.rb +10 -14
  63. data/lib/earth/rail/rail_fuel.rb +2 -6
  64. data/lib/earth/residence/air_conditioner_use/data_miner.rb +1 -3
  65. data/lib/earth/residence/clothes_machine_use/data_miner.rb +1 -3
  66. data/lib/earth/residence/dishwasher_use/data_miner.rb +1 -3
  67. data/lib/earth/residence/residence_class/data_miner.rb +1 -3
  68. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +3 -1
  69. data/lib/earth/utils.rb +15 -5
  70. data/lib/earth/version.rb +1 -1
  71. data/spec/earth_spec.rb +4 -4
  72. metadata +9 -11
  73. data/features/automobile_type_fuel_age.feature +0 -55
  74. data/lib/earth/air/aircraft_class.rb +0 -59
  75. data/lib/earth/air/aircraft_class/data_miner.rb +0 -14
  76. data/lib/earth/air/aircraft_fuel_use_equation.rb +0 -33
  77. data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
  78. data/lib/earth/automobile/automobile_make_fleet_year.rb +0 -46
  79. data/lib/earth/automobile/automobile_type_fuel_age.rb +0 -65
  80. data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -149
@@ -1,55 +0,0 @@
1
- # # DEPRECATED - use AutomobileTypeFuelYearAge
2
- # Feature: Data import for AutomobileTypeFuelAge
3
- # As a data user
4
- # I want to import AutomobileTypeFuelAge data
5
- # So that I can perform type fuel age-based calculations
6
- #
7
- # Scenario: Successfully verifying that type name and fuel common name are not missing
8
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_good"
9
- # When a data import verifies "Type name and fuel common name should never be missing"
10
- # Then the verification should be successful
11
- #
12
- # Scenario: Successfully verifying that age is from zero to thirty
13
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_good"
14
- # When a data import verifies "Age should be from zero to thirty"
15
- # Then the verification should be successful
16
- #
17
- # Scenario: Successfully verifying that age percent and total travel percent are from zero to one
18
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_good"
19
- # When a data import verifies "Age percent and total travel percent should be from zero to one"
20
- # Then the verification should be successful
21
- #
22
- # Scenario: Successfully verifying that annual distance and vehicles are greater than zero
23
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_good"
24
- # When a data import verifies "Annual distance and vehicles should be greater than zero"
25
- # Then the verification should be successful
26
- #
27
- # Scenario: Successfully verifying that annual distance units are kilometres
28
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_good"
29
- # When a data import verifies "Annual distance units should be kilometres"
30
- # Then the verification should be successful
31
- #
32
- # Scenario: Failing to verify that type name and fuel common name are not missing
33
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_bad"
34
- # When a data import verifies "Type name and fuel common name should never be missing"
35
- # Then the verification should not be successful
36
- #
37
- # Scenario: Failing to verify that age is from zero to thirty
38
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_bad"
39
- # When a data import verifies "Age should be from zero to thirty"
40
- # Then the verification should not be successful
41
- #
42
- # Scenario: Failing to verify that age percent and total travel percent are from zero to one
43
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_bad"
44
- # When a data import verifies "Age percent and total travel percent should be from zero to one"
45
- # Then the verification should not be successful
46
- #
47
- # Scenario: Failing to verify that annual distance and vehicles are greater than zero
48
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_bad"
49
- # When a data import verifies "Annual distance and vehicles should be greater than zero"
50
- # Then the verification should not be successful
51
- #
52
- # Scenario: Failing to verify that annual distance units are kilometres
53
- # Given a "AutomobileTypeFuelAge" data import fetches results listed in "automobile_type_fuel_age_bad"
54
- # When a data import verifies "Annual distance units should be kilometres"
55
- # Then the verification should not be successful
@@ -1,59 +0,0 @@
1
- class AircraftClass < ActiveRecord::Base
2
- set_primary_key :code
3
-
4
- has_many :aircraft, :foreign_key => 'class_code', :primary_key => 'code'
5
-
6
- col :code
7
- col :m3, :type => :float
8
- col :m3_units
9
- col :m2, :type => :float
10
- col :m2_units
11
- col :m1, :type => :float
12
- col :m1_units
13
- col :b, :type => :float
14
- col :b_units
15
- col :seats, :type => :float
16
-
17
- def fuel_use_coefficients
18
- [m3, m2, m1, b]
19
- end
20
-
21
- def valid_fuel_use_equation?
22
- fuel_use_coefficients.all?(&:present?) and fuel_use_coefficients.any?(&:nonzero?)
23
- end
24
-
25
- class << self
26
- def update_averages!
27
- Aircraft.run_data_miner!
28
- AircraftFuelUseEquation.run_data_miner!
29
- find_each do |aircraft_class|
30
- cumulative_passengers = 0
31
- aircraft_class.m3 = 0.0
32
- aircraft_class.m2 = 0.0
33
- aircraft_class.m1 = 0.0
34
- aircraft_class.b = 0.0
35
-
36
- aircraft_class.aircraft.where('passengers > 0 AND fuel_use_code IS NOT NULL').each do |a|
37
- cumulative_passengers += a.passengers
38
- aircraft_class.m3 += a.fuel_use_equation.m3 * a.passengers
39
- aircraft_class.m2 += a.fuel_use_equation.m2 * a.passengers
40
- aircraft_class.m1 += a.fuel_use_equation.m1 * a.passengers
41
- aircraft_class.b += a.fuel_use_equation.b * a.passengers
42
- end
43
-
44
- if cumulative_passengers > 0
45
- aircraft_class.m3 /= cumulative_passengers
46
- aircraft_class.m2 /= cumulative_passengers
47
- aircraft_class.m1 /= cumulative_passengers
48
- aircraft_class.b /= cumulative_passengers
49
- end
50
-
51
- aircraft_class.seats = aircraft_class.aircraft.weighted_average(:seats, :weighted_by => :passengers)
52
-
53
- aircraft_class.save!
54
- end
55
-
56
- update_all :m3_units => 'kilograms_per_cubic_nautical_mile', :m2_units => 'kilograms_per_square_nautical_mile', :m1_units => 'kilograms_per_nautical_mile', :b_units => 'kilograms'
57
- end
58
- end
59
- end
@@ -1,14 +0,0 @@
1
- AircraftClass.class_eval do
2
- data_miner do
3
- process "Derive aircraft classes from Aircraft" do
4
- Aircraft.run_data_miner!
5
- connection.select_values("SELECT DISTINCT class_code FROM aircraft WHERE class_code IS NOT NULL").each do |class_code|
6
- AircraftClass.find_or_create_by_code(class_code)
7
- end
8
- end
9
-
10
- process :update_averages!
11
-
12
- # FIXME TODO verify this
13
- end
14
- end
@@ -1,33 +0,0 @@
1
- class AircraftFuelUseEquation < ActiveRecord::Base
2
- set_primary_key :code
3
-
4
- has_many :aircraft, :foreign_key => 'fuel_use_code', :primary_key => 'code'
5
-
6
- falls_back_on :m3 => lambda { weighted_average(:m3, :weighted_by => [:aircraft, :passengers]) }, # 9.73423082858437e-08 r7110: 8.6540464368905e-8 r6972: 8.37e-8
7
- :m2 => lambda { weighted_average(:m2, :weighted_by => [:aircraft, :passengers]) }, # -0.000134350543484608 r7110: -0.00015337661447817 r6972: -4.09e-5
8
- :m1 => lambda { weighted_average(:m1, :weighted_by => [:aircraft, :passengers]) }, # 6.7728101555467 r7110: 4.7781966869412 r6972: 7.85
9
- :b => lambda { weighted_average(:b, :weighted_by => [:aircraft, :passengers]) }, # 1527.81790006167 r7110: 1065.3476555284 r6972: 1.72e3
10
- :m3_units => 'kilograms_per_cubic_nautical_mile',
11
- :m2_units => 'kilograms_per_square_nautical_mile',
12
- :m1_units => 'kilograms_per_nautical_mile',
13
- :b_units => 'kilograms'
14
-
15
- def fuel_use_coefficients
16
- [m3, m2, m1, b]
17
- end
18
-
19
- def valid_fuel_use_equation?
20
- fuel_use_coefficients.all?(&:present?) and fuel_use_coefficients.any?(&:nonzero?)
21
- end
22
-
23
- col :code
24
- col :aircraft_description
25
- col :m3, :type => :float
26
- col :m3_units
27
- col :m2, :type => :float
28
- col :m2_units
29
- col :m1, :type => :float
30
- col :m1_units
31
- col :b, :type => :float
32
- col :b_units
33
- end
@@ -1,13 +0,0 @@
1
- AircraftFuelUseEquation.class_eval do
2
- data_miner do
3
- import "aircraft fuel use equations derived from EMEP/EEA and ICAO",
4
- :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDltUVZVekVobEJPYlpFNUpWNkwyYXc&output=csv' do
5
- key 'code'
6
- store 'aircraft_description'
7
- store 'm3', :units_field_name => 'm3_units'
8
- store 'm2', :units_field_name => 'm2_units'
9
- store 'm1', :units_field_name => 'm1_units'
10
- store 'b', :units_field_name => 'b_units'
11
- end
12
- end
13
- end
@@ -1,46 +0,0 @@
1
- class AutomobileMakeFleetYear < ActiveRecord::Base
2
- set_primary_key :name
3
-
4
- belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
5
- belongs_to :make_year, :class_name => 'AutomobileMakeYear', :foreign_key => 'make_year_name'
6
-
7
- col :name
8
- col :make_year_name
9
- col :make_name
10
- col :fleet
11
- col :year, :type => :integer
12
- col :fuel_efficiency, :type => :float
13
- col :fuel_efficiency_units
14
- col :volume, :type => :integer
15
-
16
- # TODO convert to table_warnings
17
- # verify "Year should be from 1978 to 2011" do
18
- # connection.select_values("SELECT DISTINCT year FROM automobile_make_fleet_years").each do |year|
19
- # year = year.to_i
20
- # unless year > 1977 and year < 2012
21
- # raise "Invalid year in automobile_make_fleet_years: #{year} is not from 1978 to 2011"
22
- # end
23
- # end
24
- # end
25
- #
26
- # verify "Fuel efficiency and volume should be greater than zero" do
27
- # [:fuel_efficiency, :volume].each do |field|
28
- # if AutomobileMakeFleetYear.where(field => nil).any?
29
- # raise "Invalid #{field} in automobile_make_fleet_years: nil is not > 0"
30
- # else
31
- # min = AutomobileMakeFleetYear.minimum(field)
32
- # unless min > 0
33
- # raise "Invalid #{field} in automobile_make_fleet_years: #{min} is not > 0"
34
- # end
35
- # end
36
- # end
37
- # end
38
- #
39
- # verify "Fuel efficiency units should be kilometres per litre" do
40
- # connection.select_values("SELECT DISTINCT fuel_efficiency_units FROM automobile_make_fleet_years").each do |units|
41
- # unless units == "kilometres_per_litre"
42
- # raise "Invalid fuel efficiency units in automobile_make_fleet_years: #{units} is not 'kilometres_per_litre'"
43
- # end
44
- # end
45
- # end
46
- end
@@ -1,65 +0,0 @@
1
- # DEPRECATED - use AutomobileTypeFuelYearAge
2
- class AutomobileTypeFuelAge < ActiveRecord::Base
3
- set_primary_key :name
4
-
5
- col :name
6
- col :type_name
7
- col :fuel_common_name
8
- col :age, :type => :integer
9
- col :age_percent, :type => :float
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
- # verify "Type name and fuel common name should never be missing" do
16
- # AutomobileTypeFuelAge.all.each do |record|
17
- # %w{ type_name fuel_common_name }.each do |attribute|
18
- # value = record.send(:"#{attribute}")
19
- # unless value.present?
20
- # raise "Missing #{attribute} for AutomobileTypeFuelAge '#{record.name}'"
21
- # end
22
- # end
23
- # end
24
- # end
25
- #
26
- # verify "Age should be from zero to thirty" do
27
- # AutomobileTypeFuelAge.all.each do |record|
28
- # value = record.send(:age)
29
- # unless value >= 0 and value < 31
30
- # raise "Invalid age for AutomobileTypeFuelAge '#{record.name}': #{value} (should be from 0 to 30)"
31
- # end
32
- # end
33
- # end
34
- #
35
- # verify "Age percent and total travel percent should be from zero to one" do
36
- # AutomobileTypeFuelAge.all.each do |record|
37
- # %w{ age_percent total_travel_percent }.each do |attribute|
38
- # percent = record.send(:"#{attribute}")
39
- # unless percent > 0 and percent < 1
40
- # raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{percent} (should be from 0 to 1)"
41
- # end
42
- # end
43
- # end
44
- # end
45
- #
46
- # verify "Annual distance and vehicles should be greater than zero" do
47
- # AutomobileTypeFuelAge.all.each do |record|
48
- # %w{ annual_distance vehicles }.each do |attribute|
49
- # value = record.send(:"#{attribute}")
50
- # unless value > 0
51
- # raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{value} (should be > 0)"
52
- # end
53
- # end
54
- # end
55
- # end
56
- #
57
- # verify "Annual distance units should be kilometres" do
58
- # AutomobileTypeFuelAge.all.each do |record|
59
- # units = record.send(:annual_distance_units)
60
- # unless units == "kilometres"
61
- # raise "Invalid annual distance units for AutomobileTypeFuelAge '#{record.name}': #{units} (should be kilometres)"
62
- # end
63
- # end
64
- # end
65
- end
@@ -1,149 +0,0 @@
1
- # DEPRECATED - use AutomobileTypeFuelYearAge
2
- AutomobileTypeFuelAge.class_eval do
3
- data_miner do
4
- import "age 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-91.csv',
7
- :skip => 1,
8
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
9
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" }
10
- store 'type_name', :static => 'Passenger cars'
11
- store 'fuel_common_name', :static => 'gasoline'
12
- store 'age', :field_name => 'Vehicle Age'
13
- store 'age_percent', :synthesize => lambda { |row| row['LDGV'].to_f / 100 }
14
- end
15
-
16
- import "age distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
17
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
18
- :filename => 'Annex Tables/Annex 3/Table A-91.csv',
19
- :skip => 1,
20
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
21
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" }
22
- store 'type_name', :static => 'Light-duty trucks'
23
- store 'fuel_common_name', :static => 'gasoline'
24
- store 'age', :field_name => 'Vehicle Age'
25
- store 'age_percent', :synthesize => lambda { |row| row['LDGT'].to_f / 100 }
26
- end
27
-
28
- import "age distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
29
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
30
- :filename => 'Annex Tables/Annex 3/Table A-91.csv',
31
- :skip => 1,
32
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
33
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" }
34
- store 'type_name', :static => 'Passenger cars'
35
- store 'fuel_common_name', :static => 'diesel'
36
- store 'age', :field_name => 'Vehicle Age'
37
- store 'age_percent', :synthesize => lambda { |row| row['LDDV'].to_f / 100 }
38
- end
39
-
40
- import "age distribution of diesel light-duty trucks from the 2010 EPA GHG Inventory",
41
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
42
- :filename => 'Annex Tables/Annex 3/Table A-91.csv',
43
- :skip => 1,
44
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
45
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" }
46
- store 'type_name', :static => 'Light-duty trucks'
47
- store 'fuel_common_name', :static => 'diesel'
48
- store 'age', :field_name => 'Vehicle Age'
49
- store 'age_percent', :synthesize => lambda { |row| row['LDDT'].to_f / 100 }
50
- end
51
-
52
- import "total travel distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
53
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
54
- :filename => 'Annex Tables/Annex 3/Table A-93.csv',
55
- :skip => 1,
56
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
57
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" }
58
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDGV'].to_f / 100 }
59
- end
60
-
61
- import "total travel distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
62
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
63
- :filename => 'Annex Tables/Annex 3/Table A-93.csv',
64
- :skip => 1,
65
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
66
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" }
67
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDGT'].to_f / 100 }
68
- end
69
-
70
- import "total travel distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
71
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
72
- :filename => 'Annex Tables/Annex 3/Table A-93.csv',
73
- :skip => 1,
74
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
75
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" }
76
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDDV'].to_f / 100 }
77
- end
78
-
79
- import "total travel distribution of diesel light-duty trucks from the 2010 EPA GHG Inventory",
80
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
81
- :filename => 'Annex Tables/Annex 3/Table A-93.csv',
82
- :skip => 1,
83
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
84
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" }
85
- store 'total_travel_percent', :synthesize => lambda { |row| row['LDDT'].to_f / 100 }
86
- end
87
-
88
- import "average annual distance for gasoline passenger cars from the 2010 EPA GHG Inventory",
89
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
90
- :filename => 'Annex Tables/Annex 3/Table A-92.csv',
91
- :skip => 1,
92
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
93
- key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" }
94
- store 'annual_distance', :synthesize => lambda { |row| row['LDGV'].to_s.sub(',', '') }, :units => :miles
95
- end
96
-
97
- import "average annual distance for gasoline light-duty trucks from the 2010 EPA GHG Inventory",
98
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
99
- :filename => 'Annex Tables/Annex 3/Table A-92.csv',
100
- :skip => 1,
101
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
102
- key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" }
103
- store 'annual_distance', :synthesize => lambda { |row| row['LDGT'].to_s.sub(',', '') }, :units => :miles
104
- end
105
-
106
- import "average annual distance for diesel passenger cars from the 2010 EPA GHG Inventory",
107
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
108
- :filename => 'Annex Tables/Annex 3/Table A-92.csv',
109
- :skip => 1,
110
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
111
- key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" }
112
- store 'annual_distance', :synthesize => lambda { |row| row['LDDV'].to_s.sub(',', '') }, :units => :miles
113
- end
114
-
115
- import "average annual distance for diesel light-duty trucks from the 2010 EPA GHG Inventory",
116
- :url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
117
- :filename => 'Annex Tables/Annex 3/Table A-92.csv',
118
- :skip => 1,
119
- :select => lambda { |row| row['Vehicle Age'].to_i.to_s == row['Vehicle Age'] } do
120
- key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" }
121
- store 'annual_distance', :synthesize => lambda { |row| row['LDDT'].to_s.sub(',', '') }, :units => :miles
122
- end
123
-
124
- process "Convert annual distance from miles to kilometres" do
125
- conversion_factor = 1.miles.to(:kilometres)
126
- update_all "annual_distance = 1.0 * annual_distance * #{conversion_factor}"
127
- update_all "annual_distance_units = 'kilometres'"
128
- end
129
-
130
- process "Ensure AutomobileTypeFuelYear is populated" do
131
- AutomobileTypeFuelYear.run_data_miner!
132
- end
133
-
134
- # FIXME TODO maybe make this a method on AutomobileTypeFuelAge?
135
- process "Calculate number of vehicles from total travel percent and AutomobileTypeFuelYear" do
136
- max_year = AutomobileTypeFuelYear.maximum :year
137
- update_all %{
138
- vehicles =
139
- ( SELECT t1.total_travel
140
- FROM #{AutomobileTypeFuelYear.quoted_table_name} AS t1
141
- WHERE
142
- t1.year = #{max_year}
143
- AND t1.type_name = #{quoted_table_name}.type_name
144
- AND t1.fuel_common_name = #{quoted_table_name}.fuel_common_name )
145
- * 1.0 * #{quoted_table_name}.total_travel_percent / #{quoted_table_name}.annual_distance
146
- }
147
- end
148
- end
149
- end