earth 0.11.5 → 0.11.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "earth/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "earth"
7
7
  s.version = Earth::VERSION
8
- s.date = "2011-12-17"
8
+ s.date = "2011-12-20"
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Seamus Abshere", "Derek Kastner", "Andy Rossmeissl"]
11
11
  s.email = %q{andy@rossmeissl.net}
@@ -4,12 +4,13 @@ class CountryLodgingClass < ActiveRecord::Base
4
4
  col :name
5
5
  col :country_iso_3166_code
6
6
  col :lodging_class_name
7
- col :electricity_intensity, :type => :float
8
- col :electricity_intensity_units
7
+ col :cbecs_detailed_activity
9
8
  col :natural_gas_intensity, :type => :float
10
9
  col :natural_gas_intensity_units
11
10
  col :fuel_oil_intensity, :type => :float
12
11
  col :fuel_oil_intensity_units
12
+ col :electricity_intensity, :type => :float
13
+ col :electricity_intensity_units
13
14
  col :district_heat_intensity, :type => :float
14
15
  col :district_heat_intensity_units
15
16
  col :weighting, :type => :float
@@ -1,40 +1,41 @@
1
1
  CountryLodgingClass.class_eval do
2
2
  data_miner do
3
- import "US lodging classes and their fuel intensities derived from CBECS 2003",
4
- :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGkxNExTajZPSjRWU3REVks5SFJ0cmc&output=csv',
5
- :select => lambda { |row| row['country_lodging_class'].present? } do
6
- key 'name', :field_name => 'country_lodging_class'
7
- store 'country_iso_3166_code', :field_name => 'country'
8
- store 'lodging_class_name', :field_name => 'lodging_class'
9
- store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
10
- store 'natural_gas_intensity', :units_field_name => 'natural_gas_intensity_units'
11
- store 'fuel_oil_intensity', :units_field_name => 'fuel_oil_intensity_units'
12
- store 'district_heat_intensity', :units_field_name => 'district_heat_intensity_units'
13
- store 'weighting'
3
+ import "a curated list of country lodging classes",
4
+ :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdENYYWdiRm9LSjVZQ0tJRWplT1JNNVE&output=csv' do
5
+ key 'name'
6
+ store 'country_iso_3166_code'
7
+ store 'lodging_class_name'
8
+ store 'cbecs_detailed_activity'
14
9
  end
15
10
 
16
- process "Convert natural gas intensities to metric units" do
17
- conversion_factor = 2.83168466 # Google: 2.83168466 cubic m / 100 cubic ft
18
- where(:natural_gas_intensity_units => 'hundred_cubic_feet_per_room_night').update_all(%{
19
- natural_gas_intensity = 1.0 * natural_gas_intensity * #{conversion_factor},
20
- natural_gas_intensity_units = 'cubic_metres_per_room_night'
21
- })
11
+ process "Ensure CommercialBuildingEnergyConsumptionSurveyResponse is populated" do
12
+ CommercialBuildingEnergyConsumptionSurveyResponse.run_data_miner!
22
13
  end
23
14
 
24
- process "Convert fuel oil intensities to metric units" do
25
- conversion_factor = 3.78541178 # Google: 3.78541178 l / gal
26
- where(:fuel_oil_intensity_units => 'gallons_per_room_night').update_all(%{
27
- fuel_oil_intensity = 1.0 * fuel_oil_intensity * #{conversion_factor},
28
- fuel_oil_intensity_units = 'litres_per_room_night'
29
- })
30
- end
31
-
32
- process "Convert district heat intensities to metric units" do
33
- conversion_factor = 1.05505585 # Google: 1.05505585 MJ / 1000 Btu
34
- where(:district_heat_intensity_units => 'thousand_btu_per_room_night').update_all(%{
35
- district_heat_intensity = 1.0 * district_heat_intensity * #{conversion_factor},
36
- district_heat_intensity_units = 'megajoules_per_room_night'
37
- })
15
+ process "Calculate US lodging class fuel intensities from CommercialBuildingEnergyConsumptionSurveyResponse" do
16
+ where(:country_iso_3166_code => 'US').each do |lodging_class|
17
+ cbecs_responses = CommercialBuildingEnergyConsumptionSurveyResponse.where(:detailed_activity => lodging_class.cbecs_detailed_activity)
18
+ intensities = {}
19
+
20
+ [:natural_gas, :fuel_oil, :electricity, :district_heat].each do |fuel|
21
+ intensities[fuel] = cbecs_responses.inject(0) do |sum, response|
22
+ next sum unless response.send("#{fuel}_use").present?
23
+ occupied_room_nights = 365.0 / 7.0 / 12.0 * response.months_used * response.weekly_hours / 24.0 * response.lodging_rooms * 0.59
24
+ sum + (response.weighting * response.send("#{fuel}_use") / occupied_room_nights)
25
+ end / cbecs_responses.sum(:weighting)
26
+ end
27
+
28
+ lodging_class.natural_gas_intensity = intensities[:natural_gas]
29
+ lodging_class.natural_gas_intensity_units = 'cubic_metres_per_room_night'
30
+ lodging_class.fuel_oil_intensity = intensities[:fuel_oil]
31
+ lodging_class.fuel_oil_intensity_units = 'litres_per_room_night'
32
+ lodging_class.electricity_intensity = intensities[:electricity]
33
+ lodging_class.electricity_intensity_units = 'kilowatt_hours_per_room_night'
34
+ lodging_class.district_heat_intensity = intensities[:district_heat]
35
+ lodging_class.district_heat_intensity_units = 'megajoules_per_room_night'
36
+ lodging_class.weighting = (lodging_class.lodging_class_name == 'Motel' or lodging_class.lodging_class_name == 'Inn') ? cbecs_responses.sum(:weighting) / 2.0 : cbecs_responses.sum(:weighting) # hack to ensure that we don't double-weight motels and inns when we calculate US national average lodging fuel intensities
37
+ lodging_class.save!
38
+ end
38
39
  end
39
40
  end
40
41
  end
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.11.5"
2
+ VERSION = "0.11.6"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.11.5
5
+ version: 0.11.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-12-17 00:00:00 -05:00
15
+ date: 2011-12-20 00:00:00 -05:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -644,7 +644,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
644
644
  requirements:
645
645
  - - ">="
646
646
  - !ruby/object:Gem::Version
647
- hash: 3108148755589690229
647
+ hash: -222319721383199393
648
648
  segments:
649
649
  - 0
650
650
  version: "0"
@@ -653,7 +653,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
653
653
  requirements:
654
654
  - - ">="
655
655
  - !ruby/object:Gem::Version
656
- hash: 3108148755589690229
656
+ hash: -222319721383199393
657
657
  segments:
658
658
  - 0
659
659
  version: "0"