Sha256: 1adb14cd650e7b8eb763947286fafcb00293e2c1fe4c727c87c818500487604c

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

require 'earth/locality/data_miner'
CountryLodgingClass.class_eval do
  data_miner do
    import "a curated list of country lodging classes",
           :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdENYYWdiRm9LSjVZQ0tJRWplT1JNNVE&output=csv' do
      key 'name'
      store 'country_iso_3166_code'
      store 'lodging_class_name'
      store 'cbecs_detailed_activity'
    end
    
    process "Ensure CommercialBuildingEnergyConsumptionSurveyResponse and Country are populated" do
      CommercialBuildingEnergyConsumptionSurveyResponse.run_data_miner!
      Country.run_data_miner!
    end
    
    process "Calculate US lodging class fuel intensities from CommercialBuildingEnergyConsumptionSurveyResponse" do
      occupancy_rate = Country.united_states.lodging_occupancy_rate
      lodging_records = CommercialBuildingEnergyConsumptionSurveyResponse.lodging_records
      
      Country.united_states.lodging_classes.map(&:cbecs_detailed_activity).uniq.each do |cbecs_activity|
        %w{natural_gas fuel_oil electricity district_heat}.each do |fuel|
          cbecs_column = (fuel + '_use').to_sym
          
          where(:cbecs_detailed_activity => cbecs_activity).update_all %{
            #{fuel}_intensity = (#{
              lodging_records.where(:detailed_activity => cbecs_activity).
                weighted_average_relation(cbecs_column, :disaggregate_by => :room_nights, :weighted_by => :weighting).to_sql
            }) / #{occupancy_rate},
            #{fuel}_intensity_units = '#{lodging_records.first.send("#{fuel}_use_units")}_per_occupied_room_night',
            weighting = (#{
              lodging_records.where(:detailed_activity => cbecs_activity).sum(:weighting) /
              where(:cbecs_detailed_activity => cbecs_activity).count
            })
          }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
earth-0.12.3 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.12.2 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.12.1 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.12.0 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.20 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.19 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.18 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.17 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.16 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.15 lib/earth/hospitality/country_lodging_class/data_miner.rb
earth-0.11.14 lib/earth/hospitality/country_lodging_class/data_miner.rb