earth 0.12.3 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. data/Gemfile +1 -0
  2. data/TODO +1 -0
  3. data/bin/earth_tester.rb +39 -47
  4. data/data/air/airlines.csv +45 -0
  5. data/data/air/airports.csv +11 -0
  6. data/data/hospitality/lodging_classes.csv +4 -0
  7. data/data/locality/national_electricity_efs.csv +137 -0
  8. data/earth.gemspec +1 -1
  9. data/errata/airline/bts_carrier_codes_errata.csv +2 -0
  10. data/lib/earth.rb +3 -0
  11. data/lib/earth/active_record_base_class_methods.rb +25 -0
  12. data/lib/earth/air/aircraft.rb +5 -4
  13. data/lib/earth/air/airline.rb +5 -1
  14. data/lib/earth/air/airline/data_miner.rb +1 -1
  15. data/lib/earth/air/airport.rb +10 -2
  16. data/lib/earth/air/airport/data_miner.rb +11 -5
  17. data/lib/earth/air/bts_aircraft.rb +1 -1
  18. data/lib/earth/air/flight_segment.rb +14 -1
  19. data/lib/earth/air/flight_segment/data_miner.rb +6 -13
  20. data/lib/earth/automobile/automobile_activity_year/data_miner.rb +1 -1
  21. data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +1 -1
  22. data/lib/earth/automobile/automobile_fuel/data_miner.rb +5 -5
  23. data/lib/earth/automobile/automobile_make/data_miner.rb +1 -1
  24. data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -1
  25. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +1 -1
  26. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +6 -6
  27. data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +2 -2
  28. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -1
  29. data/lib/earth/conversions_ext.rb +7 -6
  30. data/lib/earth/fuel/fuel.rb +1 -1
  31. data/lib/earth/fuel/fuel/data_miner.rb +1 -3
  32. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +3 -1
  33. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +44 -11
  34. data/lib/earth/hospitality/lodging_class.rb +0 -1
  35. data/lib/earth/hospitality/lodging_class/data_miner.rb +3 -9
  36. data/lib/earth/industry/merchant_category/data_miner.rb +14 -0
  37. data/lib/earth/locality/country.rb +33 -7
  38. data/lib/earth/locality/country/data_miner.rb +46 -32
  39. data/lib/earth/locality/egrid_subregion.rb +1 -1
  40. data/lib/earth/locality/egrid_subregion/data_miner.rb +16 -31
  41. data/lib/earth/locality/electricity_mix.rb +37 -0
  42. data/lib/earth/locality/electricity_mix/data_miner.rb +87 -0
  43. data/lib/earth/locality/state.rb +12 -4
  44. data/lib/earth/locality/state/data_miner.rb +33 -18
  45. data/lib/earth/locality/zip_code.rb +9 -1
  46. data/lib/earth/locality/zip_code/data_miner.rb +4 -0
  47. data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -2
  48. data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -2
  49. data/lib/earth/rail/national_transit_database_record.rb +4 -0
  50. data/lib/earth/rail/rail_company/data_miner.rb +3 -3
  51. data/lib/earth/rail/rail_fuel/data_miner.rb +1 -1
  52. data/lib/earth/residence/clothes_machine_use/data_miner.rb +1 -1
  53. data/lib/earth/residence/dishwasher_use/data_miner.rb +1 -1
  54. data/lib/earth/residence/residence_fuel_price.rb +1 -1
  55. data/lib/earth/version.rb +1 -1
  56. data/spec/earth/air/airline_spec.rb +1 -1
  57. data/spec/earth/air/airport_spec.rb +7 -0
  58. data/spec/earth/air/flight_segment_spec.rb +26 -12
  59. data/spec/earth/automobile/automobile_type_fuel_spec.rb +1 -1
  60. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +3 -3
  61. data/spec/earth/fuel/fuel_spec.rb +1 -1
  62. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +32 -19
  63. data/spec/earth/hospitality/lodging_class_spec.rb +18 -0
  64. data/spec/earth/industry/mecs_energy_spec.rb +2 -2
  65. data/spec/earth/industry/mecs_ratio_spec.rb +1 -1
  66. data/spec/earth/industry/merchant_category_spec.rb +17 -0
  67. data/spec/earth/locality/country_spec.rb +32 -16
  68. data/spec/earth/locality/egrid_subregion_spec.rb +40 -27
  69. data/spec/earth/locality/electricity_mix_spec.rb +70 -0
  70. data/spec/earth/locality/state_spec.rb +10 -11
  71. data/spec/earth/locality/zip_code_spec.rb +9 -5
  72. data/spec/earth_spec.rb +4 -4
  73. data/spec/spec_helper.rb +3 -0
  74. metadata +19 -10
  75. data/lib/earth/hospitality/country_lodging_class.rb +0 -18
  76. data/lib/earth/hospitality/country_lodging_class/data_miner.rb +0 -40
  77. data/lib/earth/industry/merchant.rb +0 -9
  78. data/spec/earth/hospitality/country_lodging_class_spec.rb +0 -30
@@ -1,18 +0,0 @@
1
- require 'earth/locality'
2
- class CountryLodgingClass < ActiveRecord::Base
3
- self.primary_key = "name"
4
-
5
- col :name
6
- col :country_iso_3166_code
7
- col :lodging_class_name
8
- col :cbecs_detailed_activity
9
- col :natural_gas_intensity, :type => :float
10
- col :natural_gas_intensity_units
11
- col :fuel_oil_intensity, :type => :float
12
- col :fuel_oil_intensity_units
13
- col :electricity_intensity, :type => :float
14
- col :electricity_intensity_units
15
- col :district_heat_intensity, :type => :float
16
- col :district_heat_intensity_units
17
- col :weighting, :type => :float
18
- end
@@ -1,40 +0,0 @@
1
- require 'earth/locality/data_miner'
2
- CountryLodgingClass.class_eval do
3
- data_miner do
4
- import "a curated list of country lodging classes",
5
- :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdENYYWdiRm9LSjVZQ0tJRWplT1JNNVE&output=csv' do
6
- key 'name'
7
- store 'country_iso_3166_code'
8
- store 'lodging_class_name'
9
- store 'cbecs_detailed_activity'
10
- end
11
-
12
- process "Ensure CommercialBuildingEnergyConsumptionSurveyResponse and Country are populated" do
13
- CommercialBuildingEnergyConsumptionSurveyResponse.run_data_miner!
14
- Country.run_data_miner!
15
- end
16
-
17
- process "Calculate US lodging class fuel intensities from CommercialBuildingEnergyConsumptionSurveyResponse" do
18
- occupancy_rate = Country.united_states.lodging_occupancy_rate
19
- lodging_records = CommercialBuildingEnergyConsumptionSurveyResponse.lodging_records
20
-
21
- Country.united_states.lodging_classes.map(&:cbecs_detailed_activity).uniq.each do |cbecs_activity|
22
- %w{natural_gas fuel_oil electricity district_heat}.each do |fuel|
23
- cbecs_column = (fuel + '_use').to_sym
24
-
25
- where(:cbecs_detailed_activity => cbecs_activity).update_all %{
26
- #{fuel}_intensity = (#{
27
- lodging_records.where(:detailed_activity => cbecs_activity).
28
- weighted_average_relation(cbecs_column, :disaggregate_by => :room_nights, :weighted_by => :weighting).to_sql
29
- }) / #{occupancy_rate},
30
- #{fuel}_intensity_units = '#{lodging_records.first.send("#{fuel}_use_units")}_per_occupied_room_night',
31
- weighting = (#{
32
- lodging_records.where(:detailed_activity => cbecs_activity).sum(:weighting) /
33
- where(:cbecs_detailed_activity => cbecs_activity).count
34
- })
35
- }
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,9 +0,0 @@
1
- class Merchant < ActiveRecord::Base
2
- self.primary_key = "id"
3
-
4
- belongs_to :merchant_category, :foreign_key => 'mcc'
5
-
6
- col :id
7
- col :name
8
- col :mcc
9
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'earth/hospitality/country_lodging_class'
3
-
4
- describe CountryLodgingClass do
5
- describe "when importing data", :data_miner => true do
6
- before do
7
- Earth.init :hospitality, :load_data_miner => true, :skip_parent_associations => :true
8
- end
9
-
10
- it "imports all naics codes" do
11
- CountryLodgingClass.run_data_miner!
12
- end
13
- end
14
-
15
- describe "verify imported data", :sanity => true do
16
- it "should have all the data" do
17
- CountryLodgingClass.count.should == 3
18
- end
19
-
20
- it "should have fuel intensities" do
21
- us_hotel = CountryLodgingClass.find 'US Hotel'
22
- us_hotel.fuel_oil_intensity.should be_within(0.00001).of(0.25014)
23
- us_hotel.fuel_oil_intensity_units.should == 'litres_per_occupied_room_night'
24
- end
25
-
26
- it "should have the correct total weighting for the US" do
27
- CountryLodgingClass.where(:country_iso_3166_code => 'US').sum(&:weighting).should == be_within(0.1).of(89209.2)
28
- end
29
- end
30
- end