earth 0.11.10 → 0.11.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/Gemfile +4 -0
  2. data/Guardfile +35 -0
  3. data/README.markdown +94 -20
  4. data/Rakefile +4 -0
  5. data/earth.gemspec +14 -12
  6. data/lib/earth/air/aircraft.rb +2 -2
  7. data/lib/earth/air/aircraft_instance.rb +2 -2
  8. data/lib/earth/air/aircraft_instance_seat_class.rb +2 -2
  9. data/lib/earth/air/airline.rb +2 -2
  10. data/lib/earth/air/airport.rb +2 -2
  11. data/lib/earth/air/bts_aircraft.rb +2 -2
  12. data/lib/earth/air/flight_distance_class.rb +1 -1
  13. data/lib/earth/air/flight_distance_class_seat_class.rb +1 -1
  14. data/lib/earth/air/flight_seat_class.rb +1 -1
  15. data/lib/earth/air/flight_segment.rb +1 -1
  16. data/lib/earth/automobile/automobile_fuel.rb +1 -1
  17. data/lib/earth/automobile/automobile_make.rb +1 -1
  18. data/lib/earth/automobile/automobile_make_model.rb +1 -1
  19. data/lib/earth/automobile/automobile_make_model_year.rb +1 -1
  20. data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -1
  21. data/lib/earth/automobile/automobile_make_year.rb +1 -1
  22. data/lib/earth/automobile/automobile_make_year_fleet.rb +1 -1
  23. data/lib/earth/automobile/automobile_model.rb +1 -1
  24. data/lib/earth/automobile/automobile_size_class.rb +1 -1
  25. data/lib/earth/automobile/automobile_size_class_year.rb +1 -1
  26. data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -1
  27. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
  28. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -1
  29. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -1
  30. data/lib/earth/automobile/automobile_type_year.rb +2 -2
  31. data/lib/earth/automobile/automobile_year.rb +1 -1
  32. data/lib/earth/bus/bus_class.rb +1 -1
  33. data/lib/earth/bus/bus_fuel.rb +2 -2
  34. data/lib/earth/bus/bus_fuel_control.rb +2 -2
  35. data/lib/earth/bus/bus_fuel_year_control.rb +2 -2
  36. data/lib/earth/computation/computation_carrier.rb +2 -2
  37. data/lib/earth/computation/computation_carrier_instance_class.rb +2 -2
  38. data/lib/earth/computation/computation_carrier_region.rb +2 -2
  39. data/lib/earth/conversions_ext.rb +26 -7
  40. data/lib/earth/diet/diet_class.rb +2 -2
  41. data/lib/earth/diet/food_group.rb +2 -2
  42. data/lib/earth/eia.rb +13 -13
  43. data/lib/earth/fuel/fuel.rb +22 -13
  44. data/lib/earth/fuel/fuel/data_miner.rb +36 -44
  45. data/lib/earth/fuel/fuel_price.rb +1 -1
  46. data/lib/earth/fuel/fuel_type.rb +2 -2
  47. data/lib/earth/fuel/fuel_year.rb +4 -2
  48. data/lib/earth/fuel/greenhouse_gas.rb +2 -2
  49. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +14 -5
  50. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +22 -1
  51. data/lib/earth/hospitality/country_lodging_class.rb +3 -3
  52. data/lib/earth/hospitality/country_lodging_class/data_miner.rb +7 -5
  53. data/lib/earth/hospitality/lodging_class.rb +1 -1
  54. data/lib/earth/hospitality/lodging_property.rb +8 -8
  55. data/lib/earth/industry/cbecs_energy_intensity.rb +59 -6
  56. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +266 -69
  57. data/lib/earth/industry/industry.rb +1 -1
  58. data/lib/earth/industry/industry_product.rb +2 -2
  59. data/lib/earth/industry/industry_product_line.rb +2 -2
  60. data/lib/earth/industry/industry_sector.rb +2 -2
  61. data/lib/earth/industry/mecs_energy.rb +26 -15
  62. data/lib/earth/industry/mecs_energy/data_miner.rb +39 -23
  63. data/lib/earth/industry/mecs_ratio.rb +13 -10
  64. data/lib/earth/industry/mecs_ratio/data_miner.rb +14 -14
  65. data/lib/earth/industry/merchant.rb +2 -2
  66. data/lib/earth/industry/merchant_category.rb +2 -2
  67. data/lib/earth/industry/merchant_category_industry.rb +2 -2
  68. data/lib/earth/industry/product_line.rb +2 -2
  69. data/lib/earth/industry/product_line_industry_product.rb +2 -2
  70. data/lib/earth/industry/sector.rb +2 -2
  71. data/lib/earth/locality/census_division.rb +2 -2
  72. data/lib/earth/locality/census_division/data_miner.rb +4 -14
  73. data/lib/earth/locality/census_region.rb +2 -2
  74. data/lib/earth/locality/climate_division.rb +1 -17
  75. data/lib/earth/locality/country.rb +14 -28
  76. data/lib/earth/locality/country/data_miner.rb +8 -2
  77. data/lib/earth/locality/egrid_country.rb +1 -1
  78. data/lib/earth/locality/egrid_region.rb +4 -1
  79. data/lib/earth/locality/egrid_region/data_miner.rb +4 -1
  80. data/lib/earth/locality/egrid_subregion.rb +1 -1
  81. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -0
  82. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +3 -3
  83. data/lib/earth/locality/state.rb +2 -7
  84. data/lib/earth/locality/zip_code.rb +1 -1
  85. data/lib/earth/pet/breed.rb +2 -2
  86. data/lib/earth/pet/breed_gender.rb +2 -2
  87. data/lib/earth/pet/gender.rb +2 -2
  88. data/lib/earth/pet/species.rb +2 -2
  89. data/lib/earth/pet/species/data_miner.rb +0 -9
  90. data/lib/earth/rail/country_rail_class.rb +1 -1
  91. data/lib/earth/rail/country_rail_traction.rb +1 -1
  92. data/lib/earth/rail/country_rail_traction_class.rb +1 -1
  93. data/lib/earth/rail/national_transit_database_company.rb +2 -2
  94. data/lib/earth/rail/national_transit_database_mode.rb +2 -2
  95. data/lib/earth/rail/national_transit_database_record.rb +2 -2
  96. data/lib/earth/rail/national_transit_database_record/data_miner.rb +12 -33
  97. data/lib/earth/rail/rail_class.rb +1 -1
  98. data/lib/earth/rail/rail_company.rb +1 -1
  99. data/lib/earth/rail/rail_company_traction.rb +1 -1
  100. data/lib/earth/rail/rail_company_traction_class.rb +1 -1
  101. data/lib/earth/rail/rail_fuel.rb +1 -1
  102. data/lib/earth/rail/rail_traction.rb +1 -1
  103. data/lib/earth/residence/air_conditioner_use.rb +2 -2
  104. data/lib/earth/residence/clothes_machine_use.rb +2 -2
  105. data/lib/earth/residence/dishwasher_use.rb +2 -2
  106. data/lib/earth/residence/residence_appliance.rb +2 -2
  107. data/lib/earth/residence/residence_class.rb +2 -2
  108. data/lib/earth/residence/residence_fuel_price.rb +2 -2
  109. data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -5
  110. data/lib/earth/residence/residence_fuel_type.rb +2 -2
  111. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +3 -3
  112. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -5
  113. data/lib/earth/residence/urbanity.rb +2 -2
  114. data/lib/earth/shipping/carrier.rb +3 -2
  115. data/lib/earth/shipping/carrier/data_miner.rb +1 -0
  116. data/lib/earth/shipping/carrier_mode.rb +2 -2
  117. data/lib/earth/shipping/shipment_mode.rb +2 -2
  118. data/lib/earth/version.rb +1 -1
  119. data/spec/earth/air/aircraft_spec.rb +421 -0
  120. data/spec/earth/fuel/fuel_spec.rb +35 -0
  121. data/spec/earth/hospitality/lodging_fuel_use_equation_spec.rb +96 -0
  122. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +102 -0
  123. data/spec/earth/industry/mecs_energy_spec.rb +36 -44
  124. data/spec/earth/industry/mecs_ratio_spec.rb +24 -17
  125. data/spec/earth/locality/country_spec.rb +0 -9
  126. data/spec/spec_helper.rb +8 -3
  127. data/spec/support/integration.rb +17 -0
  128. data/vendor/geokit-rails/init.rb +2 -1
  129. data/vendor/geokit-rails/lib/geokit-rails.rb +1 -0
  130. metadata +63 -36
  131. data/lib/earth/hospitality/lodging_fuel_use_equation.rb +0 -26
  132. data/lib/earth/hospitality/lodging_fuel_use_equation/data_miner.rb +0 -20
  133. data/test/test_aircraft_match.rb +0 -732
@@ -3,29 +3,11 @@ require 'earth/hospitality'
3
3
  require 'earth/rail'
4
4
 
5
5
  class Country < ActiveRecord::Base
6
- set_primary_key :iso_3166_code
6
+ self.primary_key = "iso_3166_code"
7
7
 
8
8
  has_many :rail_companies, :foreign_key => 'country_iso_3166_code' # used to calculate rail data
9
9
  has_many :lodging_classes, :foreign_key => 'country_iso_3166_code', :class_name => 'CountryLodgingClass'
10
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
-
29
11
  falls_back_on :name => 'fallback',
30
12
  :automobile_urbanity => lambda { united_states.automobile_urbanity }, # for now assume US represents world
31
13
  :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
@@ -39,14 +21,15 @@ class Country < ActiveRecord::Base
39
21
  :electricity_emission_factor => 0.69252, # from ecometrica paper - FIXME TODO calculate this
40
22
  :electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour', # FIXME TODO derive this
41
23
  :flight_route_inefficiency_factor => lambda { maximum(:flight_route_inefficiency_factor) }, # default to the largest inefficiency factor
24
+ :lodging_occupancy_rate => lambda { united_states.lodging_occupancy_rate }, # for now assume US represents world
42
25
  :lodging_natural_gas_intensity => lambda { united_states.lodging_natural_gas_intensity }, # for now assume US represents world
43
26
  :lodging_natural_gas_intensity_units => lambda { united_states.lodging_natural_gas_intensity_units }, # for now assume US represents world
44
27
  :lodging_fuel_oil_intensity => lambda { united_states.lodging_fuel_oil_intensity }, # for now assume US represents world
45
28
  :lodging_fuel_oil_intensity_units => lambda { united_states.lodging_fuel_oil_intensity_units }, # for now assume US represents world
46
29
  :lodging_electricity_intensity => lambda { united_states.lodging_electricity_intensity }, # for now assume US represents world
47
30
  :lodging_electricity_intensity_units => lambda { united_states.lodging_electricity_intensity_units }, # for now assume US represents world
48
- :lodging_steam_intensity => lambda { united_states.lodging_steam_intensity }, # for now assume US represents world
49
- :lodging_steam_intensity_units => lambda { united_states.lodging_steam_intensity_units }, # for now assume US represents world
31
+ :lodging_district_heat_intensity => lambda { united_states.lodging_district_heat_intensity }, # for now assume US represents world
32
+ :lodging_district_heat_intensity_units => lambda { united_states.lodging_district_heat_intensity_units }, # for now assume US represents world
50
33
  :rail_trip_distance => lambda { weighted_average(:rail_trip_distance, :weighted_by => :rail_passengers) },
51
34
  :rail_trip_distance_units => 'kilometres', # FIXME TODO derive this
52
35
  :rail_speed => lambda { weighted_average(:rail_speed, :weighted_by => :rail_passengers) },
@@ -56,12 +39,14 @@ class Country < ActiveRecord::Base
56
39
  :rail_trip_diesel_intensity => lambda { weighted_average(:rail_trip_diesel_intensity, :weighted_by => :rail_passengers) },
57
40
  :rail_trip_diesel_intensity_units => 'litres_per_passenger_kilometre', # FIXME TODO derive this
58
41
  :rail_trip_co2_emission_factor => lambda { weighted_average(:rail_trip_co2_emission_factor, :weighted_by => :rail_passengers) },
59
- :rail_trip_co2_emission_factor_units => 'kilograms' # FIXME TODO derive this
42
+ :rail_trip_co2_emission_factor_units => 'kilograms_per_passenger_kilometre' # FIXME TODO derive this
43
+
44
+ def self.united_states
45
+ find_by_iso_3166_code('US')
46
+ end
60
47
 
61
- class << self
62
- def united_states
63
- find_by_iso_3166_code('US')
64
- end
48
+ def united_states?
49
+ iso_3166_code == 'US'
65
50
  end
66
51
 
67
52
  col :iso_3166_code # alpha-2 2-letter like GB
@@ -84,14 +69,15 @@ class Country < ActiveRecord::Base
84
69
  col :electricity_emission_factor, :type => :float
85
70
  col :electricity_emission_factor_units
86
71
  col :flight_route_inefficiency_factor, :type => :float
72
+ col :lodging_occupancy_rate, :type => :float
87
73
  col :lodging_natural_gas_intensity, :type => :float
88
74
  col :lodging_natural_gas_intensity_units
89
75
  col :lodging_fuel_oil_intensity, :type => :float
90
76
  col :lodging_fuel_oil_intensity_units
91
77
  col :lodging_electricity_intensity, :type => :float
92
78
  col :lodging_electricity_intensity_units
93
- col :lodging_steam_intensity, :type => :float
94
- col :lodging_steam_intensity_units
79
+ col :lodging_district_heat_intensity, :type => :float
80
+ col :lodging_district_heat_intensity_units
95
81
  col :rail_passengers, :type => :float
96
82
  col :rail_trip_distance, :type => :float
97
83
  col :rail_trip_distance_units
@@ -131,6 +131,12 @@ Country.class_eval do
131
131
  end
132
132
 
133
133
  # HOSPITALITY
134
+ process "Define US average lodging occupancy rate" do
135
+ country = united_states
136
+ country.lodging_occupancy_rate = 0.601 # per http://www.pwc.com/us/en/press-releases/2012/pwc-us-lodging-industry-forecast.jhtml
137
+ country.save!
138
+ end
139
+
134
140
  process "Ensure CountryLodgingClass is populated" do
135
141
  CountryLodgingClass.run_data_miner!
136
142
  end
@@ -144,8 +150,8 @@ Country.class_eval do
144
150
  country.lodging_fuel_oil_intensity_units = 'gallons_per_room_night' # FIXME TODO derive this
145
151
  country.lodging_electricity_intensity = country.lodging_classes.weighted_average(:electricity_intensity)
146
152
  country.lodging_electricity_intensity_units = 'kilowatt_hours_per_room_night' # FIXME TODO derive this
147
- country.lodging_steam_intensity = country.lodging_classes.weighted_average(:steam_intensity)
148
- country.lodging_steam_intensity_units = 'megajoules_per_room_night' # FIXME TODO derive this
153
+ country.lodging_district_heat_intensity = country.lodging_classes.weighted_average(:district_heat_intensity)
154
+ country.lodging_district_heat_intensity_units = 'megajoules_per_room_night' # FIXME TODO derive this
149
155
  country.save!
150
156
  end
151
157
  end
@@ -1,5 +1,5 @@
1
1
  class EgridCountry < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  class << self
5
5
  def us
@@ -1,11 +1,14 @@
1
1
  class EgridRegion < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
+ # make EgridCountry a parent so that it automatically gets data_mined (need it for fallback calculation)
5
+ belongs_to :egrid_country, :foreign_key => 'country_name'
4
6
  has_many :egrid_subregions, :foreign_key => 'egrid_region_name'
5
7
 
6
8
  falls_back_on :name => 'fallback',
7
9
  :loss_factor => lambda { (EgridCountry.us.generation + EgridCountry.us.imports - EgridCountry.us.consumption) / EgridCountry.us.generation }
8
10
 
9
11
  col :name
12
+ col :country_name
10
13
  col :loss_factor, :type => :float
11
14
  end
@@ -6,15 +6,18 @@ EgridRegion.class_eval do
6
6
  :skip => 4,
7
7
  :select => lambda { |row| row['eGRID2010 year 2007 file state sequence number'].to_i.between?(1, 51) } do
8
8
  key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
9
+ store 'country_name', :static => 'US'
9
10
  store 'loss_factor', :field_name => 'Year 2007 grid gross loss factor'
10
11
  end
11
12
 
12
- # Need this for fallback loss_factor calculation
13
+ # DEPRECATED but don't remove until confirmed that all emitters use EgridRegion.fallback rather than EgridRegion.find_by_abbreviation 'US'
14
+ # (ElectricityUse and Meeting)
13
15
  process "Ensure EgridCountry is populated" do
14
16
  EgridCountry.run_data_miner!
15
17
  end
16
18
 
17
19
  # DEPRECATED but don't remove until confirmed that all emitters use EgridRegion.fallback rather than EgridRegion.find_by_abbreviation 'US'
20
+ # (ElectricityUse and Meeting)
18
21
  process "Calculate national averages" do
19
22
  us_average = find_or_create_by_name 'US'
20
23
  us_average.loss_factor = (EgridCountry.us.generation + EgridCountry.us.imports - EgridCountry.us.consumption) / EgridCountry.us.generation
@@ -1,6 +1,6 @@
1
1
  require 'earth/fuel'
2
2
  class EgridSubregion < ActiveRecord::Base
3
- set_primary_key :abbreviation
3
+ self.primary_key = "abbreviation"
4
4
 
5
5
  has_many :zip_codes, :foreign_key => 'egrid_subregion_abbreviation'
6
6
  belongs_to :egrid_region, :foreign_key => 'egrid_region_name'
@@ -25,6 +25,7 @@ EgridSubregion.class_eval do
25
25
  end
26
26
 
27
27
  # DEPRECATED but don't remove until confirmed that all emitters use EgridSubregion.fallback rather than EgridSubregion.find_by_abbreviation 'US'
28
+ # (ElectricityUse and Meeting)
28
29
  process "Calculate national averages" do
29
30
  us_average = find_by_abbreviation 'US'
30
31
  subregions = where("abbreviation != 'US'")
@@ -1,6 +1,6 @@
1
1
  class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
2
- set_primary_key :code
3
- set_table_name :petroleum_districts
2
+ self.primary_key = "code"
3
+ self.table_name = :petroleum_districts
4
4
 
5
5
  def name
6
6
  str = "PAD District #{district_code} (#{district_name})"
@@ -13,4 +13,4 @@ class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
13
13
  col :district_name
14
14
  col :subdistrict_code
15
15
  col :subdistrict_name
16
- end
16
+ end
@@ -1,5 +1,5 @@
1
1
  class State < ActiveRecord::Base
2
- set_primary_key :postal_abbreviation
2
+ self.primary_key = "postal_abbreviation"
3
3
 
4
4
  has_many :climate_divisions, :foreign_key => 'state_postal_abbreviation'
5
5
  has_many :zip_codes, :foreign_key => 'state_postal_abbreviation'
@@ -11,14 +11,9 @@ class State < ActiveRecord::Base
11
11
  Country.united_states
12
12
  end
13
13
 
14
- def climate_zone_number
15
- potential_zones = climate_divisions.map(&:climate_zone_number)
16
- potential_zones.uniq.length == 1 ? potential_zones.first : nil
17
- end
18
-
19
14
  col :postal_abbreviation
20
15
  col :fips_code, :type => :integer
21
16
  col :name
22
- col :census_division_number
17
+ col :census_division_number, :type => :integer
23
18
  col :petroleum_administration_for_defense_district_code
24
19
  end
@@ -1,7 +1,7 @@
1
1
  require ::File.join(Earth.vendor_dir, 'geokit-rails', 'lib', 'geokit-rails')
2
2
 
3
3
  class ZipCode < ActiveRecord::Base
4
- set_primary_key :name
4
+ self.primary_key = "name"
5
5
 
6
6
  belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
7
7
  belongs_to :climate_division, :foreign_key => 'climate_division_name'
@@ -1,5 +1,5 @@
1
1
  class Breed < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  has_many :breed_genders, :foreign_key => 'breed_name'
5
5
  belongs_to :species, :foreign_key => 'species_name'
@@ -8,4 +8,4 @@ class Breed < ActiveRecord::Base
8
8
  col :species_name
9
9
  col :weight, :type => :float
10
10
  col :weight_units
11
- end
11
+ end
@@ -1,5 +1,5 @@
1
1
  class BreedGender < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  belongs_to :breed, :foreign_key => 'breed_name'
5
5
  belongs_to :gender, :foreign_key => 'gender_name'
@@ -9,4 +9,4 @@ class BreedGender < ActiveRecord::Base
9
9
  col :gender_name
10
10
  col :weight, :type => :float
11
11
  col :weight_units
12
- end
12
+ end
@@ -1,7 +1,7 @@
1
1
  class Gender < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  has_many :breed_genders, :foreign_key => 'gender_name'
5
5
 
6
6
  col :name
7
- end
7
+ end
@@ -1,5 +1,5 @@
1
1
  class Species < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  col :name
5
5
  col :population, :type => :integer
@@ -55,4 +55,4 @@ class Species < ActiveRecord::Base
55
55
  def cat?
56
56
  eql? self.class[:cat]
57
57
  end
58
- end
58
+ end
@@ -1,14 +1,5 @@
1
1
  Species.class_eval do
2
2
  data_miner do
3
- process "Define some unit conversions" do
4
- # 1 (kilocalories per pound) = 9 224.14105 joules per kilogram
5
- Conversions.register :kilocalories_per_pound, :joules_per_kilogram, 9_224.14105
6
- # 1 (grams per kilocalories) = 2.39005736 × 10-7 kilograms per joules
7
- Conversions.register :grams_per_kilocalorie, :kilograms_per_joule, 2.39005736e-7
8
- # 1 joule = 0.000239005736 kilocalories
9
- Conversions.register :joules, :kilocalories, 0.000239005736
10
- end
11
-
12
3
  import "a list of pet species weights, dietary requirements, and diet emissions intensities",
13
4
  :url => 'http://static.brighterplanet.com/science/data/consumables/pets/species.csv' do
14
5
  key 'name', :field_name => 'species'
@@ -1,6 +1,6 @@
1
1
  require 'earth/locality'
2
2
  class CountryRailClass < ActiveRecord::Base
3
- set_primary_key :name
3
+ self.primary_key = "name"
4
4
 
5
5
  col :name
6
6
  col :country_iso_3166_code
@@ -1,7 +1,7 @@
1
1
  require 'earth/fuel'
2
2
  require 'earth/locality'
3
3
  class CountryRailTraction < ActiveRecord::Base
4
- set_primary_key :name
4
+ self.primary_key = "name"
5
5
 
6
6
  col :name
7
7
  col :country_iso_3166_code
@@ -1,7 +1,7 @@
1
1
  require 'earth/fuel'
2
2
  require 'earth/locality'
3
3
  class CountryRailTractionClass < ActiveRecord::Base
4
- set_primary_key :name
4
+ self.primary_key = "name"
5
5
 
6
6
  col :name
7
7
  col :country_iso_3166_code
@@ -1,7 +1,7 @@
1
1
  require 'earth/locality'
2
2
  class NationalTransitDatabaseCompany < ActiveRecord::Base
3
- set_primary_key :id
4
- set_table_name :ntd_companies
3
+ self.primary_key = "id"
4
+ self.table_name = :ntd_companies
5
5
 
6
6
  has_many :ntd_records, :foreign_key => 'company_id', :primary_key => 'id', :class_name => 'NationalTransitDatabaseRecord'
7
7
 
@@ -1,6 +1,6 @@
1
1
  class NationalTransitDatabaseMode < ActiveRecord::Base
2
- set_primary_key :code
3
- set_table_name :ntd_modes
2
+ self.primary_key = "code"
3
+ self.table_name = :ntd_modes
4
4
 
5
5
  def self.rail_modes
6
6
  where(:rail_mode => true)
@@ -1,7 +1,7 @@
1
1
  require 'earth/fuel'
2
2
  class NationalTransitDatabaseRecord < ActiveRecord::Base
3
- set_primary_key :name
4
- set_table_name :ntd_records
3
+ self.primary_key = "name"
4
+ self.table_name = :ntd_records
5
5
 
6
6
  belongs_to :ntd_company, :foreign_key => 'company_id', :class_name => 'NationalTransitDatabaseCompany'
7
7
 
@@ -7,49 +7,28 @@ NationalTransitDatabaseRecord.class_eval do
7
7
  store 'company_id', :field_name => 'trs_id'
8
8
  store 'mode_code'
9
9
  store 'service_type', :field_name => 'service_code', :dictionary => { :input => 'code', :output => 'name', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBTZENxb3A1SzJaNTVEVGZ5cTdaMVE&output=csv' }
10
- store 'vehicle_distance', :field_name => 'vehicle_or_train_revenue_miles', :units => 'miles'
10
+ store 'vehicle_distance', :field_name => 'vehicle_or_train_revenue_miles', :from_units => :miles, :to_units => :kilometres
11
11
  store 'vehicle_time', :field_name => 'vehicle_or_train_revenue_hours', :units => 'hours'
12
- store 'passenger_distance', :field_name => 'passenger_miles', :units => 'miles'
12
+ store 'passenger_distance', :field_name => 'passenger_miles', :from_units => :miles, :to_units => :kilometres
13
13
  store 'passengers'
14
14
  end
15
15
 
16
- # FIXME TODO electricity synthesization should return NULL rather than 0
17
16
  import "US National Transit Database fuel consumption data",
18
17
  :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDItVVR5NjA2Y3FCVjgza25Ccy0zS2c&output=csv' do
19
18
  key 'name', :synthesize => lambda { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
20
19
  store 'company_id', :field_name => 'trs_id'
21
20
  store 'mode_code'
22
21
  store 'service_type', :field_name => 'service_code', :dictionary => { :input => 'code', :output => 'name', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBTZENxb3A1SzJaNTVEVGZ5cTdaMVE&output=csv' }
23
- store 'electricity', :synthesize => lambda { |row| row['electricity_kwh'].to_f + row['battery_kwh'].to_f }, :units => 'kilowatt_hours', :nullify => true
24
- store 'diesel', :field_name => 'diesel_gallons', :units => 'gallons', :nullify => true
25
- store 'gasoline', :field_name => 'gasoline_gallons', :units => 'gallons', :nullify => true
26
- store 'lpg', :field_name => 'lpg_gallons', :units => 'gallons', :nullify => true
27
- store 'lng', :field_name => 'lng_gallons', :units => 'gallons', :nullify => true
28
- store 'cng', :field_name => 'cng_gallons', :units => 'gallons', :nullify => true
29
- store 'kerosene', :field_name => 'kerosene_gallons', :units => 'gallons', :nullify => true
30
- store 'biodiesel', :field_name => 'biodiesel_gallons', :units => 'gallons', :nullify => true
31
- store 'other_fuel', :nullify => true
32
- store 'other_fuel_description', :field_name => 'other_fuel_description', :nullify => true
33
- end
34
-
35
- process "Convert miles to kilometres" do
36
- conversion_factor = 1.miles.to(:kilometres)
37
- %w{ vehicle_distance passenger_distance }.each do |field|
38
- where("#{field}_units" => 'miles').update_all(%{
39
- #{field} = 1.0 * #{field} * #{conversion_factor},
40
- #{field}_units = 'kilometres'
41
- })
42
- end
43
- end
44
-
45
- process "Convert gallons to litres" do
46
- conversion_factor = 1.gallons.to(:litres)
47
- %w{ diesel gasoline lpg lng cng kerosene biodiesel }.each do |fuel|
48
- where("#{fuel}_units" => 'gallons').update_all(%{
49
- #{fuel} = 1.0 * #{fuel} * #{conversion_factor},
50
- #{fuel}_units = 'litres'
51
- })
52
- end
22
+ store 'electricity', :synthesize => lambda { |row| row['electricity_kwh'].to_f + row['battery_kwh'].to_f }, :units => 'kilowatt_hours'
23
+ store 'diesel', :field_name => 'diesel_gallons', :from_units => :gallons, :to_units => :litres
24
+ store 'gasoline', :field_name => 'gasoline_gallons', :from_units => :gallons, :to_units => :litres
25
+ store 'lpg', :field_name => 'lpg_gallons', :from_units => :gallons, :to_units => :litres
26
+ store 'lng', :field_name => 'lng_gallons', :from_units => :gallons, :to_units => :litres
27
+ store 'cng', :field_name => 'cng_gallons', :from_units => :gallons, :to_units => :litres
28
+ store 'kerosene', :field_name => 'kerosene_gallons', :from_units => :gallons, :to_units => :litres
29
+ store 'biodiesel', :field_name => 'biodiesel_gallons', :from_units => :gallons, :to_units => :litres
30
+ store 'other_fuel'
31
+ store 'other_fuel_description', :field_name => 'other_fuel_description'
53
32
  end
54
33
  end
55
34
  end
@@ -1,5 +1,5 @@
1
1
  class RailClass < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  col :name
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require 'earth/fuel'
2
2
  require 'earth/locality'
3
3
  class RailCompany < ActiveRecord::Base
4
- set_primary_key :name
4
+ self.primary_key = "name"
5
5
 
6
6
  belongs_to :country, :foreign_key => 'country_iso_3166_code'
7
7
 
@@ -1,6 +1,6 @@
1
1
  require 'earth/fuel'
2
2
  class RailCompanyTraction < ActiveRecord::Base
3
- set_primary_key :name
3
+ self.primary_key = "name"
4
4
  col :name
5
5
  col :rail_company_name
6
6
  col :rail_traction_name
@@ -1,6 +1,6 @@
1
1
  require 'earth/fuel'
2
2
  class RailCompanyTractionClass < ActiveRecord::Base
3
- set_primary_key :name
3
+ self.primary_key = "name"
4
4
 
5
5
  col :name
6
6
  col :rail_company_name