earth 0.11.13 → 0.11.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.markdown +1 -1
  2. data/bin/earth_tester.rb +1 -1
  3. data/earth.gemspec +2 -3
  4. data/lib/earth.rb +1 -1
  5. data/lib/earth/air/aircraft/data_miner.rb +4 -0
  6. data/lib/earth/air/airline/data_miner.rb +5 -1
  7. data/lib/earth/air/airport/data_miner.rb +4 -0
  8. data/lib/earth/air/flight_segment.rb +2 -2
  9. data/lib/earth/air/flight_segment/data_miner.rb +4 -0
  10. data/lib/earth/computation/computation_carrier_instance_class.rb +1 -1
  11. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +3 -8
  12. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +10 -19
  13. data/lib/earth/hospitality/country_lodging_class/data_miner.rb +17 -23
  14. data/lib/earth/hospitality/lodging_property.rb +4 -0
  15. data/lib/earth/industry/mecs_energy.rb +15 -6
  16. data/lib/earth/industry/mecs_ratio.rb +16 -7
  17. data/lib/earth/industry/sic_1987.rb +0 -1
  18. data/lib/earth/locality/country/data_miner.rb +7 -14
  19. data/lib/earth/locality/zip_code/data_miner.rb +4 -6
  20. data/lib/earth/version.rb +1 -1
  21. data/spec/earth/air/aircraft_spec.rb +1 -1
  22. data/spec/earth/automobile/automobile_fuel_spec.rb +1 -1
  23. data/spec/earth/automobile/automobile_type_fuel_year_age_spec.rb +1 -1
  24. data/spec/earth/bus/bus_class_spec.rb +1 -1
  25. data/spec/earth/fuel/fuel_spec.rb +1 -1
  26. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +37 -0
  27. data/spec/earth/hospitality/country_lodging_class_spec.rb +31 -0
  28. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +1 -1
  29. data/spec/earth/industry/industry_spec.rb +1 -1
  30. data/spec/earth/industry/mecs_energy_spec.rb +10 -2
  31. data/spec/earth/industry/mecs_ratio_spec.rb +9 -1
  32. data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +1 -1
  33. data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +1 -1
  34. data/spec/earth/industry/naics_2002_spec.rb +1 -1
  35. data/spec/earth/industry/naics_2007_spec.rb +1 -1
  36. data/spec/earth/industry/sic_1987_spec.rb +1 -15
  37. data/spec/earth/locality/country_spec.rb +27 -10
  38. data/spec/earth/locality/state_spec.rb +1 -1
  39. data/spec/earth/locality/zip_code_spec.rb +1 -1
  40. data/spec/spec_helper.rb +2 -2
  41. metadata +193 -199
  42. data/.document +0 -5
data/README.markdown CHANGED
@@ -83,7 +83,7 @@ ft = AutomobileFuel.first
83
83
 
84
84
  ### Data storage
85
85
 
86
- You can store Earth data in any relational database. On your very first run, you will need to create the tables for data each model. This is done using minirecord with the `apply_schemas` option:
86
+ You can store Earth data in any relational database. On your very first run, you will need to create the tables for data each model. This is done using [the `active_record_inline_schema` library](https://github.com/seamusabshere/active_record_inline_schema) if you pass the `apply_schemas` option:
87
87
 
88
88
  ``` ruby
89
89
  require 'activerecord'
data/bin/earth_tester.rb CHANGED
@@ -16,7 +16,7 @@ require 'active_record'
16
16
 
17
17
  case ENV['EARTH_DB_ADAPTER']
18
18
  when 'mysql'
19
- adapter = 'mysql'
19
+ adapter = 'mysql2'
20
20
  database = 'test_earth'
21
21
  username = 'root'
22
22
  password = 'password'
data/earth.gemspec CHANGED
@@ -5,7 +5,6 @@ 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-03-05"
9
8
  s.platform = Gem::Platform::RUBY
10
9
  s.authors = ["Seamus Abshere", "Derek Kastner", "Andy Rossmeissl"]
11
10
  s.email = %q{andy@rossmeissl.net}
@@ -36,7 +35,7 @@ Gem::Specification.new do |s|
36
35
  s.add_runtime_dependency 'fixed_width-multibyte'
37
36
  s.add_runtime_dependency 'fuzzy_match', '>=1.1.0'
38
37
  s.add_runtime_dependency 'geokit'
39
- s.add_runtime_dependency 'mini_record-compat' # need https://github.com/DAddYE/mini_record/pull/7
38
+ s.add_runtime_dependency 'active_record_inline_schema'
40
39
  s.add_runtime_dependency 'remote_table', '>=1.3.0'
41
40
  s.add_runtime_dependency 'table_warnings', '>=0.0.6'
42
41
  s.add_runtime_dependency 'to_regexp'
@@ -45,7 +44,7 @@ Gem::Specification.new do |s|
45
44
  s.add_development_dependency 'bundler'
46
45
  s.add_development_dependency 'charisma'
47
46
  s.add_development_dependency 'cucumber'
48
- s.add_development_dependency 'mysql' # for bin/earth_tester.rb
47
+ s.add_development_dependency 'mysql2' # for bin/earth_tester.rb; use mysql2 for utf-8 compatibility
49
48
  s.add_development_dependency 'pg'
50
49
  s.add_development_dependency 'rake'
51
50
  s.add_development_dependency 'rdoc'
data/lib/earth.rb CHANGED
@@ -7,7 +7,7 @@ require 'falls_back_on'
7
7
  require 'weighted_average'
8
8
  require 'fixed_width'
9
9
  require 'errata'
10
- require 'mini_record'
10
+ require 'active_record_inline_schema'
11
11
  require 'table_warnings'
12
12
  require 'fuzzy_match'
13
13
  require 'fuzzy_match/cached_result'
@@ -22,6 +22,10 @@ Aircraft.class_eval do
22
22
  end
23
23
 
24
24
  data_miner do
25
+ process "Start from scratch" do
26
+ delete_all
27
+ end
28
+
25
29
  ('A'..'Z').each do |letter|
26
30
  import("aircraft made by whitelisted manufacturers whose ICAO code starts with '#{letter}' from the FAA",
27
31
  :url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
@@ -1,6 +1,10 @@
1
1
  Airline.class_eval do
2
2
  data_miner do
3
- import "a Brighter Planet-curated list of airlines and codes not included in our other sources",
3
+ process "Start from scratch" do
4
+ delete_all
5
+ end
6
+
7
+ import "a Brighter Planet-curated list of airlines and codes not included in our proprietary sources",
4
8
  :url => 'https://spreadsheets.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGJoaFpENXRqMEM2NW42am5tNURGU2c&output=csv' do
5
9
  key 'name'
6
10
  store 'bts_code', :nullify => true
@@ -17,6 +17,10 @@ Airport.class_eval do
17
17
  end
18
18
 
19
19
  data_miner do
20
+ process "Start from scratch" do
21
+ delete_all
22
+ end
23
+
20
24
  import "the OpenFlights.org airports database",
21
25
  :url => 'https://openflights.svn.sourceforge.net/svnroot/openflights/openflights/data/airports.dat',
22
26
  :headers => %w{ id name city country_name iata_code icao_code latitude longitude altitude timezone daylight_savings },
@@ -21,8 +21,8 @@ class FlightSegment < ActiveRecord::Base
21
21
  # Assume a load factor of 1 where passengers > available seats
22
22
  where('passengers > seats AND seats > 0').update_all 'load_factor = 1'
23
23
 
24
- # FIXME TODO: what is 90.718474
25
- # Derive freight share as a fraction of the total weight carried
24
+ # Derive freight share as a fraction of the total weight carried -- assume 90.718474 kg (200 lbs) per passenger (includes checked baggage)
25
+ # FIXME TODO assume 100 kg per passenger?
26
26
  where('(freight + mail + passengers) > 0').update_all 'freight_share = 1.0 * (freight + mail) / (freight + mail + (passengers * 90.718474))'
27
27
 
28
28
  # Derive average seats per flight
@@ -183,6 +183,10 @@ FlightSegment.class_eval do
183
183
  end
184
184
 
185
185
  data_miner do
186
+ process "Start from scratch" do
187
+ delete_all
188
+ end
189
+
186
190
  form_data_per_month(2009..::Time.now.year).each do |month, form_data|
187
191
  import "T100 flight segment data for #{month.strftime('%B %Y')}",
188
192
  :url => URL,
@@ -2,7 +2,7 @@ require 'earth/locality'
2
2
  class ComputationCarrierInstanceClass < ActiveRecord::Base
3
3
  self.primary_key = "name"
4
4
 
5
- belongs_to :computation_carrier, :foreign_key => 'computation_carrier_name'
5
+ belongs_to :carrier, :class_name => 'ComputationCarrier', :foreign_key => 'computation_carrier_name'
6
6
 
7
7
  falls_back_on :name => 'fallback',
8
8
  :electricity_intensity => lambda { ComputationCarrierInstanceClass.find_by_name('Amazon m1.small').electricity_intensity },
@@ -45,9 +45,12 @@ class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
45
45
  col :fuel_oil_energy_units
46
46
  col :district_heat_use, :type => :float
47
47
  col :district_heat_use_units
48
+ col :district_heat_energy, :type => :float
49
+ col :district_heat_energy_units
48
50
  col :stratum, :type => :integer
49
51
  col :pair, :type => :integer
50
52
  col :weighting, :type => :float
53
+ col :room_nights, :type => :float
51
54
  col :electricity_per_room_night, :type => :float # for lodging fuzzy weighting
52
55
  col :electricity_per_room_night_units # for lodging fuzzy weighting
53
56
  col :natural_gas_per_room_night, :type => :float # for lodging fuzzy weighting
@@ -56,12 +59,4 @@ class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
56
59
  col :fuel_oil_per_room_night_units # for lodging fuzzy weighting
57
60
  col :district_heat_per_room_night, :type => :float # for lodging fuzzy weighting
58
61
  col :district_heat_per_room_night_units # for lodging fuzzy weighting
59
- col :electricity_energy_intensity, :type => :float
60
- col :electricity_energy_intensity_units
61
- col :natural_gas_energy_intensity, :type => :float
62
- col :natural_gas_energy_intensity_units
63
- col :fuel_oil_energy_intensity, :type => :float
64
- col :fuel_oil_energy_intensity_units
65
- col :district_heat_energy_intensity, :type => :float
66
- col :district_heat_energy_intensity_units
67
62
  end
@@ -64,32 +64,23 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
64
64
  store 'fuel_oil_use', :field_name => 'FKCNS8', :from_units => :gallons, :to_units => :litres
65
65
  store 'fuel_oil_energy', :field_name => 'FKBTU8', :from_units => :kbtus, :to_units => :megajoules
66
66
  store 'district_heat_use', :field_name => 'DHBTU8', :from_units => :kbtus, :to_units => :megajoules
67
+ store 'district_heat_energy', :field_name => 'DHBTU8', :from_units => :kbtus, :to_units => :megajoules
67
68
  end
68
69
 
69
- process "Derive fuel intensities per room night for lodging buildings" do
70
- # days/year * weeks/day * years/month = weeks/month
71
- # weeks/month * months used in a year = weeks used in a year
72
- # weeks used in a year * hours/week = hours used in a year
73
- # hours used in a year * days/hour = days used in a year
70
+ process "Derive room nights for lodging records" do
71
+ lodging_records.
72
+ # nights/year * weeks/night * years/month * months * hours/week * nights/hour * rooms = room-nights
73
+ # => weeks/year => weeks/month => weeks => hours => nights => room-nights
74
+ update_all "room_nights = (365.0 * (1 / 7.0) * (1 / 12.0) * months_used * weekly_hours * (1 / 24.0) * lodging_rooms)"
75
+ end
76
+
77
+ process "Derive fuel intensities per room night for lodging records" do
74
78
  [:natural_gas, :fuel_oil, :electricity, :district_heat].each do |fuel|
75
79
  lodging_records.update_all %{
76
- #{fuel}_per_room_night = #{fuel}_use / (365.0 / 7.0 / 12.0 * months_used * weekly_hours / 24.0 * lodging_rooms),
80
+ #{fuel}_per_room_night = #{fuel}_use / room_nights,
77
81
  #{fuel}_per_room_night_units = #{fuel}_use_units || '_per_room_night'
78
82
  }
79
83
  end
80
84
  end
81
-
82
- process "Derive fuel intensities per unit area" do
83
- [:natural_gas, :fuel_oil, :electricity].each do |fuel|
84
- update_all %{
85
- #{fuel}_energy_intensity = #{fuel}_energy / area,
86
- #{fuel}_energy_intensity_units = 'megajoules_per_square_metre'
87
- }
88
- update_all %{
89
- district_heat_energy_intensity = district_heat_use / area,
90
- district_heat_energy_intensity_units = 'megajoules_per_square_metre'
91
- }
92
- end
93
- end
94
85
  end
95
86
  end
@@ -16,30 +16,24 @@ CountryLodgingClass.class_eval do
16
16
 
17
17
  process "Calculate US lodging class fuel intensities from CommercialBuildingEnergyConsumptionSurveyResponse" do
18
18
  occupancy_rate = Country.united_states.lodging_occupancy_rate
19
- connection.select_values("SELECT DISTINCT cbecs_detailed_activity FROM #{CountryLodgingClass.quoted_table_name}").each do |cbecs_activity|
20
- [:natural_gas, :fuel_oil, :electricity, :district_heat].each do |fuel|
21
- where(:cbecs_detailed_activity => cbecs_activity).update_all(%{
22
- #{fuel}_intensity = (
23
- SELECT SUM(
24
- weighting * #{fuel}_use / (365.0 / 7.0 / 12.0 * months_used * weekly_hours / 24.0 * lodging_rooms * #{occupancy_rate})
25
- ) / SUM(weighting)
26
- FROM #{CommercialBuildingEnergyConsumptionSurveyResponse.quoted_table_name}
27
- WHERE detailed_activity = '#{cbecs_activity}'
28
- )
29
- })
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
+ }
30
36
  end
31
-
32
- where(:cbecs_detailed_activity => cbecs_activity).update_all(%{
33
- natural_gas_intensity_units = 'cubic_metres_per_room_night',
34
- fuel_oil_intensity_units = 'litres_per_room_night',
35
- electricity_intensity_units = 'kilowatt_hours_per_room_night',
36
- district_heat_intensity_units = 'megajoules_per_room_night',
37
- weighting = (
38
- SELECT SUM(weighting)
39
- FROM #{CommercialBuildingEnergyConsumptionSurveyResponse.quoted_table_name}
40
- WHERE detailed_activity = '#{cbecs_activity}'
41
- ) / #{where(:cbecs_detailed_activity => cbecs_activity).count}
42
- })
43
37
  end
44
38
  end
45
39
  end
@@ -26,4 +26,8 @@ class LodgingProperty < ActiveRecord::Base
26
26
  col :pools_indoor, :type => :float # float b/c fallback needs to be a float
27
27
  col :pools_outdoor, :type => :float # float b/c fallback needs to be a float
28
28
  col :update_date
29
+ add_index :city
30
+ add_index :locality
31
+ add_index :postcode
32
+ add_index :country_iso_3166_alpha_3_code
29
33
  end
@@ -28,21 +28,30 @@ class MecsEnergy < ActiveRecord::Base
28
28
  FUELS = [:electricity, :residual_fuel_oil, :distillate_fuel_oil,
29
29
  :natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other_fuel]
30
30
 
31
- # Find the first record whose naics_code matches code.
31
+ # Find the first record whose naics_code matches code and that has valid fuel ratios.
32
32
  # If no record found chop off the last character of code and try again, and so on.
33
33
  def self.find_by_naics_code(code)
34
34
  find_by_naics_code_and_census_region_number(code, nil)
35
35
  end
36
36
 
37
- # Find the first record whose census_region_number matches number and whose naics_code matches code.
38
- # If no record found chop off the last character of code and try again, and so on.
39
- def self.find_by_naics_code_and_census_region_number(code, number)
37
+ # Find the first record whose census_region_number matches number, whose naics_code matches code, and that has valid fuel ratios.
38
+ # If none found and we know census region number, try looking nationwide
39
+ # If none found and looking nationwide, chop off the last character of code and try again looking in census region
40
+ # And so on
41
+ def self.find_by_naics_code_and_census_region_number(code, number, original_number = number)
40
42
  if code.blank?
41
43
  record = nil
42
44
  else
43
45
  code = Industry.format_naics_code code
44
- record = where(:census_region_number => number, :naics_code => code).first
45
- record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
46
+ candidate = where(:census_region_number => number, :naics_code => code).first
47
+
48
+ if candidate.try(:fuel_ratios).present?
49
+ record = candidate
50
+ elsif number.present?
51
+ record = find_by_naics_code_and_census_region_number(code, nil, original_number)
52
+ else
53
+ record = find_by_naics_code_and_census_region_number(code[0..-2], original_number)
54
+ end
46
55
  end
47
56
  record
48
57
  end
@@ -12,21 +12,30 @@ class MecsRatio < ActiveRecord::Base
12
12
  col :energy_per_dollar_of_shipments, :type => :float
13
13
  col :energy_per_dollar_of_shipments_units
14
14
 
15
- # Find the first record whose naics_code matches code.
15
+ # Find the first record whose naics_code matches code and whose energy per dollar shipment is present.
16
16
  # If no record found chop off the last character of code and try again, and so on.
17
17
  def self.find_by_naics_code(code)
18
- find_by_naics_code_and_census_region_number(code, nil)
18
+ candidate = find_by_naics_code_and_census_region_number(code, nil)
19
19
  end
20
20
 
21
- # Find the first record whose census_region_number matches number and whose naics_code matches code.
22
- # If none found, chop off the last character of code and try again, and so on.
23
- def self.find_by_naics_code_and_census_region_number(code, number)
21
+ # Find the first record whose census_region_number matches number, whose naics_code matches code, and whose energy per dollar of shipments is present.
22
+ # If none found and we know census region number, try looking nationwide
23
+ # If none found and looking nationwide, chop off the last character of code and try again looking in census region
24
+ # And so on
25
+ def self.find_by_naics_code_and_census_region_number(code, number, original_number = number)
24
26
  if code.blank?
25
27
  record = nil
26
28
  else
27
29
  code = Industry.format_naics_code code
28
- record = where(:census_region_number => number, :naics_code => code).first
29
- record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
30
+ candidate = where(:census_region_number => number, :naics_code => code).first
31
+
32
+ if candidate.try(:energy_per_dollar_of_shipments).present?
33
+ record = candidate
34
+ elsif number.present?
35
+ record = find_by_naics_code_and_census_region_number(code, nil, original_number)
36
+ else
37
+ record = find_by_naics_code_and_census_region_number(code[0..-2], original_number)
38
+ end
30
39
  end
31
40
  record
32
41
  end
@@ -4,7 +4,6 @@ class Sic1987 < ActiveRecord::Base
4
4
 
5
5
  has_many :naics_2002_sic_1987_concordances, :foreign_key => :sic_1987_code
6
6
  has_many :naics_2002, :through => :naics_2002_sic_1987_concordances
7
- has_many :industries, :through => :naics_2002
8
7
 
9
8
  # for data import
10
9
  def self.format_description(description)
@@ -9,28 +9,21 @@ Country.class_eval do
9
9
  import "OpenGeoCode.org's Country Codes to Country Names list",
10
10
  :url => 'http://opengeocode.org/download/countrynames.txt',
11
11
  :format => :delimited,
12
- :delimiter => ';',
12
+ :delimiter => '; ',
13
13
  :headers => false,
14
14
  :skip => 22 do
15
15
  key 'iso_3166_code', :field_number => 0
16
16
  store 'iso_3166_alpha_3_code', :field_number => 1
17
17
  store 'iso_3166_numeric_code', :field_number => 2
18
- store 'name', :field_number => 5 # romanized version
18
+ store 'name', :field_number => 5 # romanized version with utf-8 characters
19
19
  end
20
20
 
21
- import "heating degree day data from WRI CAIT",
21
+ import "heating and cooling degree day data from WRI CAIT",
22
22
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDN4MkRTSWtWRjdfazhRdWllTkVSMkE&output=csv',
23
23
  :select => Proc.new { |record| record['country'] != 'European Union (27)' },
24
24
  :errata => { :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDNSMUtCV0h4cUF4UnBKZlNkczlNbFE&output=csv' } do
25
25
  key 'name', :field_name => 'country'
26
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
27
  store 'cooling_degree_days', :units => :degrees_celsius
35
28
  end
36
29
 
@@ -142,13 +135,13 @@ Country.class_eval do
142
135
  find_each do |country|
143
136
  if country.lodging_classes.any?
144
137
  country.lodging_natural_gas_intensity = country.lodging_classes.weighted_average(:natural_gas_intensity)
145
- country.lodging_natural_gas_intensity_units = 'cubic_metres_per_room_night' # FIXME TODO derive this
138
+ country.lodging_natural_gas_intensity_units = 'cubic_metres_per_occupied_room_night' # FIXME TODO derive this
146
139
  country.lodging_fuel_oil_intensity = country.lodging_classes.weighted_average(:fuel_oil_intensity)
147
- country.lodging_fuel_oil_intensity_units = 'gallons_per_room_night' # FIXME TODO derive this
140
+ country.lodging_fuel_oil_intensity_units = 'gallons_per_occupied_room_night' # FIXME TODO derive this
148
141
  country.lodging_electricity_intensity = country.lodging_classes.weighted_average(:electricity_intensity)
149
- country.lodging_electricity_intensity_units = 'kilowatt_hours_per_room_night' # FIXME TODO derive this
142
+ country.lodging_electricity_intensity_units = 'kilowatt_hours_per_occupied_room_night' # FIXME TODO derive this
150
143
  country.lodging_district_heat_intensity = country.lodging_classes.weighted_average(:district_heat_intensity)
151
- country.lodging_district_heat_intensity_units = 'megajoules_per_room_night' # FIXME TODO derive this
144
+ country.lodging_district_heat_intensity_units = 'megajoules_per_occupied_room_night' # FIXME TODO derive this
152
145
  country.save!
153
146
  end
154
147
  end
@@ -9,7 +9,7 @@ ZipCode.class_eval do
9
9
 
10
10
  data_miner do
11
11
  import 'the Mapping Hacks zipcode database',
12
- :url => 'http://mappinghacks.com/data/zipcode.zip',
12
+ :url => 'http://archive.data.brighterplanet.com/zipcode.zip', # http://mappinghacks.com/data/zipcode.zip'
13
13
  :filename => 'zipcode.csv' do
14
14
  key 'name', :field_name => 'zip', :sprintf => '%05d'
15
15
  store 'state_postal_abbreviation', :field_name => 'state'
@@ -32,13 +32,11 @@ ZipCode.class_eval do
32
32
  store 'climate_division_name'
33
33
  end
34
34
 
35
- # TODO: download file directly from US census
36
35
  # NOTE: ZCTAs are not zip codes but are based on the most common zip code in the area they cover - see http://www.census.gov/geo/ZCTA/zcta.html
37
36
  import 'US Census 2010 zip code tabulation area populations',
38
- :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHJsVjlKNXNLNEQyWENjZ1owd2hFS3c&output=csv',
39
- :skip => 1 do
40
- key 'name', :field_name => 'Id2', :sprintf => '%05d'
41
- store 'population', :field_name => 'Total'
37
+ :url => 'http://www.census.gov/geo/www/2010census/zcta_rel/zcta_county_rel_10.txt' do
38
+ key 'name', :field_name => 'ZCTA5', :sprintf => '%05d'
39
+ store 'population', :field_name => 'ZPOP'
42
40
  end
43
41
 
44
42
  import 'misc zip code data not included in other sources',
data/lib/earth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.11.13"
2
+ VERSION = "0.11.14"
3
3
  end
@@ -3,7 +3,7 @@ require 'earth/air/aircraft'
3
3
  require 'earth/air/aircraft/data_miner'
4
4
 
5
5
  describe Aircraft do
6
- describe 'import', :slow => true do
6
+ describe 'import', :data_miner => true do
7
7
  it 'should treat empty cells as null' do
8
8
  Aircraft.auto_upgrade!
9
9
  Aircraft.run_data_miner!
@@ -3,7 +3,7 @@ require 'earth/automobile'
3
3
  require 'earth/automobile/data_miner'
4
4
 
5
5
  describe AutomobileFuel do
6
- describe 'import', :slow => true do
6
+ describe 'import', :data_miner => true do
7
7
  it 'should import data without problems' do
8
8
  AutomobileFuel.run_data_miner!
9
9
  AutomobileFuel.all.count.should > 0