brighter_planet_metadata 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,3 +10,21 @@ Rake::TestTask.new(:test) do |test|
10
10
  end
11
11
 
12
12
  task :default => :test
13
+
14
+ task :fallbacks do
15
+ require_relative 'lib/brighter_planet_metadata'
16
+ fallbacks = BrighterPlanet::Metadata::LIVE_URL.inject({}) do |memo, (k, _)|
17
+ if BrighterPlanet.metadata.respond_to?(k)
18
+ memo[k] = BrighterPlanet.metadata.send k
19
+ else
20
+ parts = k.split('_') # rail_trips_options => rail, trips, options
21
+ method_id = parts.pop
22
+ arg = parts.join('_')
23
+ memo[k] = BrighterPlanet.metadata.send method_id, arg
24
+ end
25
+ memo
26
+ end
27
+ File.open(File.expand_path('../lib/brighter_planet_metadata/fallbacks.json', __FILE__), 'w') do |f|
28
+ f.write MultiJson.encode(fallbacks)
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ {"datasets":["AutomobileIndustry","FlightIndustry"],"emitters":["Automobile","AutomobileTrip","BusTrip","Computation","Diet","ElectricityUse","Flight","FuelPurchase","Lodging","Meeting","Motorcycle","Pet","Purchase","RailTrip","Residence","Shipment"],"certified_emitters":["AutomobileTrip","BusTrip","Flight","Lodging","Meeting","RailTrip"],"resources":["AirConditionerUse","Aircraft","Airline","Airport","AutomobileFuel","AutomobileMake","AutomobileMakeModel","AutomobileMakeModelYear","AutomobileMakeModelYearVariant","AutomobileMakeYear","AutomobileMakeYearFleet","AutomobileModel","AutomobileSizeClass","AutomobileSizeClassYear","AutomobileTypeFuelControl","AutomobileTypeFuelYear","AutomobileTypeFuelYearAge","AutomobileTypeFuelYearControl","AutomobileTypeYear","AutomobileYear","Breed","BreedGender","BtsAircraft","BusClass","BusFuel","BusFuelControl","BusFuelYearControl","Carrier","CarrierMode","CbecsEnergyIntensity","CensusDivision","CensusRegion","ClimateDivision","ClothesMachineUse","CommercialBuildingEnergyConsumptionSurveyResponse","ComputationCarrier","ComputationCarrierInstanceClass","ComputationCarrierRegion","Country","CountryLodgingClass","CountryRailClass","CountryRailTraction","CountryRailTractionClass","DietClass","DishwasherUse","EgridCountry","EgridRegion","EgridSubregion","FlightDistanceClass","FlightDistanceClassSeatClass","FlightSeatClass","FlightSegment","FoodGroup","Fuel","FuelPrice","FuelType","FuelYear","Gender","GreenhouseGas","Industry","LodgingClass","MecsEnergy","MecsRatio","Naics2002","Naics2002Naics2007Concordance","Naics2002Sic1987Concordance","Naics2007","NationalTransitDatabaseCompany","NationalTransitDatabaseMode","NationalTransitDatabaseRecord","PetroleumAdministrationForDefenseDistrict","RailClass","RailCompany","RailFuel","RailTraction","ResidenceAppliance","ResidenceClass","ResidenceFuelPrice","ResidenceFuelType","ResidentialEnergyConsumptionSurveyResponse","ShipmentMode","Sic1987","Species","State","Urbanity","ZipCode"],"protocols":{"ghg_protocol_scope_3":"Greenhouse Gas Protocol Scope 3","iso":"ISO 14064-1","tcr":"The Climate Registry","ghg_protocol_scope_1":"Greenhouse Gas Protocol Scope 1"},"automobiles_options":["make","model","year","size_class","automobile_fuel","country","acquisition","retirement","hybridity","urbanity","speed","daily_duration","daily_distance","weekly_distance","annual_distance","fuel_efficiency","fuel_use"],"automobile_trips_options":["make","model","year","size_class","automobile_fuel","country","date","hybridity","urbanity","speed","duration","origin","destination","distance","fuel_efficiency","fuel_use"],"bus_trips_options":["bus_class","date","duration","distance"],"computations_options":["carrier","carrier_region","carrier_instance_class","zip_code","date","duration","electricity_intensity","power_usage_effectiveness"],"diets_options":["diet_class","red_meat_share","poultry_share","fish_share","eggs_share","nuts_share","dairy_share","cereals_and_grains_share","fruit_share","vegetables_share","oils_and_sugars_share","size","proximity","conventionality","start_date","end_date","intensity"],"electricity_uses_options":["zip_code","state","country","date","energy"],"flights_options":["origin_airport","destination_airport","aircraft","airline","fuel","distance_class","seat_class","date","segments_per_trip","trips","load_factor","seats","distance_estimate"],"fuel_purchases_options":["fuel_type","zip_code","state","petroleum_administration_for_defense_district","volume","cost","price","date"],"lodgings_options":["zip_code","state","country","lodging_class","property","date","rooms","duration","city","heating_degree_days","cooling_degree_days","property_rooms","floors","construction_year","ac_coverage","refrigerator_coverage","hot_tubs","outdoor_pools","indoor_pools"],"meetings_options":["zip_code","state","date","area","duration"],"motorcycles_options":["fuel_efficiency","annual_distance_estimate","weekly_distance_estimate","acquisition","retirement"],"pets_options":["species","breed","gender","weight","acquisition","retirement"],"purchases_options":["merchant","merchant_category","sic_industry","industry","cost","purchase_amount","tax","date"],"rail_trips_options":["country","rail_company","rail_class","rail_traction","date","origin","destination","distance","duration"],"residences_options":["residence_class","urbanity","dishwasher_use","air_conditioner_use","clothes_machine_use","zip_code","ownership","residents","refrigerator_count","freezer_count","lighting_efficiency","floorspace_estimate","floors","bathrooms","bedrooms","full_bathrooms","half_bathrooms","acquisition","retirement","construction_year","occupation","annual_fuel_oil_volume_estimate","annual_fuel_oil_cost","monthly_natural_gas_volume_estimate","monthly_natural_gas_cost","monthly_electricity_use_estimate","monthly_electricity_cost","green_electricity","annual_propane_volume_estimate","annual_propane_cost","annual_wood_volume_estimate","annual_kerosene_volume_estimate","annual_coal_volume_estimate"],"shipments_options":["carrier","mode","weight","package_count","segment_count","origin","destination","origin_zip_code","destination_zip_code","distance"],"automobiles_committees":["carbon","co2_emission","co2_biogenic_emission","ch4_emission","n2o_emission","hfc_emission","energy","fuel_use","distance","annual_distance","automobile_fuel","speed","fuel_efficiency","hybridity_multiplier","urbanity","safe_country","active_subtimeframe","acquisition","retirement","make_model_year","make_year","make_model"],"automobile_trips_committees":["carbon","co2_emission","co2_biogenic_emission","ch4_emission","n2o_emission","hfc_emission","energy","automobile_fuel","fuel_use","distance","destination_location","origin_location","speed","fuel_efficiency","hybridity_multiplier","urbanity","safe_country","make_model_year","make_year","make_model","date"],"bus_trips_committees":["carbon","co2_emission","co2_biogenic_emission","ch4_emission","n2o_emission","hfc_emission","fuel_uses","distance_per_passenger","distance","speed","passengers","bus_class","date"],"computations_committees":["carbon","co2_emission","co2_biogenic_emission","ch4_emission","n2o_emission","co2_emission_factor","co2_biogenic_emission_factor","ch4_emission_factor","n2o_emission_factor","electricity_use","electricity_loss_factor","egrid_region","egrid_subregion","power_usage_effectiveness","electricity_intensity","carrier_instance_class","carrier","duration","date"],"diets_committees":["carbon","intensity","size","diet_class","active_subtimeframe","start_date","end_date"],"electricity_uses_committees":["carbon","emission_factor","loss_factor","energy","country","egrid_subregion","state","date"],"flights_committees":["carbon","ghg_emission_factor","aviation_multiplier","energy","fuel_use","fuel_per_segment","seat_class_multiplier","distance_class_seat_class","distance_class","adjusted_distance_per_segment","adjusted_distance","distance","route_inefficiency_factor","dogleg_factor","fuel_use_coefficients","fuel","passengers","seats","load_factor","freight_share","trips","country","cohort","segments_per_trip","date"],"fuel_purchases_committees":["carbon","emission_factor","volume","price","petroleum_administration_for_defense_district","state"],"lodgings_committees":["carbon","electricity_emission_factor","natural_gas_use","fuel_oil_use","electricity_use","district_heat_use","adjusted_fuel_intensities","outdoor_pool_adjustment","indoor_pool_adjustment","hot_tub_adjustment","refrigerator_adjustment","fuel_intensities","occupancy_rate","outdoor_pools","indoor_pools","hot_tubs","refrigerator_coverage","ac_coverage","construction_year","floors","property_rooms","heating_degree_days","cooling_degree_days","egrid_subregion","country","state","city","climate_division","room_nights","duration","rooms","date"],"meetings_committees":["carbon","emission_factor","natural_gas_intensity","fuel_oil_intensity","electricity_intensity","district_heat_intensity","egrid_subregion","census_division","state","area","duration","date"],"motorcycles_committees":["carbon","fuel_consumed","emission_factor","distance","fuel_efficiency","fuel","annual_distance","active_subtimeframe","acquisition","retirement"],"pets_committees":["carbon","diet_emission_intensity","diet_size","marginal_dietary_requirement","fixed_dietary_requirement","weight","active_subtimeframe","acquisition","retirement"],"purchases_committees":["carbon","impacts","direct_emissions","impact_vectors","economic_flows","sector_direct_requirements","sector_shares","industry_sector_shares","industry_sector_ratios","industry_ratios","industry_product_ratios","product_line_industry_product_ratios","product_line_ratios","non_trade_industry_ratios","trade_industry_ratios","merchant_category_industries","merchant_category","adjusted_cost","cost","date"],"rail_trips_committees":["carbon","co2_emission_factor","diesel_consumption","electricity_consumption","diesel_intensity","electricity_intensity","distance","speed","rail_company_traction_class","rail_company_traction","country_rail_traction_class","country_rail_class","country_rail_traction","country","destination_location","origin_location","date"],"residences_committees":["carbon","fuel_oil_consumed","natural_gas_consumed","propane_consumed","biomass_consumed","kerosene_consumed","coal_consumed","dirty_electricity_generated","green_electricity","electricity_generated","electricity_used","missing_annual_energy","electricity_loss_rate","electricity_emission_factor","egrid_region","egrid_subregion","occupation","residents","air_conditioner_use","predicted_fuel_shares","predicted_annual_energy_consumption","reported_annual_fuel_oil_consumption","predicted_annual_fuel_oil_consumption","reported_annual_natural_gas_consumption","predicted_annual_natural_gas_consumption","reported_annual_propane_consumption","predicted_annual_propane_consumption","reported_annual_kerosene_consumption","predicted_annual_kerosene_consumption","reported_annual_biomass_consumption","predicted_annual_biomass_consumption","reported_annual_coal_consumption","predicted_annual_coal_consumption","reported_annual_electricity_use","predicted_annual_electricity_use","active_subtimeframe","acquisition","retirement","floorspace_estimate","cohort","bathrooms","census_region","census_division","state","floorspace","heating_degree_days","cooling_degree_days","climate_division"],"shipments_committees":["carbon","corporate_emission","transport_emission","corporate_emission_factor","transport_emission_factor","adjusted_distance","dogleg_factor","route_inefficiency_factor","distance","carrier_mode","segment_count","destination_location","destination","origin_location","origin","package_count","weight"]}
@@ -43,16 +43,31 @@ module BrighterPlanet
43
43
  'rail_trips_options' => 'http://impact.brighterplanet.com/rail_trips/options.json',
44
44
  'residences_options' => 'http://impact.brighterplanet.com/residences/options.json',
45
45
  'shipments_options' => 'http://impact.brighterplanet.com/shipments/options.json',
46
+
47
+ 'automobiles_committees' => 'http://impact.brighterplanet.com/automobiles/committees.json',
48
+ 'automobile_trips_committees' => 'http://impact.brighterplanet.com/automobile_trips/committees.json',
49
+ 'bus_trips_committees' => 'http://impact.brighterplanet.com/bus_trips/committees.json',
50
+ 'computations_committees' => 'http://impact.brighterplanet.com/computations/committees.json',
51
+ 'diets_committees' => 'http://impact.brighterplanet.com/diets/committees.json',
52
+ 'electricity_uses_committees' => 'http://impact.brighterplanet.com/electricity_uses/committees.json',
53
+ 'flights_committees' => 'http://impact.brighterplanet.com/flights/committees.json',
54
+ 'fuel_purchases_committees' => 'http://impact.brighterplanet.com/fuel_purchases/committees.json',
55
+ 'lodgings_committees' => 'http://impact.brighterplanet.com/lodgings/committees.json',
56
+ 'meetings_committees' => 'http://impact.brighterplanet.com/meetings/committees.json',
57
+ 'motorcycles_committees' => 'http://impact.brighterplanet.com/motorcycles/committees.json',
58
+ 'pets_committees' => 'http://impact.brighterplanet.com/pets/committees.json',
59
+ 'purchases_committees' => 'http://impact.brighterplanet.com/purchases/committees.json',
60
+ 'rail_trips_committees' => 'http://impact.brighterplanet.com/rail_trips/committees.json',
61
+ 'residences_committees' => 'http://impact.brighterplanet.com/residences/committees.json',
62
+ 'shipments_committees' => 'http://impact.brighterplanet.com/shipments/committees.json',
46
63
  }.freeze
47
-
48
- # sabshere 2/4/11 obv these have to be updated with some regularity
49
- FALLBACK = {
50
- 'datasets' => %w{ AutomobileIndustry FlightIndustry },
51
- 'emitters' => %w{ Automobile AutomobileTrip BusTrip Computation Diet ElectricityUse Flight FuelPurchase Lodging Meeting Motorcycle Pet Purchase RailTrip Residence Shipment },
52
- 'certified_emitters' => %w{ },
53
- 'resources' => %w{ AirConditionerUse Aircraft AircraftClass AircraftFuelUseEquation Airline Airport AutomobileFuel AutomobileMake AutomobileMakeFleetYear AutomobileMakeModel AutomobileMakeModelYear AutomobileMakeModelYearVariant AutomobileMakeYear AutomobileSizeClass AutomobileSizeClassYear AutomobileTypeFuelAge AutomobileTypeFuelControl AutomobileTypeFuelYear AutomobileTypeFuelYearAge AutomobileTypeFuelYearControl AutomobileTypeYear Breed BreedGender BtsAircraft BusClass BusFuel BusFuelControl BusFuelYearControl Carrier CarrierMode CensusDivision CensusRegion ClimateDivision ClothesMachineUse ComputationCarrier ComputationCarrierInstanceClass ComputationCarrierRegion Country DietClass DishwasherUse EgridRegion EgridSubregion FlightDistanceClass FlightSeatClass FlightSegment FoodGroup Fuel FuelPrice FuelType FuelYear Gender GreenhouseGas LodgingClass PetroleumAdministrationForDefenseDistrict RailClass ResidenceAppliance ResidenceClass ResidenceFuelPrice ResidenceFuelType ResidentialEnergyConsumptionSurveyResponse ShipmentMode Species State Urbanity ZipCode },
54
- 'protocols' => { 'ghg_protocol_scope_3' => 'Greenhouse Gas Protocol Scope 3', 'iso' => 'ISO 14064-1', 'tcr' => 'The Climate Registry', 'ghg_protocol_scope_1' => 'Greenhouse Gas Protocol Scope 1' },
55
- }.freeze
64
+
65
+ FALLBACK = begin
66
+ ::MultiJson.decode(::File.read(::File.expand_path('../fallbacks.json', __FILE__))).freeze
67
+ rescue
68
+ $stderr.puts "[brighter_planet_metadata] Error while loading fallbacks. Please reinstall library."
69
+ {}
70
+ end
56
71
 
57
72
  # What resources are available.
58
73
  def resources
@@ -83,6 +98,11 @@ module BrighterPlanet
83
98
  def options(emitter)
84
99
  deep_copy_of_authoritative_value_or_fallback "#{emitter.to_s.pluralize.downcase}_options"
85
100
  end
101
+
102
+ # committees (decisions) available for a given emitter
103
+ def committees(emitter)
104
+ deep_copy_of_authoritative_value_or_fallback "#{emitter.to_s.pluralize.downcase}_committees"
105
+ end
86
106
 
87
107
  # Clear out any cached values
88
108
  def refresh
@@ -109,10 +129,16 @@ module BrighterPlanet
109
129
  FALLBACK[meta_name]
110
130
  else
111
131
  begin
112
- hsh = ::MultiJson.decode ::Net::HTTP.get(::URI.parse(LIVE_URL[meta_name]))
113
- subkey = (meta_name == 'certified_emitters') ? 'emitters' : meta_name # the live certified response will contain an 'emitters' key
114
- hsh.key?(subkey) ? hsh[subkey] : hsh
132
+ actual = ::MultiJson.decode ::Net::HTTP.get(::URI.parse(LIVE_URL[meta_name]))
133
+ case actual
134
+ when ::Hash
135
+ subkey = (meta_name == 'certified_emitters') ? 'emitters' : meta_name # the live certified response will contain an 'emitters' key
136
+ actual.key?(subkey) ? actual[subkey] : actual
137
+ else
138
+ actual
139
+ end
115
140
  rescue ::Exception
141
+ $stderr.puts "[brighter_planet_metadata] Rescued from #{$!.inspect} when trying to get #{meta_name}"
116
142
  FALLBACK[meta_name]
117
143
  end
118
144
  end
@@ -1,3 +1,3 @@
1
1
  module BrighterPlanetMetadata
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -4,11 +4,7 @@ class TestFallback < Test::Unit::TestCase
4
4
  def setup
5
5
  super
6
6
  [
7
- 'http://data.brighterplanet.com/datasets.json',
8
- 'http://impact.brighterplanet.com/emitters.json',
9
- 'http://certified.impact.brighterplanet.com/emitters.json',
10
- 'http://data.brighterplanet.com/resources.json',
11
- 'http://impact.brighterplanet.com/protocols.json',
7
+ %r{http.*brighterplanet.com.*}
12
8
  ].each do |url|
13
9
  WebMock.stub_request(:get, url).to_return(:status => 500)
14
10
  end
@@ -29,4 +25,16 @@ class TestFallback < Test::Unit::TestCase
29
25
  def test_protocols
30
26
  assert ::BrighterPlanet.metadata.protocols.values.include? 'The Climate Registry'
31
27
  end
28
+
29
+ def test_options_flight
30
+ assert ::BrighterPlanet.metadata.options(:flight).include?('origin_airport')
31
+ end
32
+
33
+ def test_options_electricity_use
34
+ assert ::BrighterPlanet.metadata.options(:electricity_use).include?('zip_code')
35
+ end
36
+
37
+ def test_committees_flight
38
+ assert ::BrighterPlanet.metadata.committees(:flight).include?('energy')
39
+ end
32
40
  end
@@ -30,10 +30,14 @@ class TestReal < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_options_flight
33
- assert ::BrighterPlanet.metadata.options(:flight).keys.include?('fuel_use_coefficients')
33
+ assert ::BrighterPlanet.metadata.options(:flight).include?('origin_airport')
34
34
  end
35
35
 
36
36
  def test_options_electricity_use
37
- assert ::BrighterPlanet.metadata.options(:electricity_use).keys.include?('zip_code')
37
+ assert ::BrighterPlanet.metadata.options(:electricity_use).include?('zip_code')
38
+ end
39
+
40
+ def test_committees_flight
41
+ assert ::BrighterPlanet.metadata.committees(:flight).include?('energy')
38
42
  end
39
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brighter_planet_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-15 00:00:00.000000000Z
13
+ date: 2012-04-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2166662360 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 2.3.4
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2166662360
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 2.3.4
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: i18n
28
- requirement: &2166661940 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *2166661940
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: cache_method
39
- requirement: &2166661480 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :runtime
46
56
  prerelease: false
47
- version_requirements: *2166661480
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: multi_json
50
- requirement: &2166661060 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,7 +70,12 @@ dependencies:
55
70
  version: '0'
56
71
  type: :runtime
57
72
  prerelease: false
58
- version_requirements: *2166661060
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  description: What emitters (carbon models), resources (data classes), datasets, etc.
60
80
  we offer.
61
81
  email:
@@ -72,6 +92,7 @@ files:
72
92
  - bin/brighter_planet_metadata
73
93
  - brighter_planet_metadata.gemspec
74
94
  - lib/brighter_planet_metadata.rb
95
+ - lib/brighter_planet_metadata/fallbacks.json
75
96
  - lib/brighter_planet_metadata/metadata.rb
76
97
  - lib/brighter_planet_metadata/version.rb
77
98
  - test/helper.rb
@@ -99,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
120
  version: '0'
100
121
  requirements: []
101
122
  rubyforge_project: brighter_planet_metadata
102
- rubygems_version: 1.8.11
123
+ rubygems_version: 1.8.21
103
124
  signing_key:
104
125
  specification_version: 3
105
126
  summary: Names of Brighter Planet things
@@ -109,3 +130,4 @@ test_files:
109
130
  - test/test_live_remote.rb
110
131
  - test/test_memory_leak.rb
111
132
  - test/test_real.rb
133
+ has_rdoc: