earth 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,22 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- earth (0.3.7)
4
+ earth (0.3.8)
5
5
  activerecord (~> 3)
6
- activerecord (~> 3)
7
- cohort_scope (>= 0.0.7)
8
6
  cohort_scope (>= 0.0.7)
9
7
  conversions (>= 1.4.5)
10
- conversions (>= 1.4.5)
11
- data_miner (~> 0.5.6)
12
8
  data_miner (~> 0.5.6)
13
9
  falls_back_on (>= 0.0.3)
14
- falls_back_on (>= 0.0.3)
15
- geokit (>= 1.5.0)
16
10
  geokit (>= 1.5.0)
17
11
  loose_tight_dictionary (>= 0.0.8)
18
- loose_tight_dictionary (>= 0.0.8)
19
- weighted_average (>= 0.0.4)
20
12
  weighted_average (>= 0.0.4)
21
13
 
22
14
  GEM
@@ -139,7 +139,7 @@ AutomobileMakeModelYearVariant.class_eval do
139
139
  bus[:format] = :fixed_width
140
140
  bus[:cut] = '13-' if year == 1995
141
141
  bus[:schema_name] = :fuel_economy_guide_b
142
- bus[:select] = lambda { |row| row['supress_code'].blank? and row['state_code'] == 'F' }
142
+ bus[:select] = lambda { |row| row['suppress_code'].blank? and row['state_code'] == 'F' }
143
143
  Slither.define :fuel_economy_guide_b do |d|
144
144
  d.rows do |row|
145
145
  row.trap { true } # there's only one section
@@ -1,2 +1,3 @@
1
1
  require 'earth/shipping/carrier'
2
+ require 'earth/shipping/carrier_mode'
2
3
  require 'earth/shipping/shipment_mode'
@@ -1,7 +1,12 @@
1
1
  class Carrier < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- falls_back_on :corporate_emission_factor => 0.318#Carrier.average(:corporate_emission_factor)
4
+ has_many :carrier_modes, :foreign_key => 'carrier_name', :primary_key => 'name'
5
+
6
+ # TODO calculate these
7
+ falls_back_on :route_inefficiency_factor => 1.03,# Carrier.weighted_average(:route_inefficiency_factor, :weighted_by => :package_volume)
8
+ :transport_emission_factor => 0.0005266,# Carrier.weighted_average(:transport_emission_factor, :weighted_by => :package_volume)
9
+ :corporate_emission_factor => 0.221# Carrier.weighted_average(:corporate_emission_factor, :weighted_by => :package_volume)
5
10
 
6
11
  data_miner do
7
12
  tap "Brighter Planet's shipping company data", Earth.taps_server
@@ -2,6 +2,10 @@ Carrier.class_eval do
2
2
  data_miner do
3
3
  schema Earth.database_options do
4
4
  string 'name'
5
+ float 'package_volume'
6
+ float 'route_inefficiency_factor'
7
+ float 'transport_emission_factor'
8
+ string 'transport_emission_factor_units'
5
9
  float 'corporate_emission_factor'
6
10
  string 'corporate_emission_factor_units'
7
11
  end
@@ -9,15 +13,33 @@ Carrier.class_eval do
9
13
  import "a list of shipping companies and their characteristics",
10
14
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdG1ONU1HZDdZTFJNclFYVkRzR0k5Z2c&hl=en&single=true&gid=0&output=csv' do
11
15
  key 'name'
16
+ store 'package_volume'
17
+ store 'route_inefficiency_factor'
18
+ store 'transport_emission_factor', :units_field_name => 'transport_emission_factor_units'
12
19
  store 'corporate_emission_factor', :units_field_name => 'corporate_emission_factor_units'
13
20
  end
14
21
 
15
- verify "All entries should have corporate_emission_factor >= 0" do
16
- all.each do |record|
17
- unless record[:corporate_emission_factor] >= 0
18
- raise "Invalid corporate_emission_factor for Carrier #{record[:name]}: #{record[:corporate_emission_factor]}"
19
- end
20
- end
21
- end
22
+ # TODO: derive package volume, route inefficiency factor, and transport emission factor
23
+ # process "derive package volume, route inefficiency factor, and transport emission factor from CarrierModes" do
24
+ # CarrierMode.run_data_miner!
25
+ #
26
+ # carrier_modes = CarrierMode.arel_table
27
+ # carriers = Carrier.arel_table
28
+ # conditional_relation = carrier_modes[:include_in_fallbacks].and(carriers[:name].eq(carrier_modes[:carrier_name]))
29
+ #
30
+ # update_all "package_volume = (#{carriers.project(sum(carriers[:package_volume]).where(conditional_relation)).to_sql})"
31
+ # update_all "route_inefficiency_factor = (#{CarrierMode.weighted_average_relation(:route_inefficiency_factor, :weighted_by => :package_volume).where(conditional_relation).to_sql})"
32
+ # update_all "transport_emission_factor = (#{CarrierMode.weighted_average_relation(:transport_emission_factor, :weighted_by => :package_volume).where(conditional_relation).to_sql})"
33
+ # what about transport_emission_factor_units?
34
+ # end
35
+
36
+ # TODO: verification
37
+ # all entries should have name
38
+ # all entries should have package_volume
39
+ # all entries should have route_inefficiency_factor
40
+ # all entries should have transport_emission_factor > 0
41
+ # all entries should have transport_emission_factor_units
42
+ # all entries should have corporate_emission_factor > 0
43
+ # all entries should have corporate_emission_factor_units
22
44
  end
23
45
  end
@@ -0,0 +1,10 @@
1
+ class CarrierMode < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
5
+ belongs_to :mode, :foreign_key => 'mode_name', :primary_key => 'name', :class_name => 'ShipmentMode'
6
+
7
+ data_miner do
8
+ tap "Brighter Planet's carrier mode data", Earth.taps_server
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ CarrierMode.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ string 'carrier_name'
6
+ string 'mode_name'
7
+ boolean 'include_in_fallbacks'
8
+ float 'package_volume'
9
+ float 'route_inefficiency_factor'
10
+ float 'transport_emission_factor'
11
+ string 'transport_emission_factor_units'
12
+ end
13
+
14
+ import "a list of carrier modes and their characteristics",
15
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRsRkJOd0NPd0FETTI0NmpYUlBsN2c&hl=en&single=true&gid=0&output=csv' do
16
+ key 'name'
17
+ store 'carrier_name'
18
+ store 'mode_name'
19
+ store 'include_in_fallbacks'
20
+ store 'package_volume'
21
+ store 'route_inefficiency_factor'
22
+ store 'transport_emission_factor', :units_field_name => 'transport_emission_factor_units'
23
+ end
24
+
25
+ # TODO: verification
26
+ # all entries should have carrier_name
27
+ # all entries should have mode_name
28
+ # all entries should have include_in_fallbacks
29
+ # all entries should have package_volume
30
+ # all entries should have route_inefficiency_factor
31
+ # all entries should have transport emission factor > 0
32
+ # all entries should have transport emission factor units
33
+ end
34
+ end
@@ -1,2 +1,3 @@
1
1
  require 'earth/shipping/carrier/data_miner'
2
+ require 'earth/shipping/carrier_mode/data_miner'
2
3
  require 'earth/shipping/shipment_mode/data_miner'
@@ -1,8 +1,7 @@
1
1
  class ShipmentMode < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- falls_back_on :route_inefficiency_factor => 1.05,#ShipmentMode.where(not(:name => 'courier')).average(:route_inefficiency_factor),
5
- :transport_emission_factor => 0.0007696#ShipmentMode.where(not(:name => 'courier')).average(:route_inefficiency_factor)
4
+ has_many :carrier_modes, :foreign_key => 'mode_name', :primary_key => 'name'
6
5
 
7
6
  data_miner do
8
7
  tap "Brighter Planet's shipment mode data", Earth.taps_server
@@ -13,5 +13,22 @@ ShipmentMode.class_eval do
13
13
  store 'route_inefficiency_factor'
14
14
  store 'transport_emission_factor', :units_field_name => 'transport_emission_factor_units'
15
15
  end
16
+
17
+ # TODO: derive route inefficiency factor and transport emission factor
18
+ # process "derive route inefficiency factor and transport emission factor from CarrierModes" do
19
+ # CarrierMode.run_data_miner!
20
+ #
21
+ # carrier_modes = CarrierMode.arel_table
22
+ # modes = ShipmentMode.arel_table
23
+ #
24
+ # update_all "route_inefficiency_factor = (#{CarrierMode.weighted_average_relation(:route_inefficiency_factor, :weighted_by => :package_volume).where(modes[:name].eq(carrier_modes[:mode_name])).to_sql})"
25
+ # update_all "transport_emission_factor = (#{CarrierMode.weighted_average_relation(:transport_emission_factor, :weighted_by => :package_volume).where(modes[:name].eq(carrier_modes[:mode_name])).to_sql})"
26
+ # what about transport_emission_factor_units?
27
+ # end
28
+
29
+ # TODO: verification
30
+ # all entries should have route_inefficiency_factor >= 1
31
+ # all entries should have transport_emission_factor > 0
32
+ # all entries should have transport_emission_factor_units
16
33
  end
17
34
  end
data/spec/earth_spec.rb CHANGED
@@ -27,7 +27,7 @@ describe Earth do
27
27
  describe '.resources' do
28
28
  it 'should get a list of resources' do
29
29
  resources = Earth.resources
30
- resources.keys.count.should == 58
30
+ resources.keys.count.should == 59
31
31
  resources['FuelType'][:domain].should == 'fuel'
32
32
  end
33
33
  it 'should exclude data_miner files' do
@@ -37,7 +37,7 @@ describe Earth do
37
37
 
38
38
  describe '.resource_names' do
39
39
  it 'should get a list of all resource names' do
40
- Earth.resource_names.count.should == 58
40
+ Earth.resource_names.count.should == 59
41
41
  Earth.resource_names.should include('Aircraft')
42
42
  Earth.resource_names.should include('Industry')
43
43
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 9
10
+ version: 0.3.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-12-12 00:00:00 -05:00
20
+ date: 2010-12-16 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -376,6 +376,8 @@ files:
376
376
  - lib/earth/shipping.rb
377
377
  - lib/earth/shipping/carrier.rb
378
378
  - lib/earth/shipping/carrier/data_miner.rb
379
+ - lib/earth/shipping/carrier_mode.rb
380
+ - lib/earth/shipping/carrier_mode/data_miner.rb
379
381
  - lib/earth/shipping/data_miner.rb
380
382
  - lib/earth/shipping/shipment_mode.rb
381
383
  - lib/earth/shipping/shipment_mode/data_miner.rb