earth 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/earth/industry.rb +2 -2
- data/lib/earth/industry/industry.rb +4 -2
- data/lib/earth/industry/industry_product.rb +21 -0
- data/lib/earth/industry/industry_product_line.rb +0 -1
- data/lib/earth/industry/industry_sector.rb +3 -0
- data/lib/earth/industry/merchant_category.rb +7 -3
- data/lib/earth/industry/merchant_category_industry.rb +2 -2
- data/lib/earth/industry/product_line.rb +4 -2
- data/lib/earth/industry/product_line_industry_product.rb +20 -0
- data/lib/earth/industry/sector.rb +1 -4
- data/lib/earth/locality/egrid_region/data_miner.rb +24 -8
- data/lib/earth/locality/egrid_subregion/data_miner.rb +46 -7
- metadata +6 -5
- data/lib/earth/industry/product_line_sector.rb +0 -18
data/lib/earth/industry.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'earth/industry/industry_product_line'
|
2
2
|
require 'earth/industry/industry_sector'
|
3
3
|
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/industry_product'
|
4
5
|
require 'earth/industry/merchant'
|
5
6
|
require 'earth/industry/merchant_category_industry'
|
6
7
|
require 'earth/industry/merchant_category'
|
7
8
|
require 'earth/industry/product_line'
|
8
|
-
require 'earth/industry/
|
9
|
+
require 'earth/industry/product_line_industry_product'
|
9
10
|
require 'earth/industry/sector'
|
10
|
-
|
@@ -2,11 +2,13 @@ class Industry < ActiveRecord::Base
|
|
2
2
|
extend Earth::Base
|
3
3
|
set_primary_key :naics_code
|
4
4
|
|
5
|
+
has_many :merchant_category_industries, :foreign_key => 'naics_code'
|
6
|
+
|
5
7
|
has_many :industry_product_lines, :foreign_key => 'naics_code'
|
6
|
-
has_many :product_lines, :through => :
|
8
|
+
has_many :product_lines, :through => :industry_product_lines
|
9
|
+
|
7
10
|
has_many :industry_sectors, :foreign_key => 'naics_code'
|
8
11
|
has_many :sectors, :through => :industry_sectors
|
9
|
-
has_many :merchant_category_industries, :foreign_key => 'naics_code'
|
10
12
|
|
11
13
|
def self.schema_definition
|
12
14
|
lambda do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class IndustryProduct < ActiveRecord::Base
|
2
|
+
extend Earth::Base
|
3
|
+
set_primary_key :naics_product_code
|
4
|
+
|
5
|
+
has_many :product_line_industry_products, :foreign_key => 'naics_product_code'
|
6
|
+
|
7
|
+
belongs_to :industry, :foreign_key => 'naics_code'
|
8
|
+
|
9
|
+
def self.schema_definition
|
10
|
+
lambda do
|
11
|
+
string 'naics_product_code'
|
12
|
+
string 'description'
|
13
|
+
float 'value'
|
14
|
+
string 'naics_code'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
data_miner do
|
19
|
+
IndustryProduct.define_schema(self)
|
20
|
+
end
|
21
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
class IndustrySector < ActiveRecord::Base
|
2
2
|
extend Earth::Base
|
3
|
+
set_primary_key :row_hash
|
4
|
+
|
3
5
|
belongs_to :industry, :foreign_key => 'naics_code'
|
4
6
|
belongs_to :sector, :foreign_key => 'io_code'
|
5
7
|
|
6
8
|
def self.schema_definition
|
7
9
|
lambda do
|
10
|
+
string 'row_hash'
|
8
11
|
string 'naics_code'
|
9
12
|
float 'ratio'
|
10
13
|
string 'io_code'
|
@@ -8,11 +8,15 @@ class MerchantCategory < ActiveRecord::Base
|
|
8
8
|
def name
|
9
9
|
description
|
10
10
|
end
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
def self.schema_definition
|
13
|
+
lambda do
|
14
14
|
string 'mcc'
|
15
15
|
string 'description'
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
data_miner do
|
20
|
+
MerchantCategory.define_schema(self)
|
21
|
+
end
|
18
22
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class MerchantCategoryIndustry < ActiveRecord::Base
|
2
2
|
extend Earth::Base
|
3
|
+
set_primary_key :row_hash
|
3
4
|
|
4
5
|
belongs_to :merchant_category, :foreign_key => 'mcc'
|
5
6
|
belongs_to :industry, :foreign_key => 'naics_code'
|
6
|
-
has_many :industry_product_lines, :through => :industry
|
7
|
-
has_many :industry_sectors, :through => :industry
|
8
7
|
|
9
8
|
def self.schema_definition
|
10
9
|
lambda do
|
10
|
+
string 'row_hash'
|
11
11
|
string 'mcc'
|
12
12
|
float 'ratio'
|
13
13
|
string 'naics_code'
|
@@ -2,8 +2,10 @@ class ProductLine < ActiveRecord::Base
|
|
2
2
|
extend Earth::Base
|
3
3
|
set_primary_key :ps_code
|
4
4
|
|
5
|
-
has_many :
|
6
|
-
|
5
|
+
has_many :industry_product_lines, :foreign_key => 'ps_code'
|
6
|
+
|
7
|
+
has_many :product_line_industry_products, :foreign_key => 'ps_code'
|
8
|
+
has_many :industry_products, :through => :product_line_industry_products
|
7
9
|
|
8
10
|
def self.schema_definition
|
9
11
|
lambda do
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ProductLineIndustryProduct < ActiveRecord::Base
|
2
|
+
extend Earth::Base
|
3
|
+
set_primary_key :row_hash
|
4
|
+
|
5
|
+
belongs_to :product_line, :foreign_key => 'ps_code'
|
6
|
+
belongs_to :industry_product, :foreign_key => 'naics_product_code'
|
7
|
+
|
8
|
+
def self.schema_definition
|
9
|
+
lambda do
|
10
|
+
string 'row_hash'
|
11
|
+
string 'ps_code'
|
12
|
+
float 'ratio'
|
13
|
+
string 'naics_product_code'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
data_miner do
|
18
|
+
ProductLineIndustryProduct.define_schema(self)
|
19
|
+
end
|
20
|
+
end
|
@@ -2,14 +2,11 @@ class Sector < ActiveRecord::Base
|
|
2
2
|
extend Earth::Base
|
3
3
|
set_primary_key :io_code
|
4
4
|
|
5
|
-
has_many :product_line_sectors, :foreign_key => 'io_code'
|
6
|
-
|
7
5
|
def self.schema_definition
|
8
6
|
lambda do
|
9
7
|
string 'io_code'
|
10
8
|
string 'description'
|
11
|
-
float
|
12
|
-
string 'emission_factor_units'
|
9
|
+
float 'value'
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
@@ -5,15 +5,31 @@ EgridRegion.class_eval do
|
|
5
5
|
float 'loss_factor'
|
6
6
|
end
|
7
7
|
|
8
|
+
# NOTE: the following import uses an 18 Mb zip - don't know if two imports will cause it to be downloaded twice...
|
9
|
+
#
|
10
|
+
# import "eGRID regions and loss factors derived from eGRID 2007 data",
|
11
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
12
|
+
# :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
|
13
|
+
# :sheet => 'STIE05',
|
14
|
+
# :skip => 4,
|
15
|
+
# :select => lambda { |row| row['eGRID2007 2005 file State sequence number'].to_i.between?(1, 51) } do
|
16
|
+
# key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
|
17
|
+
# store 'loss_factor', :field_name => '2005 grid gross loss factor'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# import "the US average grid loss factor derived eGRID 2007 data"
|
21
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
22
|
+
# :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
|
23
|
+
# :sheet => 'USGC',
|
24
|
+
# :skip => 5 do
|
25
|
+
# key # the name should be 'US'
|
26
|
+
# store # store the result of (USTNGN05 + USTNFI05 - USTCON05) / USTNGN05
|
27
|
+
# end
|
28
|
+
|
8
29
|
import "eGRID regions and loss factors derived from eGRID 2007 data",
|
9
|
-
:url => '
|
10
|
-
|
11
|
-
|
12
|
-
:select => lambda { |row| row['eGRID2007 2005 file State sequence number'].to_i.between?(1, 51) },
|
13
|
-
:skip => 4 do
|
14
|
-
key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
|
15
|
-
store 'loss_factor', :field_name => '2005 grid gross loss factor'
|
30
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHoydC1MdDY0YVZkRE5zN0huOUZYbnc&hl=en&single=true&gid=0&output=csv' do
|
31
|
+
key 'name'
|
32
|
+
store 'loss_factor'
|
16
33
|
end
|
17
34
|
end
|
18
35
|
end
|
19
|
-
|
@@ -9,18 +9,57 @@ EgridSubregion.class_eval do
|
|
9
9
|
string 'egrid_region_name'
|
10
10
|
end
|
11
11
|
|
12
|
-
process "
|
13
|
-
|
14
|
-
|
12
|
+
# process "define some unit conversions" do
|
13
|
+
# Conversions.register :pounds_per_megawatt_hour, :kilograms_per_kilowatt_hour, 0.00045359237
|
14
|
+
# Conversions.register :pounds_per_gigawatt_hour, :kilograms_per_kilowatt_hour, 0.00000045359237
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# NOTE: the following import uses an 18 Mb zip - don't know if two imports will cause it to be downloaded twice...
|
18
|
+
#
|
19
|
+
# import "eGRID regions and electricity emission factors derived from eGRID 2007 data",
|
20
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
21
|
+
# :filename => 'eGRID2007V1_1_year05_aggregation.xls',
|
22
|
+
# :sheet => 'SRL05',
|
23
|
+
# :skip => 3,
|
24
|
+
# :select => lambda { |row| row['eGRID2007 2005 file eGRID subregion location (operator)-based sequence number'].to_i.between?(1, 26) } do
|
25
|
+
# key 'abbreviation', :field_name => 'eGRID subregion acronym'
|
26
|
+
# store 'name', :field_name => 'eGRID subregion name associated with eGRID subregion acronym'
|
27
|
+
# store 'nerc_abbreviation', :field_name => 'NERC region acronym associated with the eGRID subregion acronym'
|
28
|
+
# store 'electricity_ef_co2', :field_name => 'eGRID subregion annual CO2 output emission rate (lb/MWh)', :from_units => :pounds_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
29
|
+
# store 'electricity_ef_ch4', :field_name => 'eGRID subregion annual CH4 output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
30
|
+
# store 'electricity_ef_n2o', :field_name => 'eGRID subregion annual N2O output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# import "US average electricity emission factors derived from eGRID 2007 data",
|
34
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
35
|
+
# :filename => 'eGRID2007V1_1_year05_aggregation.xls',
|
36
|
+
# :sheet => 'US05',
|
37
|
+
# :skip => 3,
|
38
|
+
# :select => lambda { |row| row['eGRID2007 2005 file US sequence number'].to_i.is?(1) } do
|
39
|
+
# key # the single row should be keyed 'US'
|
40
|
+
# store 'name' # the single row should be named 'United States Average'
|
41
|
+
# store 'electricity_ef_co2', :field_name => 'US annual CO2 output emission rate (lb/MWh)', :from_units => :pounds_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
42
|
+
# store 'electricity_ef_ch4', :field_name => 'US annual CH4 output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
43
|
+
# store 'electricity_ef_n2o', :field_name => 'US annual N2O output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# import "the eGRID regions associated with each subregion" do
|
47
|
+
# :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRORTJNSWRMQ1puRVprYlAtZHhDaFE&hl=en&single=true&gid=0&output=csv' do
|
48
|
+
# key 'abbreviation'
|
49
|
+
# store 'egrid_region_name'
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# process "Calculate CO2e emission factor"
|
53
|
+
# # multiply each gas ef by the gas GWP and sum
|
54
|
+
# end
|
15
55
|
|
16
|
-
import "a list of eGRID subregions and
|
17
|
-
:url => '
|
56
|
+
import "a list of eGRID subregions and emissions factors derived from eGRID 2007 data",
|
57
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRORTJNSWRMQ1puRVprYlAtZHhDaFE&hl=en&single=true&gid=0&output=csv' do
|
18
58
|
key 'abbreviation'
|
19
59
|
store 'name'
|
20
|
-
store 'electricity_emission_factor', :from_units => :kilograms_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
21
60
|
store 'nerc_abbreviation'
|
22
61
|
store 'egrid_region_name'
|
62
|
+
store 'electricity_emission_factor', :units_field_name => 'electricity_emission_factor_units'
|
23
63
|
end
|
24
64
|
end
|
25
65
|
end
|
26
|
-
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
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-09-
|
20
|
+
date: 2010-09-22 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -325,13 +325,14 @@ files:
|
|
325
325
|
- lib/earth/hospitality/lodging_class/data_miner.rb
|
326
326
|
- lib/earth/industry.rb
|
327
327
|
- lib/earth/industry/industry.rb
|
328
|
+
- lib/earth/industry/industry_product.rb
|
328
329
|
- lib/earth/industry/industry_product_line.rb
|
329
330
|
- lib/earth/industry/industry_sector.rb
|
330
331
|
- lib/earth/industry/merchant.rb
|
331
332
|
- lib/earth/industry/merchant_category.rb
|
332
333
|
- lib/earth/industry/merchant_category_industry.rb
|
333
334
|
- lib/earth/industry/product_line.rb
|
334
|
-
- lib/earth/industry/
|
335
|
+
- lib/earth/industry/product_line_industry_product.rb
|
335
336
|
- lib/earth/industry/sector.rb
|
336
337
|
- lib/earth/inflectors.rb
|
337
338
|
- lib/earth/locality.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class ProductLineSector < ActiveRecord::Base
|
2
|
-
extend Earth::Base
|
3
|
-
belongs_to :product_line, :foreign_key => 'ps_code'
|
4
|
-
belongs_to :sector, :foreign_key => 'io_code'
|
5
|
-
|
6
|
-
def self.schema_definition
|
7
|
-
lambda do
|
8
|
-
string 'row_hash'
|
9
|
-
string 'ps_code'
|
10
|
-
float 'ratio'
|
11
|
-
string 'io_code'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
data_miner do
|
16
|
-
ProductLineSector.define_schema(self)
|
17
|
-
end
|
18
|
-
end
|