earth 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/Gemfile +1 -1
  2. data/LICENSE-PREAMBLE +1 -1
  3. data/Rakefile +3 -0
  4. data/earth.gemspec +1 -1
  5. data/lib/earth.rb +7 -7
  6. data/lib/earth/air/aircraft.rb +15 -0
  7. data/lib/earth/air/aircraft/data_miner.rb +65 -77
  8. data/lib/earth/air/aircraft_class.rb +1 -1
  9. data/lib/earth/air/aircraft_fuel_use_equation.rb +1 -1
  10. data/lib/earth/air/airline.rb +1 -1
  11. data/lib/earth/air/airport.rb +1 -1
  12. data/lib/earth/air/bts_aircraft.rb +1 -1
  13. data/lib/earth/air/flight_distance_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/air/flight_segment/data_miner.rb +24 -46
  17. data/lib/earth/automobile/automobile_fuel.rb +1 -1
  18. data/lib/earth/automobile/automobile_make.rb +1 -1
  19. data/lib/earth/automobile/automobile_make_fleet_year.rb +1 -1
  20. data/lib/earth/automobile/automobile_make_model.rb +1 -1
  21. data/lib/earth/automobile/automobile_make_model_year.rb +1 -1
  22. data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -1
  23. data/lib/earth/automobile/automobile_make_year.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_age.rb +1 -1
  27. data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -1
  28. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
  29. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -1
  30. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -1
  31. data/lib/earth/automobile/automobile_type_year.rb +1 -1
  32. data/lib/earth/bus/bus_class.rb +1 -1
  33. data/lib/earth/bus/bus_fuel.rb +1 -1
  34. data/lib/earth/bus/bus_fuel_control.rb +1 -1
  35. data/lib/earth/bus/bus_fuel_year_control.rb +1 -1
  36. data/lib/earth/computation/computation_carrier.rb +1 -1
  37. data/lib/earth/computation/computation_carrier_instance_class.rb +1 -1
  38. data/lib/earth/computation/computation_carrier_region.rb +1 -1
  39. data/lib/earth/conversions_ext.rb +1 -0
  40. data/lib/earth/diet/diet_class.rb +1 -1
  41. data/lib/earth/diet/food_group.rb +1 -1
  42. data/lib/earth/fuel/fuel.rb +1 -1
  43. data/lib/earth/fuel/fuel_price.rb +1 -1
  44. data/lib/earth/fuel/fuel_type.rb +1 -1
  45. data/lib/earth/fuel/fuel_year.rb +1 -1
  46. data/lib/earth/fuel/greenhouse_gas.rb +1 -1
  47. data/lib/earth/hospitality/lodging_class.rb +1 -1
  48. data/lib/earth/industry/industry.rb +1 -1
  49. data/lib/earth/industry/industry_product.rb +1 -1
  50. data/lib/earth/industry/industry_product_line.rb +1 -1
  51. data/lib/earth/industry/industry_sector.rb +1 -1
  52. data/lib/earth/industry/merchant.rb +1 -1
  53. data/lib/earth/industry/merchant_category.rb +1 -1
  54. data/lib/earth/industry/merchant_category_industry.rb +1 -1
  55. data/lib/earth/industry/product_line.rb +1 -1
  56. data/lib/earth/industry/product_line_industry_product.rb +1 -1
  57. data/lib/earth/industry/sector.rb +1 -1
  58. data/lib/earth/locality/census_division.rb +1 -1
  59. data/lib/earth/locality/census_region.rb +1 -1
  60. data/lib/earth/locality/climate_division.rb +1 -1
  61. data/lib/earth/locality/country.rb +1 -1
  62. data/lib/earth/locality/egrid_region.rb +1 -1
  63. data/lib/earth/locality/egrid_region/data_miner.rb +10 -0
  64. data/lib/earth/locality/egrid_subregion.rb +1 -1
  65. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +1 -1
  66. data/lib/earth/locality/state.rb +1 -1
  67. data/lib/earth/locality/urbanity.rb +1 -1
  68. data/lib/earth/locality/zip_code.rb +1 -1
  69. data/lib/earth/pet/breed.rb +1 -1
  70. data/lib/earth/pet/breed_gender.rb +1 -1
  71. data/lib/earth/pet/gender.rb +1 -1
  72. data/lib/earth/pet/species.rb +1 -1
  73. data/lib/earth/rail/rail_class.rb +1 -1
  74. data/lib/earth/residence/air_conditioner_use.rb +1 -1
  75. data/lib/earth/residence/clothes_machine_use.rb +1 -1
  76. data/lib/earth/residence/dishwasher_use.rb +1 -1
  77. data/lib/earth/residence/residence_appliance.rb +1 -1
  78. data/lib/earth/residence/residence_class.rb +1 -1
  79. data/lib/earth/residence/residence_fuel_price.rb +1 -1
  80. data/lib/earth/residence/residence_fuel_type.rb +1 -1
  81. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +1 -1
  82. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +9 -9
  83. data/lib/earth/shipping/carrier.rb +1 -1
  84. data/lib/earth/shipping/carrier_mode.rb +1 -1
  85. data/lib/earth/shipping/shipment_mode.rb +1 -1
  86. data/lib/earth/version.rb +1 -1
  87. data/spec/earth/air/aircraft_spec.rb +1 -1
  88. metadata +42 -44
@@ -6,7 +6,7 @@ class AutomobileMake < ActiveRecord::Base
6
6
  has_many :fleet_years, :class_name => 'AutomobileMakeFleetYear', :foreign_key => 'make_name'
7
7
  has_many :make_model_year_variants, :class_name => 'AutomobileMakeModelYearVariant', :foreign_key => 'make_name'
8
8
 
9
- create_table do
9
+ force_schema do
10
10
  string 'name'
11
11
  float 'fuel_efficiency'
12
12
  string 'fuel_efficiency_units'
@@ -4,7 +4,7 @@ class AutomobileMakeFleetYear < ActiveRecord::Base
4
4
  belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
5
5
  belongs_to :make_year, :class_name => 'AutomobileMakeYear', :foreign_key => 'make_year_name'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name'
9
9
  string 'make_year_name'
10
10
  string 'make_name'
@@ -4,7 +4,7 @@ class AutomobileMakeModel < ActiveRecord::Base
4
4
  belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
5
5
  has_many :make_model_year_variants, :class_name => 'AutomobileMakeModelYearVariant', :foreign_key => 'make_model_name'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name' # make + model
9
9
  string 'make_name'
10
10
  string 'model_name' # model only
@@ -4,7 +4,7 @@ class AutomobileMakeModelYear < ActiveRecord::Base
4
4
  belongs_to :make_year, :class_name => 'AutomobileMakeYear', :foreign_key => 'make_year_name'
5
5
  has_many :make_model_year_variants, :class_name => 'AutomobileMakeModelYearVariant', :foreign_key => 'make_model_year_name'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name' # make + model + year
9
9
  string 'make_name'
10
10
  string 'model_name'
@@ -6,7 +6,7 @@ class AutomobileMakeModelYearVariant < ActiveRecord::Base
6
6
  belongs_to :make_model_year, :class_name => 'AutomobileMakeModelYear', :foreign_key => 'make_model_year_name'
7
7
  belongs_to :fuel, :class_name => 'AutomobileFuel', :foreign_key => 'fuel_code', :primary_key => 'code'
8
8
 
9
- create_table do
9
+ force_schema do
10
10
  string 'row_hash'
11
11
  string 'name' # short name!
12
12
  string 'make_name'
@@ -4,7 +4,7 @@ class AutomobileMakeYear < ActiveRecord::Base
4
4
  belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
5
5
  has_many :fleet_years, :class_name => 'AutomobileMakeFleetYear', :foreign_key => 'make_year_name'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name'
9
9
  string 'make_name'
10
10
  integer 'year'
@@ -6,7 +6,7 @@ class AutomobileSizeClass < ActiveRecord::Base
6
6
  :conventional_fuel_efficiency_city_multiplier => 0.987,
7
7
  :conventional_fuel_efficiency_highway_multiplier => 0.996
8
8
 
9
- create_table do
9
+ force_schema do
10
10
  string 'name'
11
11
  string 'type_name'
12
12
  float 'annual_distance'
@@ -1,7 +1,7 @@
1
1
  class AutomobileSizeClassYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- create_table do
4
+ force_schema do
5
5
  string 'name'
6
6
  string 'size_class_name'
7
7
  integer 'year'
@@ -2,7 +2,7 @@
2
2
  class AutomobileTypeFuelAge < ActiveRecord::Base
3
3
  set_primary_key :name
4
4
 
5
- create_table do
5
+ force_schema do
6
6
  string 'name'
7
7
  string 'type_name'
8
8
  string 'fuel_common_name'
@@ -1,6 +1,6 @@
1
1
  class AutomobileTypeFuelControl < ActiveRecord::Base
2
2
  set_primary_key :name
3
- create_table do
3
+ force_schema do
4
4
  string 'name'
5
5
  string 'type_name'
6
6
  string 'fuel_common_name'
@@ -4,7 +4,7 @@ class AutomobileTypeFuelYear < ActiveRecord::Base
4
4
  has_many :year_controls, :class_name => 'AutomobileTypeFuelYearControl', :foreign_key => 'type_fuel_year_name'
5
5
  belongs_to :type_year, :class_name => 'AutomobileTypeYear', :foreign_key => 'type_year_name'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name'
9
9
  string 'type_name'
10
10
  string 'fuel_common_name'
@@ -3,7 +3,7 @@ class AutomobileTypeFuelYearAge < ActiveRecord::Base
3
3
 
4
4
  belongs_to :type_fuel_year, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_fuel_year_name'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  string 'type_name'
9
9
  string 'fuel_common_name'
@@ -3,7 +3,7 @@ class AutomobileTypeFuelYearControl < ActiveRecord::Base
3
3
 
4
4
  belongs_to :control, :class_name => 'AutomobileTypeFuelControl', :foreign_key => 'type_fuel_control_name'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  string 'type_name'
9
9
  string 'fuel_common_name'
@@ -3,7 +3,7 @@ class AutomobileTypeYear < ActiveRecord::Base
3
3
 
4
4
  has_many :type_fuel_years, :class_name => 'AutomobileTypeFuelYear', :foreign_key => 'type_year_name'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  string 'type_name'
9
9
  integer 'year'
@@ -28,7 +28,7 @@ class BusClass < ActiveRecord::Base
28
28
  :alternative_fuels_intensity => 0.04632038.gallons_per_mile.to(:litres_per_kilometre), # deprecated
29
29
  :alternative_fuels_intensity_units => 'litres_per_kilometre' # deprecated
30
30
 
31
- create_table do
31
+ force_schema do
32
32
  string 'name'
33
33
  float 'distance'
34
34
  string 'distance_units'
@@ -8,7 +8,7 @@ class BusFuel < ActiveRecord::Base
8
8
  fuel_year_controls.where(:year => fuel_year_controls.maximum('year'))
9
9
  end
10
10
 
11
- create_table do
11
+ force_schema do
12
12
  string 'name'
13
13
  string 'fuel_name'
14
14
  float 'energy_content'
@@ -1,6 +1,6 @@
1
1
  class BusFuelControl < ActiveRecord::Base
2
2
  set_primary_key :name
3
- create_table do
3
+ force_schema do
4
4
  string 'name'
5
5
  string 'bus_fuel_name'
6
6
  string 'control'
@@ -3,7 +3,7 @@ class BusFuelYearControl < ActiveRecord::Base
3
3
 
4
4
  belongs_to :fuel_control, :class_name => 'BusFuelControl', :foreign_key => 'bus_fuel_control_name'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  string 'bus_fuel_name'
9
9
  integer 'year'
@@ -4,7 +4,7 @@ class ComputationCarrier < ActiveRecord::Base
4
4
  falls_back_on :name => 'fallback',
5
5
  :power_usage_effectiveness => lambda { ComputationCarrier.maximum('power_usage_effectiveness') }
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'name'
9
9
  float 'power_usage_effectiveness'
10
10
  end
@@ -7,7 +7,7 @@ class ComputationCarrierInstanceClass < ActiveRecord::Base
7
7
  :electricity_intensity => lambda { ComputationCarrierInstanceClass.find_by_name('Amazon m1.small').electricity_intensity },
8
8
  :electricity_intensity_units => lambda { ComputationCarrierInstanceClass.find_by_name('Amazon m1.small').electricity_intensity_units }
9
9
 
10
- create_table do
10
+ force_schema do
11
11
  string 'name'
12
12
  string 'computation_carrier_name'
13
13
  string 'instance_class'
@@ -3,7 +3,7 @@ class ComputationCarrierRegion < ActiveRecord::Base
3
3
 
4
4
  belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  string 'computation_carrier_name'
9
9
  string 'region'
@@ -25,6 +25,7 @@ Conversions.register(:joules, :litres_of_fuel_oil, 1.0 / (138_690.0 * 3.78541178
25
25
  Conversions.register(:joules, :kilograms_of_coal, 1.0 / (22_342_000.0 * 0.00110231131 * 1_055.05585)) # should only be used for RECS 2005
26
26
 
27
27
  Conversions.register(:kilograms, :lbs, 2.20462262)
28
+ Conversions.register(:metric_tonnes, :kilograms, 1_000.0)
28
29
  Conversions.register(:kbtus, :btus, 1_000.0)
29
30
  Conversions.register(:square_feet, :square_metres, 0.09290304)
30
31
  Conversions.register(:pounds_per_square_foot, :kilograms_per_square_metre, 4.88242764)
@@ -7,7 +7,7 @@ class DietClass < ActiveRecord::Base
7
7
  end
8
8
  end
9
9
 
10
- create_table do
10
+ force_schema do
11
11
  string 'name'
12
12
  float 'intensity'
13
13
  string 'intensity_units'
@@ -11,7 +11,7 @@ class FoodGroup < ActiveRecord::Base
11
11
  end
12
12
  end
13
13
 
14
- create_table do
14
+ force_schema do
15
15
  string 'name'
16
16
  float 'intensity'
17
17
  string 'intensity_units'
@@ -3,7 +3,7 @@ class Fuel < ActiveRecord::Base
3
3
 
4
4
  has_many :fuel_years, :foreign_key => 'fuel_name'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  float 'density'
9
9
  string 'density_units'
@@ -3,7 +3,7 @@ class FuelPrice < ActiveRecord::Base
3
3
 
4
4
  belongs_to :fuel_type, :foreign_key => 'name' # weird
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'name'
8
8
  float 'price'
9
9
  string 'price_units'
@@ -12,7 +12,7 @@ class FuelType < ActiveRecord::Base
12
12
  prices.average :price
13
13
  end
14
14
 
15
- create_table do
15
+ force_schema do
16
16
  string 'name'
17
17
  float 'emission_factor'
18
18
  string 'emission_factor_units'
@@ -1,7 +1,7 @@
1
1
  class FuelYear < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- create_table do
4
+ force_schema do
5
5
  string 'name'
6
6
  string 'fuel_name'
7
7
  integer 'year'
@@ -7,7 +7,7 @@ class GreenhouseGas < ActiveRecord::Base
7
7
  end
8
8
  end
9
9
 
10
- create_table do
10
+ force_schema do
11
11
  string 'name'
12
12
  string 'abbreviation'
13
13
  string 'ipcc_report'
@@ -1,7 +1,7 @@
1
1
  class LodgingClass < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- create_table do
4
+ force_schema do
5
5
  string 'name'
6
6
  float 'electricity_intensity'
7
7
  string 'electricity_intensity_units'
@@ -9,7 +9,7 @@ class Industry < ActiveRecord::Base
9
9
  has_many :industry_sectors, :foreign_key => 'naics_code'
10
10
  has_many :sectors, :through => :industry_sectors
11
11
 
12
- create_table do
12
+ force_schema do
13
13
  string 'naics_code'
14
14
  string 'description'
15
15
  end
@@ -5,7 +5,7 @@ class IndustryProduct < ActiveRecord::Base
5
5
 
6
6
  belongs_to :industry, :foreign_key => 'naics_code'
7
7
 
8
- create_table do
8
+ force_schema do
9
9
  string 'naics_product_code'
10
10
  string 'description'
11
11
  float 'value'
@@ -4,7 +4,7 @@ class IndustryProductLine < ActiveRecord::Base
4
4
  belongs_to :industry, :foreign_key => 'naics_code'
5
5
  belongs_to :product_line, :foreign_key => 'ps_code'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'row_hash'
9
9
  string 'naics_code'
10
10
  float 'ratio'
@@ -4,7 +4,7 @@ class IndustrySector < ActiveRecord::Base
4
4
  belongs_to :industry, :foreign_key => 'naics_code'
5
5
  belongs_to :sector, :foreign_key => 'io_code'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'row_hash'
9
9
  string 'naics_code'
10
10
  float 'ratio'
@@ -3,7 +3,7 @@ class Merchant < ActiveRecord::Base
3
3
 
4
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'id'
8
8
  string 'name'
9
9
  string 'mcc'
@@ -8,7 +8,7 @@ class MerchantCategory < ActiveRecord::Base
8
8
  description
9
9
  end
10
10
 
11
- create_table do
11
+ force_schema do
12
12
  string 'mcc'
13
13
  string 'description'
14
14
  end
@@ -4,7 +4,7 @@ class MerchantCategoryIndustry < ActiveRecord::Base
4
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
5
5
  belongs_to :industry, :foreign_key => 'naics_code'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'row_hash'
9
9
  string 'mcc'
10
10
  float 'ratio'
@@ -6,7 +6,7 @@ class ProductLine < ActiveRecord::Base
6
6
  has_many :product_line_industry_products, :foreign_key => 'ps_code'
7
7
  has_many :industry_products, :through => :product_line_industry_products
8
8
 
9
- create_table do
9
+ force_schema do
10
10
  string 'ps_code'
11
11
  string 'description'
12
12
  string 'broadline' # FIXME TODO do we need this?
@@ -4,7 +4,7 @@ class ProductLineIndustryProduct < ActiveRecord::Base
4
4
  belongs_to :product_line, :foreign_key => 'ps_code'
5
5
  belongs_to :industry_product, :foreign_key => 'naics_product_code'
6
6
 
7
- create_table do
7
+ force_schema do
8
8
  string 'row_hash'
9
9
  string 'ps_code'
10
10
  float 'ratio'
@@ -3,7 +3,7 @@ class Sector < ActiveRecord::Base
3
3
 
4
4
  has_many :industry_sectors, :foreign_key => 'io_code'
5
5
 
6
- create_table do
6
+ force_schema do
7
7
  string 'io_code'
8
8
  string 'description'
9
9
  float 'value'
@@ -13,7 +13,7 @@ class CensusDivision < ActiveRecord::Base
13
13
  :meeting_building_electricity_intensity => 0.0084323684 / 1.square_feet.to(:square_metres),
14
14
  :meeting_building_district_heat_intensity => 0.0004776370.kbtus.to(:megajoules) / 1.square_feet.to(:square_metres)
15
15
 
16
- create_table do
16
+ force_schema do
17
17
  integer 'number'
18
18
  string 'name'
19
19
  string 'census_region_name'
@@ -7,7 +7,7 @@ class CensusRegion < ActiveRecord::Base
7
7
  # has_many :zip_codes, :through => :census_divisions
8
8
  has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_region_number'
9
9
 
10
- create_table do
10
+ force_schema do
11
11
  integer 'number'
12
12
  string 'name'
13
13
  end
@@ -6,7 +6,7 @@ class ClimateDivision < ActiveRecord::Base
6
6
 
7
7
  RADIUS = 750
8
8
 
9
- create_table do
9
+ force_schema do
10
10
  string 'name'
11
11
  float 'heating_degree_days'
12
12
  float 'cooling_degree_days'
@@ -19,7 +19,7 @@ class Country < ActiveRecord::Base
19
19
  end
20
20
  end
21
21
 
22
- create_table do
22
+ force_schema do
23
23
  string 'iso_3166_code'
24
24
  string 'name'
25
25
  float 'automobile_urbanity'
@@ -7,7 +7,7 @@ class EgridRegion < ActiveRecord::Base
7
7
  falls_back_on :name => 'fallback',
8
8
  :loss_factor => 0.061879 # calculated using above formula 2/21/2011
9
9
 
10
- create_table do
10
+ force_schema do
11
11
  string 'name'
12
12
  float 'loss_factor'
13
13
  end
@@ -10,6 +10,16 @@ EgridRegion.class_eval do
10
10
  store 'loss_factor', :field_name => '2005 grid gross loss factor'
11
11
  end
12
12
 
13
+ # resurrected from a7bb363f10d951957dd051ff3cfb81c280f61151
14
+ import "the US average grid loss factor derived eGRID 2007 data",
15
+ :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
16
+ :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
17
+ :sheet => 'USGC',
18
+ :skip => 5 do
19
+ key 'name', :static => 'US'
20
+ store 'loss_factor', :synthesize => lambda { |row| (row['USTNGN05'].to_f + row['USTNFI05'].to_f - row['USTCON05'].to_f) / row['USTNGN05'].to_f }
21
+ end
22
+
13
23
  verify "Loss factor should be greater than zero and less than one" do
14
24
  EgridRegion.all.each do |region|
15
25
  unless region.loss_factor > 0 and region.loss_factor < 1