earth 0.3.11 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -3
- data/features/automobile_fuel_type.feature +8 -18
- data/features/automobile_make_fleet_year.feature +4 -4
- data/features/automobile_make_model_year.feature +4 -4
- data/features/automobile_make_model_year_variant.feature +4 -4
- data/features/automobile_make_year.feature +4 -4
- data/features/automobile_size_class_year.feature +34 -0
- data/features/automobile_type_fuel_age.feature +54 -0
- data/features/automobile_type_fuel_control.feature +34 -0
- data/features/automobile_type_fuel_year.feature +54 -0
- data/features/automobile_type_fuel_year_control.feature +34 -0
- data/features/automobile_type_year.feature +44 -0
- data/features/computation_platform.feature +14 -0
- data/features/data_center_company.feature +14 -0
- data/features/egrid_region.feature +6 -0
- data/features/egrid_subregion.feature +4 -4
- data/features/flight_segment.feature +14 -0
- data/features/fuel_year.feature +44 -0
- data/features/greenhouse_gas.feature +44 -0
- data/features/server_type.feature +34 -0
- data/features/server_type_alias.feature +14 -0
- data/features/support/imports/automobile_make_fleet_year_bad.csv +1 -2
- data/features/support/imports/automobile_make_fleet_year_good.csv +1 -2
- data/features/support/imports/automobile_size_class_year_bad.csv +2 -0
- data/features/support/imports/automobile_size_class_year_good.csv +2 -0
- data/features/support/imports/automobile_type_fuel_age_bad.csv +3 -0
- data/features/support/imports/automobile_type_fuel_age_good.csv +3 -0
- data/features/support/imports/automobile_type_fuel_control_bad.csv +3 -0
- data/features/support/imports/automobile_type_fuel_control_good.csv +3 -0
- data/features/support/imports/automobile_type_fuel_year_bad.csv +2 -0
- data/features/support/imports/automobile_type_fuel_year_control_bad.csv +3 -0
- data/features/support/imports/automobile_type_fuel_year_control_good.csv +3 -0
- data/features/support/imports/automobile_type_fuel_year_good.csv +2 -0
- data/features/support/imports/automobile_type_year_bad.csv +2 -0
- data/features/support/imports/automobile_type_year_good.csv +2 -0
- data/features/support/imports/computation_platform_bad.csv +3 -0
- data/features/support/imports/computation_platform_good.csv +3 -0
- data/features/support/imports/data_center_company_bad.csv +3 -0
- data/features/support/imports/data_center_company_good.csv +3 -0
- data/features/support/imports/egrid_subregion_good.csv +2 -2
- data/features/support/imports/flight_segment_bad.csv +8 -0
- data/features/support/imports/flight_segment_good.csv +8 -0
- data/features/support/imports/fuel_year_bad.csv +2 -0
- data/features/support/imports/fuel_year_good.csv +2 -0
- data/features/support/imports/greenhouse_gas_bad.csv +2 -0
- data/features/support/imports/greenhouse_gas_good.csv +2 -0
- data/features/support/imports/server_type_alias_bad.csv +3 -0
- data/features/support/imports/server_type_alias_good.csv +3 -0
- data/features/support/imports/server_type_bad.csv +3 -0
- data/features/support/imports/server_type_good.csv +3 -0
- data/lib/earth/air/aircraft.rb +2 -3
- data/lib/earth/air/aircraft/data_miner.rb +2 -4
- data/lib/earth/air/aircraft_class/data_miner.rb +3 -1
- data/lib/earth/air/airport/data_miner.rb +4 -3
- data/lib/earth/air/flight_distance_class/data_miner.rb +2 -0
- data/lib/earth/air/flight_seat_class/data_miner.rb +4 -4
- data/lib/earth/air/flight_segment/data_miner.rb +7 -0
- data/lib/earth/all.rb +1 -0
- data/lib/earth/automobile.rb +6 -0
- data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +68 -25
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +5 -6
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -2
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +3 -4
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +14 -10
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +2 -2
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +28 -26
- data/lib/earth/automobile/automobile_size_class_year.rb +7 -0
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +56 -0
- data/lib/earth/automobile/automobile_type_fuel_age.rb +7 -0
- data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +195 -0
- data/lib/earth/automobile/automobile_type_fuel_control.rb +7 -0
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +57 -0
- data/lib/earth/automobile/automobile_type_fuel_year.rb +7 -0
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +164 -0
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -0
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +46 -0
- data/lib/earth/automobile/automobile_type_year.rb +7 -0
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +55 -0
- data/lib/earth/automobile/data_miner.rb +6 -0
- data/lib/earth/computation.rb +4 -0
- data/lib/earth/computation/computation_platform.rb +9 -0
- data/lib/earth/computation/computation_platform/data_miner.rb +24 -0
- data/lib/earth/computation/data_center_company.rb +7 -0
- data/lib/earth/computation/data_center_company/data_miner.rb +22 -0
- data/lib/earth/computation/data_miner.rb +4 -0
- data/lib/earth/computation/server_type.rb +9 -0
- data/lib/earth/computation/server_type/data_miner.rb +49 -0
- data/lib/earth/computation/server_type_alias.rb +10 -0
- data/lib/earth/computation/server_type_alias/data_miner.rb +30 -0
- data/lib/earth/data_miner.rb +1 -0
- data/lib/earth/fuel.rb +2 -0
- data/lib/earth/fuel/data_miner.rb +2 -0
- data/lib/earth/fuel/fuel_year.rb +7 -0
- data/lib/earth/fuel/fuel_year/data_miner.rb +76 -0
- data/lib/earth/fuel/greenhouse_gas.rb +7 -0
- data/lib/earth/fuel/greenhouse_gas/data_miner.rb +59 -0
- data/lib/earth/locality/country/data_miner.rb +1 -1
- data/lib/earth/locality/egrid_region/data_miner.rb +8 -0
- data/lib/earth/locality/egrid_subregion/data_miner.rb +3 -3
- data/lib/earth/locality/urbanity/data_miner.rb +2 -2
- data/lib/earth/locality/zip_code/data_miner.rb +2 -3
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +2 -2
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +3 -3
- data/lib/earth/residence/dishwasher_use/data_miner.rb +1 -1
- data/lib/earth/residence/residence_class/data_miner.rb +2 -2
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +4 -4
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +3 -4
- data/spec/earth_spec.rb +4 -5
- metadata +196 -81
@@ -0,0 +1,195 @@
|
|
1
|
+
AutomobileTypeFuelAge.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
string 'type_name'
|
6
|
+
string 'fuel_common_name'
|
7
|
+
integer 'age'
|
8
|
+
float 'age_percent'
|
9
|
+
float 'total_travel_percent'
|
10
|
+
float 'annual_distance'
|
11
|
+
string 'annual_distance_units'
|
12
|
+
integer 'vehicles'
|
13
|
+
end
|
14
|
+
|
15
|
+
import "age distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
|
16
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
17
|
+
:filename => 'Annex Tables/Annex 3/Table A-91.csv',
|
18
|
+
:skip => 1 do
|
19
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
20
|
+
store 'type_name', :static => 'Passenger cars'
|
21
|
+
store 'fuel_common_name', :static => 'gasoline'
|
22
|
+
store 'age', :field_name => 'Vehicle Age'
|
23
|
+
store 'age_percent', :synthesize => lambda { |row| row['LDGV'].to_f / 100 }
|
24
|
+
end
|
25
|
+
|
26
|
+
import "age distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
27
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
28
|
+
:filename => 'Annex Tables/Annex 3/Table A-91.csv',
|
29
|
+
:skip => 1 do
|
30
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
31
|
+
store 'type_name', :static => 'Light-duty trucks'
|
32
|
+
store 'fuel_common_name', :static => 'gasoline'
|
33
|
+
store 'age', :field_name => 'Vehicle Age'
|
34
|
+
store 'age_percent', :synthesize => lambda { |row| row['LDGT'].to_f / 100 }
|
35
|
+
end
|
36
|
+
|
37
|
+
import "age distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
|
38
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
39
|
+
:filename => 'Annex Tables/Annex 3/Table A-91.csv',
|
40
|
+
:skip => 1 do
|
41
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
42
|
+
store 'type_name', :static => 'Passenger cars'
|
43
|
+
store 'fuel_common_name', :static => 'diesel'
|
44
|
+
store 'age', :field_name => 'Vehicle Age'
|
45
|
+
store 'age_percent', :synthesize => lambda { |row| row['LDDV'].to_f / 100 }
|
46
|
+
end
|
47
|
+
|
48
|
+
import "age distribution of diesel light-duty trucks from the 2010 EPA GHG Inventory",
|
49
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
50
|
+
:filename => 'Annex Tables/Annex 3/Table A-91.csv',
|
51
|
+
:skip => 1 do
|
52
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
53
|
+
store 'type_name', :static => 'Light-duty trucks'
|
54
|
+
store 'fuel_common_name', :static => 'diesel'
|
55
|
+
store 'age', :field_name => 'Vehicle Age'
|
56
|
+
store 'age_percent', :synthesize => lambda { |row| row['LDDT'].to_f / 100 }
|
57
|
+
end
|
58
|
+
|
59
|
+
import "total travel distribution of gasoline passenger cars from the 2010 EPA GHG Inventory",
|
60
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
61
|
+
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
62
|
+
:skip => 1 do
|
63
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
64
|
+
store 'total_travel_percent', :synthesize => lambda { |row| row['LDGV'].to_f / 100 }
|
65
|
+
end
|
66
|
+
|
67
|
+
import "total travel distribution of gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
68
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
69
|
+
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
70
|
+
:skip => 1 do
|
71
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
72
|
+
store 'total_travel_percent', :synthesize => lambda { |row| row['LDGT'].to_f / 100 }
|
73
|
+
end
|
74
|
+
|
75
|
+
import "total travel distribution of diesel passenger cars from the 2010 EPA GHG Inventory",
|
76
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
77
|
+
:filename => 'Annex Tables/Annex 3/Table A-93.csv',
|
78
|
+
:skip => 1 do
|
79
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
80
|
+
store 'total_travel_percent', :synthesize => lambda { |row| row['LDDV'].to_f / 100 }
|
81
|
+
end
|
82
|
+
|
83
|
+
import "total travel distribution of 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-93.csv',
|
86
|
+
:skip => 1 do
|
87
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
88
|
+
store 'total_travel_percent', :synthesize => lambda { |row| row['LDDT'].to_f / 100 }
|
89
|
+
end
|
90
|
+
|
91
|
+
import "average annual distance for gasoline passenger cars from the 2010 EPA GHG Inventory",
|
92
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
93
|
+
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
94
|
+
:skip => 1 do
|
95
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
96
|
+
store 'annual_distance', :synthesize => lambda { |row| row['LDGV'].to_s.sub(',', '') }, :units => :miles
|
97
|
+
end
|
98
|
+
|
99
|
+
import "average annual distance for gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
100
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
101
|
+
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
102
|
+
:skip => 1 do
|
103
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
104
|
+
store 'annual_distance', :synthesize => lambda { |row| row['LDGT'].to_s.sub(',', '') }, :units => :miles
|
105
|
+
end
|
106
|
+
|
107
|
+
import "average annual distance for diesel passenger cars from the 2010 EPA GHG Inventory",
|
108
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
109
|
+
:filename => 'Annex Tables/Annex 3/Table A-92.csv',
|
110
|
+
:skip => 1 do
|
111
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
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 do
|
119
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel age #{row['Vehicle Age']}" if row['Vehicle Age'].length < 3 }
|
120
|
+
store 'annual_distance', :synthesize => lambda { |row| row['LDDT'].to_s.sub(',', '') }, :units => :miles
|
121
|
+
end
|
122
|
+
|
123
|
+
process "Convert annual distance from miles to kilometres" do
|
124
|
+
conversion_factor = 1.miles.to(:kilometres)
|
125
|
+
update_all "annual_distance = annual_distance * #{conversion_factor}"
|
126
|
+
update_all "annual_distance_units = 'kilometres'"
|
127
|
+
end
|
128
|
+
|
129
|
+
process "Calculate number of vehicles from total travel and total travel percent" do
|
130
|
+
AutomobileTypeFuelYear.run_data_miner!
|
131
|
+
connection.execute %{
|
132
|
+
UPDATE automobile_type_fuel_ages
|
133
|
+
SET automobile_type_fuel_ages.vehicles =
|
134
|
+
((SELECT automobile_type_fuel_years.total_travel
|
135
|
+
FROM automobile_type_fuel_years
|
136
|
+
WHERE automobile_type_fuel_years.year =
|
137
|
+
(SELECT max(automobile_type_fuel_years.year) FROM automobile_type_fuel_years)
|
138
|
+
AND automobile_type_fuel_years.type_name = automobile_type_fuel_ages.type_name
|
139
|
+
AND automobile_type_fuel_years.fuel_common_name = automobile_type_fuel_ages.fuel_common_name
|
140
|
+
) * automobile_type_fuel_ages.total_travel_percent / automobile_type_fuel_ages.annual_distance )
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
verify "Type name and fuel common name should never be missing" do
|
145
|
+
AutomobileTypeFuelAge.all.each do |record|
|
146
|
+
%w{ type_name fuel_common_name }.each do |attribute|
|
147
|
+
value = record.send(:"#{attribute}")
|
148
|
+
if value.nil?
|
149
|
+
raise "Missing #{attribute} for AutomobileTypeFuelAge '#{record.name}'"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
verify "Age should be from zero to thirty" do
|
156
|
+
AutomobileTypeFuelAge.all.each do |record|
|
157
|
+
value = record.send(:age)
|
158
|
+
unless value >= 0 and value < 31
|
159
|
+
raise "Invalid age for AutomobileTypeFuelAge '#{record.name}': #{value} (should be from 0 to 30)"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
verify "Age percent and total travel percent should be from zero to one" do
|
165
|
+
AutomobileTypeFuelAge.all.each do |record|
|
166
|
+
%w{ age_percent total_travel_percent }.each do |attribute|
|
167
|
+
percent = record.send(:"#{attribute}")
|
168
|
+
unless percent > 0 and percent < 1
|
169
|
+
raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{percent} (should be from 0 to 1)"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
verify "Annual distance and vehicles should be greater than zero" do
|
176
|
+
AutomobileTypeFuelAge.all.each do |record|
|
177
|
+
%w{ annual_distance vehicles }.each do |attribute|
|
178
|
+
value = record.send(:"#{attribute}")
|
179
|
+
unless value > 0
|
180
|
+
raise "Invalid #{attribute} for AutomobileTypeFuelAge '#{record.name}': #{value} (should be > 0)"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
verify "Annual distance units should be kilometres" do
|
187
|
+
AutomobileTypeFuelAge.all.each do |record|
|
188
|
+
units = record.send(:annual_distance_units)
|
189
|
+
unless units == "kilometres"
|
190
|
+
raise "Invalid annual distance units for AutomobileTypeFuelAge '#{record.name}': #{units} (should be kilometres)"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
AutomobileTypeFuelControl.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
string 'type_name'
|
6
|
+
string 'fuel_common_name'
|
7
|
+
string 'control_name'
|
8
|
+
float 'ch4_emission_factor'
|
9
|
+
string 'ch4_emission_factor_units'
|
10
|
+
float 'n2o_emission_factor'
|
11
|
+
string 'n2o_emission_factor_units'
|
12
|
+
end
|
13
|
+
|
14
|
+
import "automobile type fuel control data derived from the 2010 EPA GHG Inventory",
|
15
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEloSTU5YUNOUXRFRUcxWHlTUi1GMkE&hl=en&output=csv' do
|
16
|
+
key 'name'
|
17
|
+
store 'type_name'
|
18
|
+
store 'fuel_common_name'
|
19
|
+
store 'control_name'
|
20
|
+
store 'ch4_emission_factor', :units_field_name => 'ch4_emission_factor_units'
|
21
|
+
store 'n2o_emission_factor', :units_field_name => 'n2o_emission_factor_units'
|
22
|
+
end
|
23
|
+
|
24
|
+
verify "Type name, fuel common name, and control name should never be missing" do
|
25
|
+
AutomobileTypeFuelControl.all.each do |record|
|
26
|
+
%w{ type_name fuel_common_name control_name }.each do |attribute|
|
27
|
+
value = record.send(:"#{attribute}")
|
28
|
+
if value.nil?
|
29
|
+
raise "Missing #{attribute} for AutomobileTypeFuelControl '#{record.name}'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
verify "Emission factors should be greater than zero" do
|
36
|
+
AutomobileTypeFuelControl.all.each do |record|
|
37
|
+
%w{ ch4_emission_factor n2o_emission_factor }.each do |factor|
|
38
|
+
value = record.send(:"#{factor}")
|
39
|
+
unless value > 0
|
40
|
+
raise "Invalid #{factor} for AutomobileTypeFuelControl '#{record.name}': #{valuel} (should be > 0)"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
verify "Emission factor units should be kilograms per kilometre" do
|
47
|
+
AutomobileTypeFuelControl.all.each do |record|
|
48
|
+
%w{ ch4_emission_factor_units n2o_emission_factor_units }.each do |attribute|
|
49
|
+
units = record.send(:"#{attribute}")
|
50
|
+
unless units == "kilograms_per_kilometre"
|
51
|
+
raise "Invalid #{attribute} for AutomobileTypeFuelControl '#{record.name}': #{units} (should be kilograms_per_kilometre)"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
AutomobileTypeFuelYear.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
string 'type_name'
|
6
|
+
string 'fuel_common_name'
|
7
|
+
integer 'year'
|
8
|
+
float 'total_travel'
|
9
|
+
string 'total_travel_units'
|
10
|
+
float 'fuel_consumption'
|
11
|
+
string 'fuel_consumption_units'
|
12
|
+
float 'ch4_emission_factor'
|
13
|
+
string 'ch4_emission_factor_units'
|
14
|
+
float 'n2o_emission_factor'
|
15
|
+
string 'n2o_emission_factor_units'
|
16
|
+
float 'hfc_emission_factor'
|
17
|
+
string 'hfc_emission_factor_units'
|
18
|
+
end
|
19
|
+
|
20
|
+
import "total vehicle miles travelled by gasoline passenger cars from the 2010 EPA GHG Inventory",
|
21
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
22
|
+
:filename => 'Annex Tables/Annex 3/Table A-87.csv',
|
23
|
+
:skip => 1 do
|
24
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars gasoline #{row['Year']}" if row['Year'].length < 5 }
|
25
|
+
store 'type_name', :static => 'Passenger cars'
|
26
|
+
store 'fuel_common_name', :static => 'gasoline'
|
27
|
+
store 'year', :field_name => 'Year'
|
28
|
+
store 'total_travel', :field_name => 'Passenger Cars', :units => :billion_miles
|
29
|
+
end
|
30
|
+
|
31
|
+
import "total vehicle miles travelled by gasoline light-duty trucks from the 2010 EPA GHG Inventory",
|
32
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
33
|
+
:filename => 'Annex Tables/Annex 3/Table A-87.csv',
|
34
|
+
:skip => 1 do
|
35
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks gasoline #{row['Year']}" if row['Year'].length < 5 }
|
36
|
+
store 'type_name', :static => 'Light-duty trucks'
|
37
|
+
store 'fuel_common_name', :static => 'gasoline'
|
38
|
+
store 'year', :field_name => 'Year'
|
39
|
+
store 'total_travel', :field_name => 'Light-Duty Trucks', :units => :billion_miles
|
40
|
+
end
|
41
|
+
|
42
|
+
import "total vehicle miles travelled by diesel passenger cars from the 2010 EPA GHG Inventory",
|
43
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
44
|
+
:filename => 'Annex Tables/Annex 3/Table A-88.csv',
|
45
|
+
:skip => 1 do
|
46
|
+
key 'name', :synthesize => lambda { |row| "Passenger cars diesel #{row['Year']}" if row['Year'].length < 5 }
|
47
|
+
store 'type_name', :static => 'Passenger cars'
|
48
|
+
store 'fuel_common_name', :static => 'diesel'
|
49
|
+
store 'year', :field_name => 'Year'
|
50
|
+
store 'total_travel', :field_name => 'Passenger Cars', :units => :billion_miles
|
51
|
+
end
|
52
|
+
|
53
|
+
import "total vehicle miles travelled by diesel light-duty trucks from the 2010 EPA GHG Inventory",
|
54
|
+
:url => 'http://www.epa.gov/climatechange/emissions/downloads10/2010-Inventory-Annex-Tables.zip',
|
55
|
+
:filename => 'Annex Tables/Annex 3/Table A-88.csv',
|
56
|
+
:skip => 1 do
|
57
|
+
key 'name', :synthesize => lambda { |row| "Light-duty trucks diesel #{row['Year']}" if row['Year'].length < 5 }
|
58
|
+
store 'type_name', :static => 'Light-duty trucks'
|
59
|
+
store 'fuel_common_name', :static => 'diesel'
|
60
|
+
store 'year', :field_name => 'Year'
|
61
|
+
store 'total_travel', :field_name => 'Light-Duty Trucks', :units => :billion_miles
|
62
|
+
end
|
63
|
+
|
64
|
+
process "Convert total travel from billion miles to kilometres" do
|
65
|
+
conversion_factor = 1_000_000_000.miles.to(:kilometres)
|
66
|
+
update_all "total_travel = total_travel * #{conversion_factor}"
|
67
|
+
update_all "total_travel_units = 'kilometres'"
|
68
|
+
end
|
69
|
+
|
70
|
+
import "fuel consumption derived from the 2010 EPA GHG Inventory",
|
71
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHBCMFhLRTFTZENsd0dPUGUyYlJna0E&hl=en&output=csv' do
|
72
|
+
key 'name'
|
73
|
+
store 'fuel_consumption', :units_field_name => 'fuel_consumption_units'
|
74
|
+
end
|
75
|
+
|
76
|
+
process "Calculate CH4 and N2O emision factors from AutomobileTypeFuelYearControl and AutomobileTypeFuelControl" do
|
77
|
+
AutomobileTypeFuelYearControl.run_data_miner!
|
78
|
+
AutomobileTypeFuelControl.run_data_miner!
|
79
|
+
|
80
|
+
year_controls = AutomobileTypeFuelYearControl.arel_table
|
81
|
+
controls = AutomobileTypeFuelControl.arel_table
|
82
|
+
years = AutomobileTypeFuelYear.arel_table
|
83
|
+
|
84
|
+
join_relation = controls[:type_name].eq(year_controls[:type_name]).and(controls[:fuel_common_name].eq(year_controls[:fuel_common_name])).and(controls[:control_name].eq(year_controls[:control_name]))
|
85
|
+
where_relation = year_controls[:type_name].eq(years[:type_name]).and(year_controls[:fuel_common_name].eq(years[:fuel_common_name])).and(year_controls[:year].eq(years[:year]))
|
86
|
+
|
87
|
+
%w{ ch4 n2o }.each do |gas|
|
88
|
+
update_all "#{gas}_emission_factor = (
|
89
|
+
SELECT SUM(automobile_type_fuel_year_controls.total_travel_percent * automobile_type_fuel_controls.#{gas}_emission_factor)
|
90
|
+
FROM automobile_type_fuel_year_controls
|
91
|
+
INNER JOIN automobile_type_fuel_controls
|
92
|
+
ON #{join_relation.to_sql}
|
93
|
+
WHERE #{where_relation.to_sql}) * total_travel / fuel_consumption"
|
94
|
+
update_all "#{gas}_emission_factor_units = 'kilograms_per_litre'"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
process "Calculate HFC emission factor from AutomobileTypeYear" do
|
99
|
+
AutomobileTypeYear.run_data_miner!
|
100
|
+
type_fuel_years = AutomobileTypeFuelYear.arel_table
|
101
|
+
type_years = AutomobileTypeYear.arel_table
|
102
|
+
|
103
|
+
AutomobileTypeFuelYear.all.each do |record|
|
104
|
+
fuel_consumption = AutomobileTypeFuelYear.find_all_by_type_name_and_year(record.type_name, record.year).map{|x| x.fuel_consumption}.sum
|
105
|
+
hfc_emissions_sql = type_years.project(type_years[:hfc_emissions]).where(type_years[:type_name].eq(record.type_name).and(type_years[:year].eq(record.year))).to_sql
|
106
|
+
connection.execute "UPDATE automobile_type_fuel_years SET hfc_emission_factor = ((#{hfc_emissions_sql}) / #{fuel_consumption}) WHERE type_name = '#{record.type_name}' AND year = #{record.year}"
|
107
|
+
end
|
108
|
+
update_all "hfc_emission_factor_units = 'kilograms_co2e_per_litre'"
|
109
|
+
end
|
110
|
+
|
111
|
+
verify "Type name and fuel common name should never be missing" do
|
112
|
+
AutomobileTypeFuelYear.all.each do |record|
|
113
|
+
%w{ type_name fuel_common_name }.each do |attribute|
|
114
|
+
value = record.send(:"#{attribute}")
|
115
|
+
if value.nil?
|
116
|
+
raise "Missing #{attribute} for AutomobileTypeFuelYear '#{record.name}'"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
verify "Year should be from 1990 to 2008" do
|
123
|
+
AutomobileTypeFuelYear.all.each do |record|
|
124
|
+
year = record.send(:year)
|
125
|
+
unless year > 1989 and year < 2009
|
126
|
+
raise "Invalid year for AutomobileTypeFuelYear '#{record.name}': #{year} (should be from 1990 to 2008)"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
verify "Total travel, fuel consumption, and emission factors should be greater than zero" do
|
132
|
+
AutomobileTypeFuelYear.all.each do |record|
|
133
|
+
%w{ total_travel fuel_consumption ch4_emission_factor n2o_emission_factor }.each do |attribute|
|
134
|
+
value = record.send(:"#{attribute}")
|
135
|
+
unless value > 0
|
136
|
+
raise "Invalid #{attribute} for AutomobileTypeFuelYear '#{record.name}': #{value} (should be > 0)"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
verify "HFC emission factor should be zero or more" do
|
143
|
+
AutomobileTypeFuelYear.all.each do |record|
|
144
|
+
value = record.send(:hfc_emission_factor)
|
145
|
+
unless value >= 0
|
146
|
+
raise "Invalid HFC emission factor for AutomobileTypeFuelYear '#{record.name}': #{value} (should be >= 0)"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
verify "Units should be correct" do
|
152
|
+
AutomobileTypeFuelYear.all.each do |record|
|
153
|
+
["total_travel_units kilometres", "fuel_consumption_units litres", "ch4_emission_factor_units kilograms_per_litre", "n2o_emission_factor_units kilograms_per_litre", "hfc_emission_factor_units kilograms_co2e_per_litre"].each do |pair|
|
154
|
+
attribute = pair.split[0]
|
155
|
+
proper_units = pair.split[1]
|
156
|
+
units = record.send(:"#{attribute}")
|
157
|
+
unless units == proper_units
|
158
|
+
raise "Invalid #{attribute} for AutomobileTypeFuelYear '#{record.name}': #{units} (should be #{proper_units})"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|