earth 0.7.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,45 @@
1
+ This file shows which additional classes will be data_mined when you run data_miner on an automobile class. To get a complete set of automobile data you only need to data_mine the classes that are not indented.
2
+
3
+ Make
4
+ MakeYearFleet
5
+ MakeModelYearVariant
6
+
7
+ Model
8
+ MakeYearFleet
9
+ MakeModelYearVariant
10
+
11
+ Year
12
+ MakeYearFleet
13
+ MakeModelYearVariant
14
+
15
+ MakeModel
16
+ MakeModelYearVariant
17
+
18
+ MakeYear
19
+ MakeYearFleet
20
+ MakeModelYearVariant
21
+
22
+ MakeModelYear
23
+ MakeModelYearVariant
24
+ AutomobileFuel
25
+ GreenhouseGas
26
+ Fuel
27
+ FuelYear
28
+ TypeYear
29
+ TypeFuelYear
30
+ TypeFuelControl
31
+ TypeFuelYearControl
32
+ TypeFuelYearAge
33
+ TypeFuelYear
34
+ TypeFuelControl
35
+ TypeFuelYearControl
36
+
37
+ SizeClass
38
+ TypeYear
39
+ TypeFuelYear
40
+ TypeFuelControl
41
+ TypeFuelYearControl
42
+ TypeFuelYearAge
43
+ TypeFuelYear
44
+ TypeFuelControl
45
+ TypeFuelYearControl
@@ -24,9 +24,7 @@ class BusClass < ActiveRecord::Base
24
24
  :electricity_intensity => 0.00001804 / 1.miles.to(:kilometres),
25
25
  :electricity_intensity_units => 'kilowatt_hours_per_kilometre',
26
26
  :air_conditioning_emission_factor => 0.04779 / 1.miles.to(:kilometres),
27
- :air_conditioning_emission_factor_units => 'kilograms_co2e_per_kilometre',
28
- :alternative_fuels_intensity => 0.04632038.gallons_per_mile.to(:litres_per_kilometre), # deprecated
29
- :alternative_fuels_intensity_units => 'litres_per_kilometre' # deprecated
27
+ :air_conditioning_emission_factor_units => 'kilograms_co2e_per_kilometre'
30
28
 
31
29
  col :name
32
30
  col :distance, :type => :float
@@ -52,88 +50,4 @@ class BusClass < ActiveRecord::Base
52
50
  col :electricity_intensity_units
53
51
  col :air_conditioning_emission_factor, :type => :float
54
52
  col :air_conditioning_emission_factor_units
55
- col :alternative_fuels_intensity, :type => :float
56
- col :alternative_fuels_intensity_units
57
-
58
- # verify "Some attributes should be greater than zero" do
59
- # BusClass.all.each do |bus_class|
60
- # %w{ distance passengers speed diesel_intensity air_conditioning_emission_factor }.each do |attribute|
61
- # value = bus_class.send(:"#{attribute}")
62
- # unless value > 0
63
- # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{value} (should be > 0)"
64
- # end
65
- # end
66
- # end
67
- # end
68
- #
69
- # verify "Some attributes should be zero or more" do
70
- # BusClass.all.each do |bus_class|
71
- # %w{ gasoline_intensity cng_intensity lng_intensity lpg_intensity methanol_intensity biodiesel_intensity electricity_intensity alternative_fuels_intensity }.each do |attribute|
72
- # value = bus_class.send(:"#{attribute}")
73
- # unless value >= 0
74
- # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{value} (should be >= 0)"
75
- # end
76
- # end
77
- # end
78
- # end
79
- #
80
- # verify "Units should be correct" do
81
- # BusClass.all.each do |bus_class|
82
- # [["distance_units", "kilometres"],
83
- # ["speed_units", "kilometres_per_hour"],
84
- # ["diesel_intensity_units", "litres_per_kilometre"],
85
- # ["gasoline_intensity_units", "litres_per_kilometre"],
86
- # ["cng_intensity_units", "litres_per_kilometre"],
87
- # ["lng_intensity_units", "litres_per_kilometre"],
88
- # ["lpg_intensity_units", "litres_per_kilometre"],
89
- # ["methanol_intensity_units", "litres_per_kilometre"],
90
- # ["biodiesel_intensity_units", "litres_per_kilometre"],
91
- # ["electricity_intensity_units", "kilowatt_hours_per_kilometre"],
92
- # ["air_conditioning_emission_factor_units", "kilograms_co2e_per_kilometre"],
93
- # ["alternative_fuels_intensity_units", "litres_per_kilometre"]].each do |pair|
94
- # attribute = pair[0]
95
- # proper_units = pair[1]
96
- # units = bus_class.send(:"#{attribute}")
97
- # unless units == proper_units
98
- # raise "Invalid #{attribute.humanize.downcase} for BusClass #{bus_class.name}: #{units} (should be #{proper_units})"
99
- # end
100
- # end
101
- # end
102
- # end
103
- #
104
- # verify "Fallbacks should satisfy same constraints as data" do
105
- # %w{ distance passengers speed diesel_intensity air_conditioning_emission_factor }.each do |attribute|
106
- # value = BusClass.fallback.send(:"#{attribute}")
107
- # unless value > 0
108
- # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{value} (should be > 0)"
109
- # end
110
- # end
111
- #
112
- # %w{ gasoline_intensity cng_intensity lng_intensity lpg_intensity methanol_intensity biodiesel_intensity electricity_intensity alternative_fuels_intensity }.each do |attribute|
113
- # value = BusClass.fallback.send(:"#{attribute}")
114
- # unless value >= 0
115
- # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{value} (should be >= 0)"
116
- # end
117
- # end
118
- #
119
- # [["distance_units", "kilometres"],
120
- # ["speed_units", "kilometres_per_hour"],
121
- # ["diesel_intensity_units", "litres_per_kilometre"],
122
- # ["gasoline_intensity_units", "litres_per_kilometre"],
123
- # ["cng_intensity_units", "litres_per_kilometre"],
124
- # ["lng_intensity_units", "litres_per_kilometre"],
125
- # ["lpg_intensity_units", "litres_per_kilometre"],
126
- # ["methanol_intensity_units", "litres_per_kilometre"],
127
- # ["biodiesel_intensity_units", "litres_per_kilometre"],
128
- # ["electricity_intensity_units", "kilowatt_hours_per_kilometre"],
129
- # ["air_conditioning_emission_factor_units", "kilograms_co2e_per_kilometre"],
130
- # ["alternative_fuels_intensity_units", "litres_per_kilometre"]].each do |pair|
131
- # attribute = pair[0]
132
- # proper_units = pair[1]
133
- # units = BusClass.fallback.send(:"#{attribute}")
134
- # unless units == proper_units
135
- # raise "Invalid #{attribute.humanize.downcase} for fallback BusClass: #{units} (should be #{proper_units})"
136
- # end
137
- # end
138
- # end
139
53
  end
@@ -15,7 +15,6 @@ BusClass.class_eval do
15
15
  store 'biodiesel_intensity', :units_field_name => 'biodiesel_intensity_units'
16
16
  store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
17
17
  store 'air_conditioning_emission_factor', :units_field_name => 'air_conditioning_emission_factor_units'
18
- store 'alternative_fuels_intensity', :units_field_name => 'alternative_fuels_intensity_units'
19
18
  end
20
19
  end
21
20
  end
@@ -29,30 +29,23 @@ BusFuel.class_eval do
29
29
  process "Convert emission factors to metric units" do
30
30
  conversion_factor = (1 / 1.609344) * (1.0 / 1_000.0 ) # Google: 1 mile / 1.609344 km * 1 kg / 1000 g
31
31
  gwp_ch4 = GreenhouseGas[:ch4].global_warming_potential
32
- connection.execute %{
33
- UPDATE bus_fuels
34
- SET ch4_emission_factor = 1.0 * ch4_emission_factor * #{conversion_factor} * #{gwp_ch4},
35
- ch4_emission_factor_units = 'kilograms_co2e_per_kilometre'
36
- WHERE ch4_emission_factor_units = 'grams_per_mile'
37
- }
38
-
32
+ where(:ch4_emission_factor_units => 'grams_per_mile').update_all(%{
33
+ ch4_emission_factor = 1.0 * ch4_emission_factor * #{conversion_factor} * #{gwp_ch4},
34
+ ch4_emission_factor_units = 'kilograms_co2e_per_kilometre'
35
+ })
39
36
  gwp_n2o = GreenhouseGas[:n2o].global_warming_potential
40
- connection.execute %{
41
- UPDATE bus_fuels
42
- SET n2o_emission_factor = 1.0 * n2o_emission_factor * #{conversion_factor} * #{gwp_n2o},
43
- n2o_emission_factor_units = 'kilograms_co2e_per_kilometre'
44
- WHERE n2o_emission_factor_units = 'grams_per_mile'
45
- }
37
+ where(:n2o_emission_factor_units => 'grams_per_mile').update_all(%{
38
+ n2o_emission_factor = 1.0 * n2o_emission_factor * #{conversion_factor} * #{gwp_n2o},
39
+ n2o_emission_factor_units = 'kilograms_co2e_per_kilometre'
40
+ })
46
41
  end
47
42
 
48
43
  process "Convert energy contents to metric units" do
49
44
  conversion_factor = (1 / 947.81712) * (1 / 3.78541178) # Google: 1 MJ / 947.81712 btu * 1 gallon / 3.78541178 l
50
- connection.execute %{
51
- UPDATE bus_fuels
52
- SET energy_content = 1.0 * energy_content * #{conversion_factor},
53
- energy_content_units = 'megajoules_per_litre'
54
- WHERE energy_content_units = 'btu_per_gallon'
55
- }
45
+ where(:energy_content_units => 'btu_per_gallon').update_all(%{
46
+ energy_content = 1.0 * energy_content * #{conversion_factor},
47
+ energy_content_units = 'megajoules_per_litre'
48
+ })
56
49
  end
57
50
 
58
51
  process 'Calculate CO2 and CO2 biogenic emission factors and units' do
@@ -11,19 +11,15 @@ BusFuelControl.class_eval do
11
11
 
12
12
  process "Convert emission factors to metric units" do
13
13
  conversion_factor = (1 / 1.609344) * (1.0 / 1_000.0 ) # Google: 1 mile / 1.609344 km * 1 kg / 1000 g
14
- connection.execute %{
15
- UPDATE bus_fuel_controls
16
- SET ch4_emission_factor = 1.0 * ch4_emission_factor * #{conversion_factor},
17
- ch4_emission_factor_units = 'kilograms_per_kilometre'
18
- WHERE ch4_emission_factor_units = 'grams_per_mile'
19
- }
20
14
 
21
- connection.execute %{
22
- UPDATE bus_fuel_controls
23
- SET n2o_emission_factor = 1.0 * n2o_emission_factor * #{conversion_factor},
24
- n2o_emission_factor_units = 'kilograms_per_kilometre'
25
- WHERE n2o_emission_factor_units = 'grams_per_mile'
26
- }
15
+ where(:ch4_emission_factor_units => 'grams_per_mile').update_all(%{
16
+ ch4_emission_factor = 1.0 * ch4_emission_factor * #{conversion_factor},
17
+ ch4_emission_factor_units = 'kilograms_per_kilometre'
18
+ })
19
+ where(:n2o_emission_factor_units => 'grams_per_mile').update_all(%{
20
+ n2o_emission_factor = 1.0 * n2o_emission_factor * #{conversion_factor},
21
+ n2o_emission_factor_units = 'kilograms_per_kilometre'
22
+ })
27
23
  end
28
24
 
29
25
  # FIXME TODO verify this
@@ -39,6 +39,7 @@ Conversions.register(:cords, :joules, 2.11011171e10)
39
39
  Conversions.register(:gallons_per_mile, :litres_per_kilometre, 2.35214583)
40
40
  Conversions.register(:pounds_per_mile, :kilograms_per_kilometre, 0.281849232)
41
41
  Conversions.register(:dollars, :cents, 100)
42
+ Conversions.register(:cubic_inches, :litres, 0.016387064)
42
43
  Conversions.register(:cubic_feet, :cubic_metres, 0.0283168466)
43
44
  # 1 (kilocalories per pound) = 9 224.14105 joules per kilogram
44
45
  Conversions.register :kilocalories_per_pound, :joules_per_kilogram, 9_224.14105
@@ -8,9 +8,7 @@ Fuel.class_eval do
8
8
  ::Earth::Utils.insert_ignore(
9
9
  :src => FuelYear,
10
10
  :dest => Fuel,
11
- :cols => {
12
- :fuel_name => :name
13
- }
11
+ :cols => { :fuel_name => :name }
14
12
  )
15
13
  end
16
14
 
@@ -30,57 +28,49 @@ Fuel.class_eval do
30
28
  end
31
29
 
32
30
  process "Convert energy content of liquid fuels to metric units" do
33
- conversion_factor = (1_055.05585 / 1.0) * (1.0 / 158.987295) # Google: 1_055.05585 MJ / 1 MMBtu * 1 barrel / 158.987295 l
34
- connection.execute %{
35
- UPDATE fuels
36
- SET energy_content = 1.0 * energy_content * #{conversion_factor}, energy_content_units = 'megajoules_per_litre'
37
- WHERE energy_content_units = 'million_btu_per_barrel'
38
- }
31
+ conversion_factor = (1_055.05585) * (1.0 / 158.987295) # Google: 1_055.05585 MJ / 1 MMBtu * 1 barrel / 158.987295 l
32
+ where(:energy_content_units => 'million_btu_per_barrel').update_all(%{
33
+ energy_content = 1.0 * energy_content * #{conversion_factor},
34
+ energy_content_units = 'megajoules_per_litre'
35
+ })
39
36
  end
40
37
 
41
38
  process "Convert energy content of gaseous fuels to metric units" do
42
- conversion_factor = (1.0 / 947.81712) * (35.3146667 / 1.0) # Google: 1.0 MJ / 947.81712 Btu * 35.3146667 cubic feet / 1 cubic m
43
- connection.execute %{
44
- UPDATE fuels
45
- SET energy_content = 1.0 * energy_content * #{conversion_factor}, energy_content_units = 'megajoules_per_cubic_metre'
46
- WHERE energy_content_units = 'btu_per_cubic_foot'
47
- }
39
+ conversion_factor = (1.0 / 947.81712) * (35.3146667) # Google: 1.0 MJ / 947.81712 Btu * 35.3146667 cubic feet / 1 cubic m
40
+ where(:energy_content_units => 'btu_per_cubic_foot').update_all(%{
41
+ energy_content = 1.0 * energy_content * #{conversion_factor},
42
+ energy_content_units = 'megajoules_per_cubic_metre'
43
+ })
48
44
  end
49
45
 
50
46
  process "Convert carbon content to metric units" do
51
- conversion_factor = (1_000_000_000_000.0 / 1.0) * (1.0 / 1_055_055_852_620.0) # Google: 1e12 g / Tg * 1 QBtu / 1.055e12 MJ
52
- connection.execute %{
53
- UPDATE fuels
54
- SET carbon_content = 1.0 * carbon_content * #{conversion_factor}, carbon_content_units = 'grams_per_megajoule'
55
- WHERE carbon_content_units = 'teragrams_per_quadrillion_btu'
56
- }
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
+ })
57
52
  end
58
53
 
59
54
  process "Calculate CO2 and CO2 biogenic emission factors" do
60
55
  conversion_factor = (1.0 / 1_000.0) * (44.0 / 12.0) # Google: 1 kg / 1e3 g * 44 CO2 / 12 C
61
- connection.execute %{
62
- UPDATE fuels
63
- SET co2_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * (1 - biogenic_fraction) * #{conversion_factor},
64
- co2_biogenic_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * biogenic_fraction * #{conversion_factor}
65
- }
56
+ update_all(%{
57
+ co2_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * (1 - biogenic_fraction) * #{conversion_factor},
58
+ co2_biogenic_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * biogenic_fraction * #{conversion_factor}
59
+ })
66
60
  end
67
61
 
68
62
  process "Update emission factor units for liquid fuels" do
69
- connection.execute %{
70
- UPDATE fuels
71
- SET co2_emission_factor_units = 'kilograms_per_litre',
72
- co2_biogenic_emission_factor_units = 'kilograms_per_litre'
73
- WHERE energy_content_units = 'megajoules_per_litre'
74
- }
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
+ )
75
67
  end
76
68
 
77
69
  process "Update emission factor units for gaseous fuels" do
78
- connection.execute %{
79
- UPDATE fuels
80
- SET co2_emission_factor_units = 'kilograms_per_cubic_metre',
81
- co2_biogenic_emission_factor_units = 'kilograms_per_cubic_metre'
82
- WHERE energy_content_units = 'megajoules_per_cubic_metre'
83
- }
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
+ )
84
74
  end
85
75
 
86
76
  # FIXME TODO verify this stuff
@@ -12,75 +12,64 @@ FuelYear.class_eval do
12
12
  end
13
13
 
14
14
  process "Convert energy content of solid fuels to metric units" do
15
- conversion_factor = (1_055.05585 / 1.0) * (1.0 / 907.18474) # Google: 1_055.05585 MJ / 1 MMBtu * 1 short ton / 907.18474 kg
16
- connection.execute %{
17
- UPDATE fuel_years
18
- SET energy_content = 1.0 * energy_content * #{conversion_factor}, energy_content_units = 'megajoules_per_kilogram'
19
- WHERE energy_content_units = 'million_btu_per_short_ton'
20
- }
15
+ conversion_factor = (1_055.05585) * (1.0 / 907.18474) # Google: 1_055.05585 MJ / 1 MMBtu * 1 short ton / 907.18474 kg
16
+ where(:energy_content_units => 'million_btu_per_short_ton').update_all(%{
17
+ energy_content = 1.0 * energy_content * #{conversion_factor},
18
+ energy_content_units = 'megajoules_per_kilogram'
19
+ })
21
20
  end
22
21
 
23
22
  process "Convert energy content of liquid fuels to metric units" do
24
- conversion_factor = (1_055.05585 / 1.0) * (1.0 / 158.987295) # Google: 1_055.05585 MJ / 1 MMBtu * 1 barrel / 158.987295 l
25
- connection.execute %{
26
- UPDATE fuel_years
27
- SET energy_content = 1.0 * energy_content * #{conversion_factor}, energy_content_units = 'megajoules_per_litre'
28
- WHERE energy_content_units = 'million_btu_per_barrel'
29
- }
23
+ conversion_factor = (1_055.05585) * (1.0 / 158.987295) # Google: 1_055.05585 MJ / 1 MMBtu * 1 barrel / 158.987295 l
24
+ where(:energy_content_units => 'million_btu_per_barrel').update_all(%{
25
+ energy_content = 1.0 * energy_content * #{conversion_factor},
26
+ energy_content_units = 'megajoules_per_litre'
27
+ })
30
28
  end
31
29
 
32
30
  process "Convert energy content of gaseous fuels to metric units" do
33
- conversion_factor = (1.0 / 947.81712) * (35.3146667 / 1.0) # Google: 1.0 MJ / 947.81712 Btu * 35.3146667 cubic feet / 1 cubic m
34
- connection.execute %{
35
- UPDATE fuel_years
36
- SET energy_content = 1.0 * energy_content * #{conversion_factor}, energy_content_units = 'megajoules_per_cubic_metre'
37
- WHERE energy_content_units = 'btu_per_cubic_foot'
38
- }
31
+ conversion_factor = (1.0 / 947.81712) * (35.3146667) # Google: 1.0 MJ / 947.81712 Btu * 35.3146667 cubic feet / 1 cubic m
32
+ where(:energy_content_units => 'btu_per_cubic_foot').update_all(%{
33
+ energy_content = 1.0 * energy_content * #{conversion_factor},
34
+ energy_content_units = 'megajoules_per_cubic_metre'
35
+ })
39
36
  end
40
37
 
41
38
  process "Convert carbon content to metric units" do
42
- conversion_factor = (1_000_000_000_000.0 / 1.0) * (1.0 / 1_055_055_852_620.0) # Google: 1e12 g / Tg * 1 QBtu / 1.055e12 MJ
43
- connection.execute %{
44
- UPDATE fuel_years
45
- SET carbon_content = 1.0 * carbon_content * #{conversion_factor}, carbon_content_units = 'grams_per_megajoule'
46
- WHERE carbon_content_units = 'teragrams_per_quadrillion_btu'
47
- }
39
+ 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
40
+ where(:carbon_content_units => 'teragrams_per_quadrillion_btu').update_all(%{
41
+ carbon_content = 1.0 * carbon_content * #{conversion_factor},
42
+ carbon_content_units = 'grams_per_megajoule'
43
+ })
48
44
  end
49
45
 
50
46
  process "Calculate CO2 and CO2 biogenic emission factors" do
51
47
  conversion_factor = (1.0 / 1_000.0) * (44.0 / 12.0) # Google: 1 kg / 1e3 g * 44 CO2 / 12 C
52
- connection.execute %{
53
- UPDATE fuel_years
54
- SET co2_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * (1 - biogenic_fraction) * #{conversion_factor},
55
- co2_biogenic_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * biogenic_fraction * #{conversion_factor}
56
- }
48
+ update_all(%{
49
+ co2_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * (1 - biogenic_fraction) * #{conversion_factor},
50
+ co2_biogenic_emission_factor = 1.0 * carbon_content * energy_content * oxidation_factor * biogenic_fraction * #{conversion_factor}
51
+ })
57
52
  end
58
53
 
59
54
  process "Update emission factor units for solid fuels" do
60
- connection.execute %{
61
- UPDATE fuel_years
62
- SET co2_emission_factor_units = 'kilograms_per_kilogram',
63
- co2_biogenic_emission_factor_units = 'kilograms_per_kilogram'
64
- WHERE energy_content_units = 'megajoules_per_kilogram'
65
- }
55
+ where(:energy_content_units => 'megajoules_per_kilogram').update_all(
56
+ :co2_emission_factor_units => 'kilograms_per_kilogram',
57
+ :co2_biogenic_emission_factor_units => 'kilograms_per_kilogram'
58
+ )
66
59
  end
67
60
 
68
61
  process "Update emission factor units for liquid fuels" do
69
- connection.execute %{
70
- UPDATE fuel_years
71
- SET co2_emission_factor_units = 'kilograms_per_litre',
72
- co2_biogenic_emission_factor_units = 'kilograms_per_litre'
73
- WHERE energy_content_units = 'megajoules_per_litre'
74
- }
62
+ where(:energy_content_units => 'megajoules_per_litre').update_all(
63
+ :co2_emission_factor_units => 'kilograms_per_litre',
64
+ :co2_biogenic_emission_factor_units => 'kilograms_per_litre'
65
+ )
75
66
  end
76
67
 
77
68
  process "Update emission factor units for gaseous fuels" do
78
- connection.execute %{
79
- UPDATE fuel_years
80
- SET co2_emission_factor_units = 'kilograms_per_cubic_metre',
81
- co2_biogenic_emission_factor_units = 'kilograms_per_cubic_metre'
82
- WHERE energy_content_units = 'megajoules_per_cubic_metre'
83
- }
69
+ where(:energy_content_units => 'megajoules_per_cubic_metre').update_all(
70
+ :co2_emission_factor_units => 'kilograms_per_cubic_metre',
71
+ :co2_biogenic_emission_factor_units => 'kilograms_per_cubic_metre'
72
+ )
84
73
  end
85
74
  end
86
75
  end
@@ -11,20 +11,26 @@ LodgingClass.class_eval do
11
11
 
12
12
  process "Convert natural gas intensities to metric units" do
13
13
  conversion_factor = 2.83168466 # Google: 2.83168466 cubic m / 100 cubic ft
14
- update_all "natural_gas_intensity = 1.0 * natural_gas_intensity * #{conversion_factor}", :natural_gas_intensity_units => 'hundred_cubic_feet_per_room_night'
15
- update_all({:natural_gas_intensity_units => 'cubic_metres_per_room_night'}, :natural_gas_intensity_units => 'hundred_cubic_feet_per_room_night')
14
+ where(:natural_gas_intensity_units => 'hundred_cubic_feet_per_room_night').update_all(%{
15
+ natural_gas_intensity = 1.0 * natural_gas_intensity * #{conversion_factor},
16
+ natural_gas_intensity_units = 'cubic_metres_per_room_night'
17
+ })
16
18
  end
17
19
 
18
20
  process "Convert fuel oil intensities to metric units" do
19
21
  conversion_factor = 3.78541178 # Google: 3.78541178 l / gal
20
- update_all "fuel_oil_intensity = 1.0 * fuel_oil_intensity * #{conversion_factor}", :fuel_oil_intensity_units => 'gallons_per_room_night'
21
- update_all({:fuel_oil_intensity_units => 'litres_per_room_night'}, :fuel_oil_intensity_units => 'gallons_per_room_night')
22
+ where(:fuel_oil_intensity_units => 'gallons_per_room_night').update_all(%{
23
+ fuel_oil_intensity = 1.0 * fuel_oil_intensity * #{conversion_factor},
24
+ fuel_oil_intensity_units = 'litres_per_room_night'
25
+ })
22
26
  end
23
27
 
24
28
  process "Convert district heat intensities to metric units" do
25
29
  conversion_factor = 1.05505585 # Google: 1.05505585 MJ / 1000 Btu
26
- update_all "district_heat_intensity = 1.0 * district_heat_intensity * #{conversion_factor}", :district_heat_intensity_units => 'thousand_btu_per_room_night'
27
- update_all({:district_heat_intensity_units => 'megajoules_per_room_night'}, :district_heat_intensity_units => 'thousand_btu_per_room_night')
30
+ where(:district_heat_intensity_units => 'thousand_btu_per_room_night').update_all(%{
31
+ district_heat_intensity = 1.0 * district_heat_intensity * #{conversion_factor},
32
+ district_heat_intensity_units = 'megajoules_per_room_night'
33
+ })
28
34
  end
29
35
  end
30
36
  end