earth 0.11.10 → 0.11.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Guardfile +35 -0
- data/README.markdown +94 -20
- data/Rakefile +4 -0
- data/earth.gemspec +14 -12
- data/lib/earth/air/aircraft.rb +2 -2
- data/lib/earth/air/aircraft_instance.rb +2 -2
- data/lib/earth/air/aircraft_instance_seat_class.rb +2 -2
- data/lib/earth/air/airline.rb +2 -2
- data/lib/earth/air/airport.rb +2 -2
- data/lib/earth/air/bts_aircraft.rb +2 -2
- data/lib/earth/air/flight_distance_class.rb +1 -1
- data/lib/earth/air/flight_distance_class_seat_class.rb +1 -1
- data/lib/earth/air/flight_seat_class.rb +1 -1
- data/lib/earth/air/flight_segment.rb +1 -1
- data/lib/earth/automobile/automobile_fuel.rb +1 -1
- data/lib/earth/automobile/automobile_make.rb +1 -1
- data/lib/earth/automobile/automobile_make_model.rb +1 -1
- data/lib/earth/automobile/automobile_make_model_year.rb +1 -1
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -1
- data/lib/earth/automobile/automobile_make_year.rb +1 -1
- data/lib/earth/automobile/automobile_make_year_fleet.rb +1 -1
- data/lib/earth/automobile/automobile_model.rb +1 -1
- data/lib/earth/automobile/automobile_size_class.rb +1 -1
- data/lib/earth/automobile/automobile_size_class_year.rb +1 -1
- data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -1
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -1
- data/lib/earth/automobile/automobile_type_year.rb +2 -2
- data/lib/earth/automobile/automobile_year.rb +1 -1
- data/lib/earth/bus/bus_class.rb +1 -1
- data/lib/earth/bus/bus_fuel.rb +2 -2
- data/lib/earth/bus/bus_fuel_control.rb +2 -2
- data/lib/earth/bus/bus_fuel_year_control.rb +2 -2
- data/lib/earth/computation/computation_carrier.rb +2 -2
- data/lib/earth/computation/computation_carrier_instance_class.rb +2 -2
- data/lib/earth/computation/computation_carrier_region.rb +2 -2
- data/lib/earth/conversions_ext.rb +26 -7
- data/lib/earth/diet/diet_class.rb +2 -2
- data/lib/earth/diet/food_group.rb +2 -2
- data/lib/earth/eia.rb +13 -13
- data/lib/earth/fuel/fuel.rb +22 -13
- data/lib/earth/fuel/fuel/data_miner.rb +36 -44
- data/lib/earth/fuel/fuel_price.rb +1 -1
- data/lib/earth/fuel/fuel_type.rb +2 -2
- data/lib/earth/fuel/fuel_year.rb +4 -2
- data/lib/earth/fuel/greenhouse_gas.rb +2 -2
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +14 -5
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +22 -1
- data/lib/earth/hospitality/country_lodging_class.rb +3 -3
- data/lib/earth/hospitality/country_lodging_class/data_miner.rb +7 -5
- data/lib/earth/hospitality/lodging_class.rb +1 -1
- data/lib/earth/hospitality/lodging_property.rb +8 -8
- data/lib/earth/industry/cbecs_energy_intensity.rb +59 -6
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +266 -69
- data/lib/earth/industry/industry.rb +1 -1
- data/lib/earth/industry/industry_product.rb +2 -2
- data/lib/earth/industry/industry_product_line.rb +2 -2
- data/lib/earth/industry/industry_sector.rb +2 -2
- data/lib/earth/industry/mecs_energy.rb +26 -15
- data/lib/earth/industry/mecs_energy/data_miner.rb +39 -23
- data/lib/earth/industry/mecs_ratio.rb +13 -10
- data/lib/earth/industry/mecs_ratio/data_miner.rb +14 -14
- data/lib/earth/industry/merchant.rb +2 -2
- data/lib/earth/industry/merchant_category.rb +2 -2
- data/lib/earth/industry/merchant_category_industry.rb +2 -2
- data/lib/earth/industry/product_line.rb +2 -2
- data/lib/earth/industry/product_line_industry_product.rb +2 -2
- data/lib/earth/industry/sector.rb +2 -2
- data/lib/earth/locality/census_division.rb +2 -2
- data/lib/earth/locality/census_division/data_miner.rb +4 -14
- data/lib/earth/locality/census_region.rb +2 -2
- data/lib/earth/locality/climate_division.rb +1 -17
- data/lib/earth/locality/country.rb +14 -28
- data/lib/earth/locality/country/data_miner.rb +8 -2
- data/lib/earth/locality/egrid_country.rb +1 -1
- data/lib/earth/locality/egrid_region.rb +4 -1
- data/lib/earth/locality/egrid_region/data_miner.rb +4 -1
- data/lib/earth/locality/egrid_subregion.rb +1 -1
- data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +3 -3
- data/lib/earth/locality/state.rb +2 -7
- data/lib/earth/locality/zip_code.rb +1 -1
- data/lib/earth/pet/breed.rb +2 -2
- data/lib/earth/pet/breed_gender.rb +2 -2
- data/lib/earth/pet/gender.rb +2 -2
- data/lib/earth/pet/species.rb +2 -2
- data/lib/earth/pet/species/data_miner.rb +0 -9
- data/lib/earth/rail/country_rail_class.rb +1 -1
- data/lib/earth/rail/country_rail_traction.rb +1 -1
- data/lib/earth/rail/country_rail_traction_class.rb +1 -1
- data/lib/earth/rail/national_transit_database_company.rb +2 -2
- data/lib/earth/rail/national_transit_database_mode.rb +2 -2
- data/lib/earth/rail/national_transit_database_record.rb +2 -2
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +12 -33
- data/lib/earth/rail/rail_class.rb +1 -1
- data/lib/earth/rail/rail_company.rb +1 -1
- data/lib/earth/rail/rail_company_traction.rb +1 -1
- data/lib/earth/rail/rail_company_traction_class.rb +1 -1
- data/lib/earth/rail/rail_fuel.rb +1 -1
- data/lib/earth/rail/rail_traction.rb +1 -1
- data/lib/earth/residence/air_conditioner_use.rb +2 -2
- data/lib/earth/residence/clothes_machine_use.rb +2 -2
- data/lib/earth/residence/dishwasher_use.rb +2 -2
- data/lib/earth/residence/residence_appliance.rb +2 -2
- data/lib/earth/residence/residence_class.rb +2 -2
- data/lib/earth/residence/residence_fuel_price.rb +2 -2
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -5
- data/lib/earth/residence/residence_fuel_type.rb +2 -2
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +3 -3
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -5
- data/lib/earth/residence/urbanity.rb +2 -2
- data/lib/earth/shipping/carrier.rb +3 -2
- data/lib/earth/shipping/carrier/data_miner.rb +1 -0
- data/lib/earth/shipping/carrier_mode.rb +2 -2
- data/lib/earth/shipping/shipment_mode.rb +2 -2
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/aircraft_spec.rb +421 -0
- data/spec/earth/fuel/fuel_spec.rb +35 -0
- data/spec/earth/hospitality/lodging_fuel_use_equation_spec.rb +96 -0
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +102 -0
- data/spec/earth/industry/mecs_energy_spec.rb +36 -44
- data/spec/earth/industry/mecs_ratio_spec.rb +24 -17
- data/spec/earth/locality/country_spec.rb +0 -9
- data/spec/spec_helper.rb +8 -3
- data/spec/support/integration.rb +17 -0
- data/vendor/geokit-rails/init.rb +2 -1
- data/vendor/geokit-rails/lib/geokit-rails.rb +1 -0
- metadata +63 -36
- data/lib/earth/hospitality/lodging_fuel_use_equation.rb +0 -26
- data/lib/earth/hospitality/lodging_fuel_use_equation/data_miner.rb +0 -20
- data/test/test_aircraft_match.rb +0 -732
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/fuel'
|
2
2
|
class AutomobileTypeFuelYear < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
# FIXME TODO keep this until fix AutomobileFuel import so that it doesn't call type_fuel_year.type_year
|
6
6
|
belongs_to :type_year, :class_name => 'AutomobileTypeYear', :foreign_key => 'type_year_name'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/fuel'
|
2
2
|
class AutomobileTypeYear < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
# FIXME TODO keep this until fix AutomobileFuel fallback hfc emission factor so that it doesn't call type_year.type_fuel_year
|
6
6
|
has_many :type_fuel_years, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_year_name'
|
@@ -55,4 +55,4 @@ class AutomobileTypeYear < ActiveRecord::Base
|
|
55
55
|
# end
|
56
56
|
# end
|
57
57
|
|
58
|
-
end
|
58
|
+
end
|
data/lib/earth/bus/bus_class.rb
CHANGED
data/lib/earth/bus/bus_fuel.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/fuel'
|
2
2
|
class BusFuel < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
belongs_to :fuel, :foreign_key => 'fuel_name'
|
6
6
|
has_many :fuel_year_controls, :class_name => 'BusFuelYearControl', :foreign_key => 'bus_fuel_name'
|
@@ -91,4 +91,4 @@ class BusFuel < ActiveRecord::Base
|
|
91
91
|
# end
|
92
92
|
# end
|
93
93
|
# end
|
94
|
-
end
|
94
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/fuel'
|
2
2
|
class BusFuelControl < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
col :name
|
5
5
|
col :bus_fuel_name
|
6
6
|
col :control
|
@@ -8,4 +8,4 @@ class BusFuelControl < ActiveRecord::Base
|
|
8
8
|
col :ch4_emission_factor_units
|
9
9
|
col :n2o_emission_factor, :type => :float
|
10
10
|
col :n2o_emission_factor_units
|
11
|
-
end
|
11
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/fuel'
|
2
2
|
class BusFuelYearControl < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
belongs_to :fuel_control, :class_name => 'BusFuelControl', :foreign_key => 'bus_fuel_control_name'
|
6
6
|
|
@@ -10,4 +10,4 @@ class BusFuelYearControl < ActiveRecord::Base
|
|
10
10
|
col :control
|
11
11
|
col :bus_fuel_control_name
|
12
12
|
col :total_travel_percent, :type => :float
|
13
|
-
end
|
13
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/locality'
|
2
2
|
class ComputationCarrier < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
falls_back_on :name => 'fallback',
|
6
6
|
:power_usage_effectiveness => lambda { ComputationCarrier.maximum('power_usage_effectiveness') }
|
@@ -15,4 +15,4 @@ class ComputationCarrier < ActiveRecord::Base
|
|
15
15
|
# end
|
16
16
|
# end
|
17
17
|
# end
|
18
|
-
end
|
18
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/locality'
|
2
2
|
class ComputationCarrierInstanceClass < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
belongs_to :computation_carrier, :foreign_key => 'computation_carrier_name'
|
6
6
|
|
@@ -32,4 +32,4 @@ class ComputationCarrierInstanceClass < ActiveRecord::Base
|
|
32
32
|
# end
|
33
33
|
# end
|
34
34
|
|
35
|
-
end
|
35
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'earth/locality'
|
2
2
|
class ComputationCarrierRegion < ActiveRecord::Base
|
3
|
-
|
3
|
+
self.primary_key = "name"
|
4
4
|
|
5
5
|
belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
|
6
6
|
|
@@ -8,4 +8,4 @@ class ComputationCarrierRegion < ActiveRecord::Base
|
|
8
8
|
col :computation_carrier_name
|
9
9
|
col :region
|
10
10
|
col :egrid_subregion_abbreviation
|
11
|
-
end
|
11
|
+
end
|
@@ -5,15 +5,18 @@ Conversions.register :kilometres, :miles, 0.621371192
|
|
5
5
|
Conversions.register :kilometres, :nautical_miles, 0.539956803
|
6
6
|
|
7
7
|
# Area
|
8
|
-
Conversions.register :square_metres, :square_feet,
|
8
|
+
Conversions.register :square_metres, :square_feet, 10.7639104
|
9
|
+
Conversions.register :square_metres, :million_square_feet, (1.square_metres.to(:square_feet) / 1_000_000)
|
9
10
|
|
10
11
|
# Volume, liquid: base unit = litre
|
11
|
-
Conversions.register :
|
12
|
-
Conversions.register :
|
12
|
+
Conversions.register :gallons, :litres, 3.78541178
|
13
|
+
Conversions.register :cubic_inches, :litres, 0.016387064
|
14
|
+
Conversions.register :barrels, :litres, 42.gallons.to(:litres)
|
13
15
|
|
14
16
|
# Volume, solid: base unit = cubic metre
|
15
17
|
Conversions.register :cubic_metres, :cubic_feet, 35.3146667
|
16
|
-
Conversions.register :cubic_metres, :hundred_cubic_feet,
|
18
|
+
Conversions.register :cubic_metres, :hundred_cubic_feet, (1.cubic_metres.to(:cubic_feet) / 100)
|
19
|
+
Conversions.register :cubic_metres, :billion_cubic_feet, (1.cubic_metres.to(:cubic_feet) / 1_000_000_000)
|
17
20
|
|
18
21
|
# Mass: base unit = kilogram
|
19
22
|
Conversions.register :kilograms, :grams, 1_000.0
|
@@ -22,8 +25,14 @@ Conversions.register :kilograms, :pounds, 2.20462262
|
|
22
25
|
Conversions.register :kilograms, :tons, 0.00110231131
|
23
26
|
|
24
27
|
# Energy: base unit = megajoule
|
25
|
-
Conversions.register :megajoules,
|
26
|
-
Conversions.register :
|
28
|
+
Conversions.register :btus, :megajoules, 0.00105505585
|
29
|
+
Conversions.register :kbtus, :megajoules, 1_000.btus.to(:megajoules)
|
30
|
+
Conversions.register :trillion_btus, :megajoules, 1_000_000_000_000.btus.to(:megajoules)
|
31
|
+
Conversions.register :kilowatt_hours, :megajoules, 3.6
|
32
|
+
Conversions.register :billion_kilowatt_hours, :megajoules, 1_000_000_000.kilowatt_hours.to(:megajoules)
|
33
|
+
|
34
|
+
# Electricity: base unit = kilowatt hour
|
35
|
+
Conversions.register :kilowatt_hours, :billion_kilowatt_hours, (1.0 / 1_000_000_000.0)
|
27
36
|
|
28
37
|
# Monetary
|
29
38
|
Conversions.register :dollars, :cents, 100.0
|
@@ -42,10 +51,13 @@ Conversions.register :litres_per_square_metre_hour, :gallons_per_square_
|
|
42
51
|
Conversions.register :litres_per_room_night, :gallons_per_room_night, (1.litres.to(:gallons))
|
43
52
|
Conversions.register :cubic_metres_per_square_metre_hour, :hundred_cubic_feet_per_square_foot_hour, (1.cubic_metres.to(:hundred_cubic_feet) / 1.square_metres.to(:square_feet))
|
44
53
|
Conversions.register :cubic_metres_per_room_night, :hundred_cubic_feet_per_room_night, (1.cubic_metres.to(:hundred_cubic_feet))
|
54
|
+
Conversions.register :kilowatt_hours_per_square_metre, :kilowatt_hours_per_square_foot, (1 / 1.square_metres.to(:square_feet))
|
45
55
|
Conversions.register :kilowatt_hours_per_square_metre_hour, :kilowatt_hours_per_square_foot_hour, (1 / 1.square_metres.to(:square_feet))
|
46
56
|
Conversions.register :megajoules_per_square_metre_hour, :kbtus_per_square_foot_hour, (1.megajoules.to(:kbtus) / 1.square_metres.to(:square_feet))
|
47
57
|
Conversions.register :megajoules_per_room_night, :kbtus_per_room_night, (1.megajoules.to(:kbtus))
|
48
|
-
|
58
|
+
Conversions.register :million_btu_per_barrel, :megajoules_per_litre, (1_000_000.btus.to(:megajoules) / 1.barrels.to(:litres)) # Fuel
|
59
|
+
Conversions.register :btus_per_cubic_foot, :megajoules_per_cubic_metre, (1.btus.to(:megajoules) / 1.cubic_feet.to(:cubic_metres)) # Fuel
|
60
|
+
Conversions.register :teragrams_per_quadrillion_btu, :grams_per_megajoule, (1_000_000_000_000 / 1_000_000_000_000_000.btus.to(:megajoules)) # Fuel
|
49
61
|
|
50
62
|
# Odd units for pet - FIXME use megajoules rather than joules
|
51
63
|
Conversions.register :kilocalories, :joules, 4_184.0
|
@@ -64,6 +76,13 @@ Conversions.register :kbtus, :joules, (1_000.0 * 1_055.0558
|
|
64
76
|
Conversions.register :watt_hours, :joules, 3_600.0
|
65
77
|
Conversions.register :kilowatt_hours, :joules, 3_600_000.0
|
66
78
|
|
79
|
+
# Odd units for CBECS
|
80
|
+
Conversions.register :trillion_btus_per_million_square_feet, :megajoules_per_square_metre, (1.trillion_btus.to(:megajoules) / 1.square_feet.to(:square_metres))
|
81
|
+
Conversions.register :kilowatt_hours_per_square_foot, :megajoules_per_square_metre, (1.kilowatt_hours.to(:megajoules) / 1.square_feet.to(:square_metres))
|
82
|
+
Conversions.register :billion_cubic_feet_of_natural_gas, :megajoules, (1_000_000_000.cubic_feet.to(:cubic_metres) * 38.3395) # 2003 NatGas energy content MJ/m3
|
83
|
+
Conversions.register :cubic_feet_of_natural_gas_per_square_foot, :megajoules_per_square_metre, ((1.cubic_feet.to(:cubic_metres) * 38.3395) / 1.square_feet.to(:square_metres))
|
84
|
+
Conversions.register :million_gallons_of_fuel_oil, :megajoules, (1_000_000.gallons.to(:litres) * 39.0136) # Residual Fuel Oil energy content MJ/l from Fuels
|
85
|
+
Conversions.register :gallons_of_fuel_oil_per_square_foot, :megajoules_per_square_metre, ((39.0136 * 1.gallons.to(:litres)) / 1.square_feet.to(:square_metres))
|
67
86
|
|
68
87
|
# Only used in app1
|
69
88
|
Conversions.register(:pounds_per_gallon, :kilograms_per_litre, 0.119826427) # only used in app1
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class DietClass < ActiveRecord::Base
|
2
|
-
|
2
|
+
self.primary_key = "name"
|
3
3
|
|
4
4
|
class << self
|
5
5
|
def fallback
|
@@ -20,4 +20,4 @@ class DietClass < ActiveRecord::Base
|
|
20
20
|
col :fruit_share, :type => :float
|
21
21
|
col :vegetables_share, :type => :float
|
22
22
|
col :oils_and_sugars_share, :type => :float
|
23
|
-
end
|
23
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FoodGroup < ActiveRecord::Base
|
2
|
-
|
2
|
+
self.primary_key = "name"
|
3
3
|
|
4
4
|
class << self
|
5
5
|
def names
|
@@ -17,4 +17,4 @@ class FoodGroup < ActiveRecord::Base
|
|
17
17
|
col :energy, :type => :float
|
18
18
|
col :energy_units
|
19
19
|
col :suggested_imperial_measurement # ?
|
20
|
-
end
|
20
|
+
end
|
data/lib/earth/eia.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'earth'
|
2
|
+
|
2
3
|
module Earth
|
3
4
|
module EIA
|
4
5
|
extend self
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
|
7
|
+
def convert_value(value, args = {})
|
8
|
+
case value
|
9
|
+
when '*'
|
10
|
+
0
|
11
|
+
when 'Q', 'W'
|
12
|
+
nil
|
13
|
+
else
|
14
|
+
if args[:to]
|
15
|
+
value.to_f.send(args[:from]).to(args[:to])
|
16
|
+
else
|
17
|
+
value.to_f
|
17
18
|
end
|
18
|
-
record.save!
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/earth/fuel/fuel.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
class Fuel < ActiveRecord::Base
|
2
|
-
|
2
|
+
self.primary_key = "name"
|
3
3
|
|
4
4
|
has_many :fuel_years, :foreign_key => 'fuel_name'
|
5
5
|
|
6
6
|
col :name
|
7
|
+
col :physical_units
|
7
8
|
col :density, :type => :float
|
8
9
|
col :density_units
|
9
10
|
col :energy_content, :type => :float
|
@@ -17,7 +18,15 @@ class Fuel < ActiveRecord::Base
|
|
17
18
|
col :co2_biogenic_emission_factor, :type => :float
|
18
19
|
col :co2_biogenic_emission_factor_units
|
19
20
|
|
20
|
-
|
21
|
+
# Need to ensure FuelYear gets data_mined even when pulling with taps
|
22
|
+
# b/c Fuel has instance methods to look up missing values from FuelYear
|
23
|
+
data_miner do
|
24
|
+
process "Ensure FuelYear is imported" do
|
25
|
+
FuelYear.run_data_miner!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def latest_fuel_year
|
21
30
|
fuel_years.find_by_year(fuel_years.maximum('year'))
|
22
31
|
end
|
23
32
|
|
@@ -25,7 +34,7 @@ class Fuel < ActiveRecord::Base
|
|
25
34
|
if content = super
|
26
35
|
content
|
27
36
|
elsif fuel_years.present?
|
28
|
-
|
37
|
+
latest_fuel_year.energy_content
|
29
38
|
end
|
30
39
|
end
|
31
40
|
|
@@ -33,7 +42,7 @@ class Fuel < ActiveRecord::Base
|
|
33
42
|
if units = super
|
34
43
|
units
|
35
44
|
elsif fuel_years.present?
|
36
|
-
|
45
|
+
latest_fuel_year.energy_content_units
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
@@ -41,7 +50,7 @@ class Fuel < ActiveRecord::Base
|
|
41
50
|
if content = super
|
42
51
|
content
|
43
52
|
elsif fuel_years.present?
|
44
|
-
|
53
|
+
latest_fuel_year.carbon_content
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
@@ -49,7 +58,7 @@ class Fuel < ActiveRecord::Base
|
|
49
58
|
if units = super
|
50
59
|
units
|
51
60
|
elsif fuel_years.present?
|
52
|
-
|
61
|
+
latest_fuel_year.carbon_content_units
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
@@ -57,7 +66,7 @@ class Fuel < ActiveRecord::Base
|
|
57
66
|
if oxidation_factor = super
|
58
67
|
oxidation_factor
|
59
68
|
elsif fuel_years.present?
|
60
|
-
|
69
|
+
latest_fuel_year.oxidation_factor
|
61
70
|
end
|
62
71
|
end
|
63
72
|
|
@@ -65,7 +74,7 @@ class Fuel < ActiveRecord::Base
|
|
65
74
|
if biogenic_fraction = super
|
66
75
|
biogenic_fraction
|
67
76
|
elsif fuel_years.present?
|
68
|
-
|
77
|
+
latest_fuel_year.biogenic_fraction
|
69
78
|
end
|
70
79
|
end
|
71
80
|
|
@@ -73,7 +82,7 @@ class Fuel < ActiveRecord::Base
|
|
73
82
|
if ef = super
|
74
83
|
ef
|
75
84
|
elsif fuel_years.present?
|
76
|
-
|
85
|
+
latest_fuel_year.co2_emission_factor
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
@@ -81,7 +90,7 @@ class Fuel < ActiveRecord::Base
|
|
81
90
|
if units = super
|
82
91
|
units
|
83
92
|
elsif fuel_years.present?
|
84
|
-
|
93
|
+
latest_fuel_year.co2_emission_factor_units
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
@@ -89,7 +98,7 @@ class Fuel < ActiveRecord::Base
|
|
89
98
|
if ef = super
|
90
99
|
ef
|
91
100
|
elsif fuel_years.present?
|
92
|
-
|
101
|
+
latest_fuel_year.co2_biogenic_emission_factor
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
@@ -97,7 +106,7 @@ class Fuel < ActiveRecord::Base
|
|
97
106
|
if units = super
|
98
107
|
units
|
99
108
|
elsif fuel_years.present?
|
100
|
-
|
109
|
+
latest_fuel_year.co2_biogenic_emission_factor_units
|
101
110
|
end
|
102
111
|
end
|
103
|
-
end
|
112
|
+
end
|
@@ -12,11 +12,24 @@ Fuel.class_eval do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
import "fuels with non-variable characteristics",
|
16
|
-
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGJmYkdtajZyV3Byb0lrd21xLVhXUGc&
|
15
|
+
import "liquid fuels with non-variable characteristics",
|
16
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGJmYkdtajZyV3Byb0lrd21xLVhXUGc&output=csv',
|
17
|
+
:select => lambda {|row| row['energy_content_units'] == 'million_btu_per_barrel'} do
|
17
18
|
key 'name'
|
18
|
-
store '
|
19
|
-
store '
|
19
|
+
store 'physical_units', :static => 'litre'
|
20
|
+
store 'energy_content', :from_units => :million_btu_per_barrel, :to_units => :megajoules_per_litre
|
21
|
+
store 'carbon_content', :from_units => :teragrams_per_quadrillion_btu, :to_units => :grams_per_megajoule
|
22
|
+
store 'oxidation_factor'
|
23
|
+
store 'biogenic_fraction'
|
24
|
+
end
|
25
|
+
|
26
|
+
import "gaseous fuels with non-variable characteristics",
|
27
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGJmYkdtajZyV3Byb0lrd21xLVhXUGc&output=csv',
|
28
|
+
:select => lambda {|row| row['energy_content_units'] == 'btu_per_cubic_foot'} do
|
29
|
+
key 'name'
|
30
|
+
store 'physical_units', :static => 'cubic_metre'
|
31
|
+
store 'energy_content', :from_units => :btus_per_cubic_foot, :to_units => :megajoules_per_cubic_metre
|
32
|
+
store 'carbon_content', :from_units => :teragrams_per_quadrillion_btu, :to_units => :grams_per_megajoule
|
20
33
|
store 'oxidation_factor'
|
21
34
|
store 'biogenic_fraction'
|
22
35
|
end
|
@@ -27,52 +40,31 @@ Fuel.class_eval do
|
|
27
40
|
store 'density', :units_field_name => 'density_units'
|
28
41
|
end
|
29
42
|
|
30
|
-
process "
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
process "Convert carbon content to metric units" do
|
47
|
-
conversion_factor = (1_000_000_000_000.0) * (1.0 / 1_055_055_852_620.0) # Google: 1e12 g / Tg * 1 QBtu / 1.055e12 MJ
|
48
|
-
where(:carbon_content_units => 'teragrams_per_quadrillion_btu').update_all(%{
|
49
|
-
carbon_content = 1.0 * carbon_content * #{conversion_factor},
|
50
|
-
carbon_content_units = 'grams_per_megajoule'
|
51
|
-
})
|
43
|
+
process "Create district heat" do
|
44
|
+
natural_gas = find_by_name 'Pipeline Natural Gas'
|
45
|
+
fuel_oil = find_by_name 'Residual Fuel Oil No. 6'
|
46
|
+
district_heat = find_or_create_by_name "District Heat"
|
47
|
+
|
48
|
+
# Assumptions: half nat gas at 81.7% efficiency half fuel oil at 84.6% efficiency 5% transmission losses
|
49
|
+
district_heat.carbon_content = (((natural_gas.carbon_content / 0.817) + (fuel_oil.carbon_content / 0.846)) / 2.0) / 0.95
|
50
|
+
district_heat.carbon_content_units = 'grams_per_megajoule'
|
51
|
+
district_heat.energy_content = 1.0
|
52
|
+
district_heat.energy_content_units = 'megajoules_per_megajoule'
|
53
|
+
district_heat.oxidation_factor = 1.0
|
54
|
+
district_heat.biogenic_fraction = 0.0
|
55
|
+
district_heat.physical_units = 'megajoule'
|
56
|
+
district_heat.save!
|
52
57
|
end
|
53
58
|
|
54
59
|
process "Calculate CO2 and CO2 biogenic emission factors" do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
co2_biogenic_emission_factor
|
60
|
+
where('carbon_content IS NOT NULL and energy_content IS NOT NULL and oxidation_factor IS NOT NULL and biogenic_fraction IS NOT NULL').update_all(%{
|
61
|
+
co2_emission_factor = 1.0 * carbon_content * #{1.grams.to(:kilograms).carbon.to(:co2)} * energy_content * oxidation_factor * (1.0 - biogenic_fraction),
|
62
|
+
co2_emission_factor_units = 'kilograms_per_' || physical_units,
|
63
|
+
co2_biogenic_emission_factor = 1.0 * carbon_content * #{1.grams.to(:kilograms).carbon.to(:co2)} * energy_content * oxidation_factor * biogenic_fraction,
|
64
|
+
co2_biogenic_emission_factor_units = 'kilograms_per_' || physical_units
|
59
65
|
})
|
60
66
|
end
|
61
67
|
|
62
|
-
process "Update emission factor units for liquid fuels" do
|
63
|
-
where(:energy_content_units => 'megajoules_per_litre').update_all(
|
64
|
-
:co2_emission_factor_units => 'kilograms_per_litre',
|
65
|
-
:co2_biogenic_emission_factor_units => 'kilograms_per_litre'
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
process "Update emission factor units for gaseous fuels" do
|
70
|
-
where(:energy_content_units => 'megajoules_per_cubic_metre').update_all(
|
71
|
-
:co2_emission_factor_units => 'kilograms_per_cubic_metre',
|
72
|
-
:co2_biogenic_emission_factor_units => 'kilograms_per_cubic_metre'
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
68
|
# FIXME TODO verify this stuff
|
77
69
|
end
|
78
70
|
end
|