earth 0.11.9 → 0.11.10

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 = "2012-01-24"
8
+ s.date = "2012-01-26"
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}
@@ -31,6 +31,9 @@ Conversions.register :dollars, :cents, 100.0
31
31
  # GHG
32
32
  Conversions.register :carbon, :co2, (44.0 / 12.0)
33
33
 
34
+ # Temperature
35
+ Conversions.register :degrees_celsius, :degrees_fahrenheit, (9.0 / 5.0) # NOTE: only for conversion between degrees NOT temperatures: 1 degree C = 9/5 degrees F but a temperature of 1 degree C = temperature of 33.8 degrees F
36
+
34
37
  # Complex
35
38
  Conversions.register :kilometres_per_litre, :miles_per_gallon, (1.kilometres.to(:miles) / 1.litres.to(:gallons))
36
39
  Conversions.register :litres_per_kilometre, :gallons_per_mile, (1.litres.to(:gallons) / 1.kilometres.to(:miles))
@@ -14,8 +14,10 @@ class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
14
14
  col :census_region_number, :type => :integer
15
15
  col :census_division_number, :type => :integer
16
16
  col :climate_zone_number, :type => :integer
17
- col :heating_degree_days, :type => :integer
18
- col :cooling_degree_days, :type => :integer
17
+ col :heating_degree_days, :type => :float
18
+ col :heating_degree_days_units
19
+ col :cooling_degree_days, :type => :float
20
+ col :cooling_degree_days_units
19
21
  col :construction_year, :type => :integer
20
22
  col :area, :type => :float
21
23
  col :area_units
@@ -40,8 +40,8 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
40
40
  :skip => 1,
41
41
  :headers => ["PUBID8", "REGION8", "CENDIV8", "SQFT8", "SQFTC8", "YRCONC8", "PBA8", "ELUSED8", "NGUSED8", "FKUSED8", "PRUSED8", "STUSED8", "HWUSED8", "ADJWT8", "STRATUM8", "PAIR8", "HDD658", "CDD658", "MFUSED8", "MFBTU8", "MFEXP8", "ELCNS8", "ELBTU8", "ELEXP8", "ZELCNS8", "ZELEXP8"] do
42
42
  key 'id', :field_name => 'PUBID8'
43
- store 'heating_degree_days', :field_name => 'HDD658'
44
- store 'cooling_degree_days', :field_name => 'CDD658'
43
+ store 'heating_degree_days', :field_name => 'HDD658', :from_units => :degrees_fahrenheit, :to_units => :degrees_celsius
44
+ store 'cooling_degree_days', :field_name => 'CDD658', :from_units => :degrees_fahrenheit, :to_units => :degrees_celsius
45
45
  store 'electricity_use', :synthesize => Proc.new { |row| row['ELCNS8'].to_i }, :units => :kilowatt_hours
46
46
  store 'electricity_energy', :field_name => 'ELBTU8', :from_units => :kbtus, :to_units => :megajoules
47
47
  end
@@ -7,12 +7,12 @@ class ClimateDivision < ActiveRecord::Base
7
7
  RADIUS = 750
8
8
 
9
9
  def climate_zone_number
10
- if cooling_degree_days < 2000
11
- if heating_degree_days > 7000
10
+ if cooling_degree_days < 2000.degrees_fahrenheit.to(:degrees_celsius)
11
+ if heating_degree_days > 7000.degrees_fahrenheit.to(:degrees_celsius)
12
12
  1
13
- elsif heating_degree_days > 5499
13
+ elsif heating_degree_days > 5499.degrees_fahrenheit.to(:degrees_celsius)
14
14
  2
15
- elsif heating_degree_days > 3999
15
+ elsif heating_degree_days > 3999.degrees_fahrenheit.to(:degrees_celsius)
16
16
  3
17
17
  else
18
18
  4
@@ -24,6 +24,8 @@ class ClimateDivision < ActiveRecord::Base
24
24
 
25
25
  col :name
26
26
  col :heating_degree_days, :type => :float
27
+ col :heating_degree_days_units
27
28
  col :cooling_degree_days, :type => :float
29
+ col :cooling_degree_days_units
28
30
  col :state_postal_abbreviation
29
31
  end
@@ -3,10 +3,9 @@ ClimateDivision.class_eval do
3
3
  import "a list of climate divisions and their average heating and cooling degree days",
4
4
  :url => 'http://static.brighterplanet.com/science/data/climate/climate_divisions/climate_divisions.csv' do
5
5
  key 'name'
6
- store 'heating_degree_days'
7
- store 'cooling_degree_days'
6
+ store 'heating_degree_days', :from_units => :degrees_fahrenheit, :to_units => :degrees_celsius
7
+ store 'cooling_degree_days', :from_units => :degrees_fahrenheit, :to_units => :degrees_celsius
8
8
  store 'state_postal_abbreviation'
9
9
  end
10
- #associate :state, :key => :state_postal_abbreviation, :foreign_key => :postal_abbreviation
11
10
  end
12
11
  end
@@ -1,12 +1,31 @@
1
1
  require 'earth/automobile'
2
2
  require 'earth/hospitality'
3
3
  require 'earth/rail'
4
+
4
5
  class Country < ActiveRecord::Base
5
6
  set_primary_key :iso_3166_code
6
7
 
7
8
  has_many :rail_companies, :foreign_key => 'country_iso_3166_code' # used to calculate rail data
8
9
  has_many :lodging_classes, :foreign_key => 'country_iso_3166_code', :class_name => 'CountryLodgingClass'
9
10
 
11
+ def climate_zone_number
12
+ if heating_degree_days and cooling_degree_days
13
+ if cooling_degree_days < 2000.degrees_fahrenheit.to(:degrees_celsius)
14
+ if heating_degree_days > 7000.degrees_fahrenheit.to(:degrees_celsius)
15
+ 1
16
+ elsif heating_degree_days > 5499.degrees_fahrenheit.to(:degrees_celsius)
17
+ 2
18
+ elsif heating_degree_days > 3999.degrees_fahrenheit.to(:degrees_celsius)
19
+ 3
20
+ else
21
+ 4
22
+ end
23
+ else
24
+ 5
25
+ end
26
+ end
27
+ end
28
+
10
29
  falls_back_on :name => 'fallback',
11
30
  :automobile_urbanity => lambda { united_states.automobile_urbanity }, # for now assume US represents world
12
31
  :automobile_fuel_efficiency => ((22.5 + 16.2) / 2.0).miles_per_gallon.to(:kilometres_per_litre), # average of passenger car fuel unknown and light goods vehicle fuel unknown - WRI Mobile Combustion calculation tool v2.0
@@ -49,6 +68,10 @@ class Country < ActiveRecord::Base
49
68
  col :iso_3166_numeric_code, :type => :integer # numeric like 826; aka UN M49 code
50
69
  col :iso_3166_alpha_3_code # 3-letter like GBR
51
70
  col :name
71
+ col :heating_degree_days, :type => :float
72
+ col :heating_degree_days_units
73
+ col :cooling_degree_days, :type => :float
74
+ col :cooling_degree_days_units
52
75
  col :automobile_urbanity, :type => :float # float from 0 to 1
53
76
  col :automobile_fuel_efficiency, :type => :float
54
77
  col :automobile_fuel_efficiency_units
@@ -18,6 +18,32 @@ Country.class_eval do
18
18
  store 'name', :field_number => 5 # romanized version
19
19
  end
20
20
 
21
+ import "heating degree day data from WRI CAIT",
22
+ :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDN4MkRTSWtWRjdfazhRdWllTkVSMkE&output=csv',
23
+ :select => Proc.new { |record| record['country'] != 'European Union (27)' },
24
+ :errata => { :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDNSMUtCV0h4cUF4UnBKZlNkczlNbFE&output=csv' } do
25
+ key 'name', :field_name => 'country'
26
+ store 'heating_degree_days', :units => :degrees_celsius
27
+ end
28
+
29
+ import "cooling degree day data from WRI CAIT",
30
+ :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDN4MkRTSWtWRjdfazhRdWllTkVSMkE&output=csv',
31
+ :select => Proc.new { |record| record['country'] != 'European Union (27)' },
32
+ :errata => { :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDNSMUtCV0h4cUF4UnBKZlNkczlNbFE&output=csv' } do
33
+ key 'name', :field_name => 'country'
34
+ store 'cooling_degree_days', :units => :degrees_celsius
35
+ end
36
+
37
+ process "set Montenegro's heating and cooling degree days to the same as Serbia's" do
38
+ montenegro = Country.find 'ME'
39
+ serbia = Country.find 'RS'
40
+ montenegro.heating_degree_days = serbia.heating_degree_days
41
+ montenegro.heating_degree_days_units = serbia.heating_degree_days_units
42
+ montenegro.cooling_degree_days = serbia.cooling_degree_days
43
+ montenegro.cooling_degree_days_units = serbia.cooling_degree_days_units
44
+ montenegro.save!
45
+ end
46
+
21
47
  # AUTOMOBILE
22
48
  import "automobile-related data for the US",
23
49
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDdZRm1tNjY0c2dYNG00bXJ3TXRqUVE&gid=0&output=csv' do
@@ -77,7 +103,7 @@ Country.class_eval do
77
103
  row['electricity_co2_emission_factor'].to_f +
78
104
  (row['electricity_ch4_emission_factor'].to_f * GreenhouseGas[:ch4].global_warming_potential) +
79
105
  (row['electricity_n2o_emission_factor'].to_f * GreenhouseGas[:n2o].global_warming_potential)
80
- ) / (1 - row['loss_factor'].to_f) }, :units_field_name => 'kilograms_co2e_per_kilowatt_hour'
106
+ ) / (1 - row['loss_factor'].to_f) }, :units => 'kilograms_co2e_per_kilowatt_hour'
81
107
  end
82
108
 
83
109
  process "Ensure EgridSubregion is populated" do
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.11.9"
2
+ VERSION = "0.11.10"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'earth/locality'
3
+ require 'earth/locality/data_miner'
4
+
5
+ describe Country do
6
+ describe 'import', :slow => true do
7
+ it 'should import data' do
8
+ Earth.init 'locality', :load_data_miner => true, :apply_schemas => true
9
+ Country.run_data_miner!
10
+ Country.all.count.should == 249
11
+ end
12
+
13
+ it 'should correctly determine climate zone number' do
14
+ Country.find('LT').climate_zone_number.should == 1
15
+ Country.find('HU').climate_zone_number.should == 2
16
+ Country.find('HR').climate_zone_number.should == 3
17
+ Country.find('CY').climate_zone_number.should == 4
18
+ Country.find('UZ').climate_zone_number.should == 5
19
+ Country.where(:heating_degree_days => nil).first.climate_zone_number.should == nil
20
+ end
21
+ end
22
+ end
@@ -8,13 +8,36 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  require 'earth'
10
10
 
11
+ case ENV['EARTH_DB_ADAPTER']
12
+ when 'mysql'
13
+ adapter = 'mysql'
14
+ database = 'test_earth'
15
+ username = 'root'
16
+ password = 'password'
17
+
18
+ # system %{mysql -u #{username} -p#{password} -e "DROP DATABASE #{database}"}
19
+ # system %{mysql -u #{username} -p#{password} -e "CREATE DATABASE #{database}"}
20
+ else
21
+ adapter = 'sqlite3'
22
+ database = ':memory:'
23
+ username = nil
24
+ password = nil
25
+ end
26
+
27
+ config = {
28
+ 'encoding' => 'utf8',
29
+ 'adapter' => adapter,
30
+ 'database' => database,
31
+ }
32
+ config['username'] = username if username
33
+ config['password'] = password if password
34
+
35
+ ActiveRecord::Base.establish_connection config
36
+
11
37
  logger = Logger.new 'log/test.log'
12
38
  logger.level = Logger::DEBUG
13
39
 
14
- ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
15
-
16
40
  ActiveRecord::Base.logger = logger
17
-
18
41
  DataMiner.logger = logger
19
42
 
20
43
  RSpec.configure do |c|
@@ -7,10 +7,10 @@
7
7
  #
8
8
  require 'geokit'
9
9
  if defined? Geokit
10
- require 'geokit-rails/defaults'
11
- require 'geokit-rails/adapters/abstract'
12
- require 'geokit-rails/acts_as_mappable'
13
- require 'geokit-rails/ip_geocode_lookup'
10
+ require File.expand_path('../geokit-rails/defaults', __FILE__)
11
+ require File.expand_path('../geokit-rails/adapters/abstract', __FILE__)
12
+ require File.expand_path('../geokit-rails/acts_as_mappable', __FILE__)
13
+ require File.expand_path('../geokit-rails/ip_geocode_lookup', __FILE__)
14
14
 
15
15
  # Automatically mix in distance finder support into ActiveRecord classes.
16
16
  ActiveRecord::Base.send :include, GeoKit::ActsAsMappable
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.11.9
5
+ version: 0.11.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere
@@ -12,8 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-01-24 00:00:00 +01:00
16
- default_executable:
15
+ date: 2012-01-26 00:00:00 Z
17
16
  dependencies:
18
17
  - !ruby/object:Gem::Dependency
19
18
  name: data_miner
@@ -584,6 +583,7 @@ files:
584
583
  - spec/earth/bus/bus_fuel_year_control_spec.rb
585
584
  - spec/earth/industry/mecs_energy_spec.rb
586
585
  - spec/earth/industry/mecs_ratio_spec.rb
586
+ - spec/earth/locality/country_spec.rb
587
587
  - spec/earth/pet/species_spec.rb
588
588
  - spec/earth_spec.rb
589
589
  - spec/spec_helper.rb
@@ -633,7 +633,6 @@ files:
633
633
  - vendor/geokit-rails/test/schema.rb
634
634
  - vendor/geokit-rails/test/tasks.rake
635
635
  - vendor/geokit-rails/test/test_helper.rb
636
- has_rdoc: true
637
636
  homepage: https://github.com/brighterplanet/earth
638
637
  licenses: []
639
638
 
@@ -647,7 +646,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
647
646
  requirements:
648
647
  - - ">="
649
648
  - !ruby/object:Gem::Version
650
- hash: 3547937136240416644
649
+ hash: 1670776732781702788
651
650
  segments:
652
651
  - 0
653
652
  version: "0"
@@ -656,14 +655,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
656
655
  requirements:
657
656
  - - ">="
658
657
  - !ruby/object:Gem::Version
659
- hash: 3547937136240416644
658
+ hash: 1670776732781702788
660
659
  segments:
661
660
  - 0
662
661
  version: "0"
663
662
  requirements: []
664
663
 
665
664
  rubyforge_project:
666
- rubygems_version: 1.6.2
665
+ rubygems_version: 1.8.15
667
666
  signing_key:
668
667
  specification_version: 3
669
668
  summary: Land, sky, and sea
@@ -758,6 +757,7 @@ test_files:
758
757
  - spec/earth/bus/bus_fuel_year_control_spec.rb
759
758
  - spec/earth/industry/mecs_energy_spec.rb
760
759
  - spec/earth/industry/mecs_ratio_spec.rb
760
+ - spec/earth/locality/country_spec.rb
761
761
  - spec/earth/pet/species_spec.rb
762
762
  - spec/earth_spec.rb
763
763
  - spec/spec_helper.rb