earth 0.11.11 → 0.11.12
Sign up to get free protection for your applications and to get access to all the features.
- data/earth.gemspec +1 -1
- data/lib/earth/air/flight_distance_class_seat_class.rb +3 -0
- data/lib/earth/conversions_ext.rb +3 -3
- data/lib/earth/industry/cbecs_energy_intensity.rb +42 -3
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +0 -23
- data/lib/earth/industry/industry.rb +4 -2
- data/lib/earth/industry/mecs_energy.rb +16 -4
- data/lib/earth/industry/mecs_ratio.rb +8 -2
- data/lib/earth/industry/naics_2002.rb +15 -0
- data/lib/earth/industry/naics_2002/data_miner.rb +12 -0
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +16 -0
- data/lib/earth/industry/naics_2002_naics_2007_concordance/data_miner.rb +16 -0
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +16 -0
- data/lib/earth/industry/naics_2002_sic_1987_concordance/data_miner.rb +15 -0
- data/lib/earth/industry/naics_2007.rb +10 -0
- data/lib/earth/industry/naics_2007/data_miner.rb +12 -0
- data/lib/earth/industry/sic_1987.rb +16 -0
- data/lib/earth/industry/sic_1987/data_miner.rb +10 -0
- data/lib/earth/pet/species.rb +2 -0
- data/lib/earth/version.rb +1 -1
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +93 -58
- data/spec/earth/industry/industry_spec.rb +28 -0
- data/spec/earth/industry/mecs_energy_spec.rb +46 -24
- data/spec/earth/industry/mecs_ratio_spec.rb +43 -23
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +41 -0
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +41 -0
- data/spec/earth/industry/naics_2002_spec.rb +59 -0
- data/spec/earth/industry/naics_2007_spec.rb +35 -0
- data/spec/earth/industry/sic_1987_spec.rb +55 -0
- data/spec/earth_spec.rb +3 -3
- metadata +26 -6
- data/spec/earth/hospitality/lodging_fuel_use_equation_spec.rb +0 -96
data/earth.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "earth/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "earth"
|
7
7
|
s.version = Earth::VERSION
|
8
|
-
s.date = "2012-02-
|
8
|
+
s.date = "2012-02-20"
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = ["Seamus Abshere", "Derek Kastner", "Andy Rossmeissl"]
|
11
11
|
s.email = %q{andy@rossmeissl.net}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
class FlightDistanceClassSeatClass < ActiveRecord::Base
|
2
2
|
self.primary_key = "name"
|
3
3
|
|
4
|
+
belongs_to :seat_class, :class_name => 'FlightSeatClass', :foreign_key => 'seat_class_name'
|
5
|
+
belongs_to :distance_class, :class_name => 'FlightDistanceClass', :foreign_key => 'distance_class_name'
|
6
|
+
|
4
7
|
falls_back_on :name => 'fallback',
|
5
8
|
:multiplier => 1.0
|
6
9
|
|
@@ -76,13 +76,13 @@ Conversions.register :kbtus, :joules, (1_000.0 * 1_055.0558
|
|
76
76
|
Conversions.register :watt_hours, :joules, 3_600.0
|
77
77
|
Conversions.register :kilowatt_hours, :joules, 3_600_000.0
|
78
78
|
|
79
|
-
# Odd units for CBECS
|
79
|
+
# Odd units for CBECS 2003
|
80
80
|
Conversions.register :trillion_btus_per_million_square_feet, :megajoules_per_square_metre, (1.trillion_btus.to(:megajoules) / 1.square_feet.to(:square_metres))
|
81
81
|
Conversions.register :kilowatt_hours_per_square_foot, :megajoules_per_square_metre, (1.kilowatt_hours.to(:megajoules) / 1.square_feet.to(:square_metres))
|
82
82
|
Conversions.register :billion_cubic_feet_of_natural_gas, :megajoules, (1_000_000_000.cubic_feet.to(:cubic_metres) * 38.3395) # 2003 NatGas energy content MJ/m3
|
83
83
|
Conversions.register :cubic_feet_of_natural_gas_per_square_foot, :megajoules_per_square_metre, ((1.cubic_feet.to(:cubic_metres) * 38.3395) / 1.square_feet.to(:square_metres))
|
84
|
-
Conversions.register :million_gallons_of_fuel_oil, :megajoules, (1_000_000.gallons.to(:litres) *
|
85
|
-
Conversions.register :gallons_of_fuel_oil_per_square_foot, :megajoules_per_square_metre, ((
|
84
|
+
Conversions.register :million_gallons_of_fuel_oil, :megajoules, (1_000_000.gallons.to(:litres) * 41.9203) # Residual Fuel Oil No. 6 energy content MJ/l from Fuels
|
85
|
+
Conversions.register :gallons_of_fuel_oil_per_square_foot, :megajoules_per_square_metre, ((41.9203 * 1.gallons.to(:litres)) / 1.square_feet.to(:square_metres))
|
86
86
|
|
87
87
|
# Only used in app1
|
88
88
|
Conversions.register(:pounds_per_gallon, :kilograms_per_litre, 0.119826427) # only used in app1
|
@@ -41,18 +41,57 @@ class CbecsEnergyIntensity < ActiveRecord::Base
|
|
41
41
|
scope :regional, where('census_region_number IS NOT NULL AND census_division_number IS NULL')
|
42
42
|
scope :national, where(:census_region_number => nil, :census_division_number => nil)
|
43
43
|
|
44
|
+
FUELS = {
|
45
|
+
:electricity => {
|
46
|
+
:consumption => :billion_kilowatt_hours,
|
47
|
+
:intensity => :kilowatt_hours_per_square_foot,
|
48
|
+
:set => 10
|
49
|
+
},
|
50
|
+
:natural_gas => {
|
51
|
+
:consumption => :billion_cubic_feet_of_natural_gas,
|
52
|
+
:intensity => :cubic_feet_of_natural_gas_per_square_foot,
|
53
|
+
:set => 11
|
54
|
+
},
|
55
|
+
:fuel_oil => {
|
56
|
+
:consumption => :million_gallons_of_fuel_oil,
|
57
|
+
:intensity => :gallons_of_fuel_oil_per_square_foot,
|
58
|
+
:set => 12
|
59
|
+
},
|
60
|
+
:district_heat => {
|
61
|
+
:consumption => :trillion_btu,
|
62
|
+
:intensity => :trillion_btu_per_million_square_feet,
|
63
|
+
:set => 13
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
# Find the first record whose naics_code matches code.
|
68
|
+
# If no record found chop off the last character of code and try again, and so on.
|
69
|
+
def self.find_by_naics_code(code)
|
70
|
+
find_by_naics_code_and_census_field(code, :census_region_number, nil)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Find the first record whose census_region_number matches number and whose naics_code matches code.
|
74
|
+
# If no record found chop off the last character of code and try again, and so on.
|
75
|
+
def self.find_by_naics_code_and_census_region_number(code, number)
|
76
|
+
find_by_naics_code_and_census_field(code, :census_region_number, number)
|
77
|
+
end
|
78
|
+
|
44
79
|
# Find the first record whose census_division_number matches number and whose naics_code matches code.
|
45
80
|
# If no record found chop off the last character of code and try again, and so on.
|
46
81
|
def self.find_by_naics_code_and_census_division_number(code, number)
|
82
|
+
find_by_naics_code_and_census_field(code, :census_division_number, number)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.find_by_naics_code_and_census_field(code, field, number)
|
47
86
|
if code.blank?
|
48
87
|
record = nil
|
49
88
|
else
|
50
|
-
record = where(
|
51
|
-
record ||=
|
89
|
+
record = where(field => number, :naics_code => code).first
|
90
|
+
record ||= find_by_naics_code_and_census_field(code[0..-2], field, number)
|
52
91
|
end
|
53
92
|
record
|
54
93
|
end
|
55
|
-
|
94
|
+
|
56
95
|
def fuel_ratios
|
57
96
|
energy = 0
|
58
97
|
FUELS.keys.each { |fuel| energy += send(fuel).to_f }
|
@@ -3,29 +3,6 @@ require 'earth/industry'
|
|
3
3
|
require 'earth/locality/data_miner'
|
4
4
|
|
5
5
|
CbecsEnergyIntensity.class_eval do
|
6
|
-
const_set :FUELS, {
|
7
|
-
:electricity => {
|
8
|
-
:consumption => :billion_kilowatt_hours,
|
9
|
-
:intensity => :kilowatt_hours_per_square_foot,
|
10
|
-
:set => 10
|
11
|
-
},
|
12
|
-
:natural_gas => {
|
13
|
-
:consumption => :billion_cubic_feet_of_natural_gas,
|
14
|
-
:intensity => :cubic_feet_of_natural_gas_per_square_foot,
|
15
|
-
:set => 11
|
16
|
-
},
|
17
|
-
:fuel_oil => {
|
18
|
-
:consumption => :million_gallons_of_fuel_oil,
|
19
|
-
:intensity => :gallons_of_fuel_oil_per_square_foot,
|
20
|
-
:set => 12
|
21
|
-
},
|
22
|
-
:district_heat => {
|
23
|
-
:consumption => :trillion_btu,
|
24
|
-
:intensity => :trillion_btu_per_million_square_feet,
|
25
|
-
:set => 13
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
6
|
const_set(:CBECS, {
|
30
7
|
:region_tables => {
|
31
8
|
:electricity => 'c15',
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'earth/locality'
|
2
|
+
|
3
|
+
# TODO replace this with NAICS 2002?
|
2
4
|
class Industry < ActiveRecord::Base
|
3
5
|
self.primary_key = "naics_code"
|
4
6
|
|
@@ -12,13 +14,13 @@ class Industry < ActiveRecord::Base
|
|
12
14
|
|
13
15
|
col :naics_code
|
14
16
|
col :description
|
15
|
-
|
17
|
+
|
16
18
|
class << self
|
17
19
|
def format_naics_code(input)
|
18
20
|
"%d" % input.to_i
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
23
|
+
|
22
24
|
def trade_industry?
|
23
25
|
prefix = naics_code.to_s[0,2]
|
24
26
|
%w{42 44 45}.include?(prefix)
|
@@ -28,6 +28,12 @@ class MecsEnergy < ActiveRecord::Base
|
|
28
28
|
FUELS = [:electricity, :residual_fuel_oil, :distillate_fuel_oil,
|
29
29
|
:natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other_fuel]
|
30
30
|
|
31
|
+
# Find the first record whose naics_code matches code.
|
32
|
+
# If no record found chop off the last character of code and try again, and so on.
|
33
|
+
def self.find_by_naics_code(code)
|
34
|
+
find_by_naics_code_and_census_region_number(code, nil)
|
35
|
+
end
|
36
|
+
|
31
37
|
# Find the first record whose census_region_number matches number and whose naics_code matches code.
|
32
38
|
# If no record found chop off the last character of code and try again, and so on.
|
33
39
|
def self.find_by_naics_code_and_census_region_number(code, number)
|
@@ -35,16 +41,22 @@ class MecsEnergy < ActiveRecord::Base
|
|
35
41
|
record = nil
|
36
42
|
else
|
37
43
|
code = Industry.format_naics_code code
|
38
|
-
record = where(
|
44
|
+
record = where(:census_region_number => number, :naics_code => code).first
|
39
45
|
record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
|
40
46
|
end
|
41
47
|
record
|
42
48
|
end
|
43
49
|
|
50
|
+
# TODO make this less paranoid
|
51
|
+
# for now only return a ratio if no fuels are nil and at least one fuel is nonzero
|
44
52
|
def fuel_ratios
|
45
|
-
|
46
|
-
ratios
|
47
|
-
|
53
|
+
if energy.to_f > 0 # return nil if energy is nil or 0
|
54
|
+
ratios = FUELS.inject({}) do |r, fuel|
|
55
|
+
fuel_use = send("#{fuel}")
|
56
|
+
r[fuel] = fuel_use.present? ? fuel_use / energy : nil
|
57
|
+
r
|
58
|
+
end
|
59
|
+
ratios unless ratios.values.include? nil or ratios.values.all?(&:zero?) # return nil if any fuel uses were missing or all fuel uses were zero
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
@@ -12,14 +12,20 @@ class MecsRatio < ActiveRecord::Base
|
|
12
12
|
col :energy_per_dollar_of_shipments, :type => :float
|
13
13
|
col :energy_per_dollar_of_shipments_units
|
14
14
|
|
15
|
-
# Find the first
|
15
|
+
# Find the first record whose naics_code matches code.
|
16
|
+
# If no record found chop off the last character of code and try again, and so on.
|
17
|
+
def self.find_by_naics_code(code)
|
18
|
+
find_by_naics_code_and_census_region_number(code, nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Find the first record whose census_region_number matches number and whose naics_code matches code.
|
16
22
|
# If none found, chop off the last character of code and try again, and so on.
|
17
23
|
def self.find_by_naics_code_and_census_region_number(code, number)
|
18
24
|
if code.blank?
|
19
25
|
record = nil
|
20
26
|
else
|
21
27
|
code = Industry.format_naics_code code
|
22
|
-
record = where(
|
28
|
+
record = where(:census_region_number => number, :naics_code => code).first
|
23
29
|
record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
|
24
30
|
end
|
25
31
|
record
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Naics2002 < ActiveRecord::Base
|
2
|
+
self.primary_key = "code"
|
3
|
+
self.table_name = "naics_2002"
|
4
|
+
|
5
|
+
belongs_to :industry, :foreign_key => :code
|
6
|
+
|
7
|
+
has_many :naics_2002_sic_1987_concordances, :foreign_key => :naics_2002_code
|
8
|
+
has_many :sic_1987, :through => :naics_2002_sic_1987_concordances
|
9
|
+
|
10
|
+
has_many :naics_2002_naics_2007_concordances, :foreign_key => :naics_2002_code
|
11
|
+
has_many :naics_2007, :through => :naics_2002_naics_2007_concordances
|
12
|
+
|
13
|
+
col :code
|
14
|
+
col :description
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Naics2002.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "the U.S. Census 2002 NAICS code list",
|
4
|
+
:url => 'http://www.census.gov/eos/www/naics/reference_files_tools/2002/naics_2_6_02.txt',
|
5
|
+
:skip => 4,
|
6
|
+
:headers => %w{ code description },
|
7
|
+
:delimiter => ' ' do
|
8
|
+
key 'code'
|
9
|
+
store 'description'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Naics2002Naics2007Concordance < ActiveRecord::Base
|
2
|
+
self.primary_key = "row_hash"
|
3
|
+
|
4
|
+
belongs_to :naics_2002, :foreign_key => :naics_2002_code
|
5
|
+
belongs_to :naics_2007, :foreign_key => :naics_2007_code
|
6
|
+
|
7
|
+
# for data import
|
8
|
+
def self.extract_note(description)
|
9
|
+
(note = description.match(/ - (.+)/)) ? note.captures.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
col :row_hash
|
13
|
+
col :naics_2002_code
|
14
|
+
col :naics_2007_code
|
15
|
+
col :naics_2002_note
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'earth/industry/naics_2002'
|
2
|
+
require 'earth/industry/naics_2007'
|
3
|
+
|
4
|
+
Naics2002Naics2007Concordance.class_eval do
|
5
|
+
data_miner do
|
6
|
+
import "the US Census NAICS 2002 to NAICS 2007 concordance",
|
7
|
+
:url => 'http://www.census.gov/eos/www/naics/concordances/2002_to_2007_NAICS.xls',
|
8
|
+
:skip => 3,
|
9
|
+
:headers => %w{ 2002_code 2002_title 2007_code 2007_title } do
|
10
|
+
key 'row_hash'
|
11
|
+
store 'naics_2002_code', :synthesize => lambda { |row| "%06d" % row['2002_code'].to_i }
|
12
|
+
store 'naics_2007_code', :synthesize => lambda { |row| "%06d" % row['2007_code'].to_i }
|
13
|
+
store 'naics_2002_note', :synthesize => lambda { |row| extract_note row['2002_title'] }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Naics2002Sic1987Concordance < ActiveRecord::Base
|
2
|
+
self.primary_key = "row_hash"
|
3
|
+
|
4
|
+
belongs_to :naics_2002, :foreign_key => :naics_2002_code
|
5
|
+
belongs_to :sic_1987, :foreign_key => :sic_1987_code
|
6
|
+
|
7
|
+
# for data import
|
8
|
+
def self.extract_note(description)
|
9
|
+
(note = description.match /.+?\((.+)\)/) ? note.captures.first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
col :row_hash
|
13
|
+
col :naics_2002_code
|
14
|
+
col :sic_1987_code
|
15
|
+
col :sic_note
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'earth/industry/naics_2002'
|
2
|
+
require 'earth/industry/sic_1987'
|
3
|
+
|
4
|
+
Naics2002Sic1987Concordance.class_eval do
|
5
|
+
data_miner do
|
6
|
+
import "the US Census SIC 1987 to NAICS 2002 concordance",
|
7
|
+
:url => 'http://www.census.gov/eos/www/naics/concordances/1987_SIC_to_2002_NAICS.xls',
|
8
|
+
:select => lambda {|row| row['SIC'].to_i > 0} do
|
9
|
+
key 'row_hash'
|
10
|
+
store 'naics_2002_code', :synthesize => lambda { |row| "%06d" % row['2002 NAICS'].to_i }
|
11
|
+
store 'sic_1987_code', :synthesize => lambda { |row| "%04d" % row['SIC'].to_i }
|
12
|
+
store 'sic_note', :synthesize => lambda { |row| extract_note row['SIC Title (and note)'] }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Naics2007 < ActiveRecord::Base
|
2
|
+
self.primary_key = "code"
|
3
|
+
self.table_name = "naics_2007"
|
4
|
+
|
5
|
+
has_many :naics_2002_naics_2007_concordances, :foreign_key => :naics_2007_code
|
6
|
+
has_many :naics_2002, :through => :naics_2002_naics_2007_concordances
|
7
|
+
|
8
|
+
col :code
|
9
|
+
col :description
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Naics2007.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "the U.S. Census 2007 NAICS code list",
|
4
|
+
:url => 'http://www.census.gov/eos/www/naics/reference_files_tools/2007/naics07.txt',
|
5
|
+
:skip => 2,
|
6
|
+
:headers => %w{ IGNORE code description },
|
7
|
+
:delimiter => ' ' do
|
8
|
+
key 'code'
|
9
|
+
store 'description'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Sic1987 < ActiveRecord::Base
|
2
|
+
self.primary_key = "code"
|
3
|
+
self.table_name = "sic_1987"
|
4
|
+
|
5
|
+
has_many :naics_2002_sic_1987_concordances, :foreign_key => :sic_1987_code
|
6
|
+
has_many :naics_2002, :through => :naics_2002_sic_1987_concordances
|
7
|
+
has_many :industries, :through => :naics_2002
|
8
|
+
|
9
|
+
# for data import
|
10
|
+
def self.format_description(description)
|
11
|
+
(desc = description.match /^(.+?) \(/) ? desc.captures.first : description
|
12
|
+
end
|
13
|
+
|
14
|
+
col :code
|
15
|
+
col :description
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Sic1987.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "SIC 1987 codes derived from US Census SIC 1987 to NAICS 2002 concordance",
|
4
|
+
:url => 'http://www.census.gov/eos/www/naics/concordances/1987_SIC_to_2002_NAICS.xls',
|
5
|
+
:select => lambda {|row| row['SIC'].to_i > 0} do
|
6
|
+
key 'code', :synthesize => lambda { |row| "%04d" % row['SIC'].to_i }
|
7
|
+
store 'description', :synthesize => lambda { |row| format_description row['SIC Title (and note)'] }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/earth/pet/species.rb
CHANGED
@@ -15,6 +15,8 @@ class Species < ActiveRecord::Base
|
|
15
15
|
col :minimum_weight_units
|
16
16
|
col :maximum_weight, :type => :float
|
17
17
|
col :maximum_weight_units
|
18
|
+
|
19
|
+
has_many :breeds, :foreign_key => 'species_name'
|
18
20
|
|
19
21
|
scope :thoroughly_researched, :conditions => 'marginal_dietary_requirement IS NOT NULL'
|
20
22
|
|
data/lib/earth/version.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'earth/industry/cbecs_energy_intensity'
|
3
|
-
require 'earth/industry/cbecs_energy_intensity/data_miner'
|
4
3
|
|
5
4
|
def create_cbecs(name, args)
|
6
5
|
c = CbecsEnergyIntensity.new args
|
@@ -9,86 +8,59 @@ def create_cbecs(name, args)
|
|
9
8
|
end
|
10
9
|
|
11
10
|
describe CbecsEnergyIntensity do
|
12
|
-
|
13
|
-
CbecsEnergyIntensity.auto_upgrade!
|
14
|
-
end
|
15
|
-
before :each do
|
16
|
-
CbecsEnergyIntensity.delete_all
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '.find_by_naics_code_and_census_division_number' do
|
11
|
+
describe 'import', :slow => true do
|
20
12
|
before do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
create_cbecs '4', :naics_code => '44', :census_division_number => 2
|
25
|
-
create_cbecs '5', :naics_code => '445', :census_division_number => 2
|
26
|
-
create_cbecs '6', :naics_code => '621', :census_division_number => 2
|
27
|
-
end
|
28
|
-
it 'finds an exact match' do
|
29
|
-
record = CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('445', 2)
|
30
|
-
record.naics_code.should == '445'
|
31
|
-
record.census_division_number.should == 2
|
32
|
-
end
|
33
|
-
it 'finds a parent category when exact code is not present' do
|
34
|
-
record = CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('4451', 2)
|
35
|
-
record.naics_code.should == '445'
|
36
|
-
record.census_division_number.should == 2
|
37
|
-
end
|
38
|
-
it 'does not find a sibling category' do
|
39
|
-
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('622', 2).
|
40
|
-
should be_nil
|
13
|
+
require 'earth/industry/cbecs_energy_intensity/data_miner'
|
14
|
+
CbecsEnergyIntensity.auto_upgrade!
|
15
|
+
CbecsEnergyIntensity.delete_all
|
41
16
|
end
|
42
|
-
it 'returns nil if no match found' do
|
43
|
-
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('8131', 1).
|
44
|
-
should be_nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#fuel_ratios' do
|
49
|
-
it 'makes ratios from fuel energies' do
|
50
|
-
cbecs = CbecsEnergyIntensity.new :name => '1', :electricity => 1000, :natural_gas => 2000, :fuel_oil => 500, :district_heat => 0
|
51
|
-
cbecs.fuel_ratios.should == {
|
52
|
-
:electricity => 0.2857142857142857,
|
53
|
-
:natural_gas => 0.5714285714285714,
|
54
|
-
:fuel_oil => 0.14285714285714285,
|
55
|
-
:district_heat => 0.0
|
56
|
-
}
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'import', :slow => true do
|
61
17
|
it 'fetches electric, natural gas, fuel oil, and distric heat data' do
|
62
18
|
CbecsEnergyIntensity.run_data_miner!
|
63
|
-
|
64
|
-
|
19
|
+
CbecsEnergyIntensity.count.should == 182
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'verify imported data', :sanity => true do
|
24
|
+
#TODO check values
|
25
|
+
it 'checks census divisions' do
|
65
26
|
divisionals = CbecsEnergyIntensity.divisional
|
66
27
|
divisionals.count.should == 117
|
67
28
|
spot_check(divisionals, [
|
68
29
|
[[:principal_building_activity, :census_region_number, :census_division_number], [:electricity, :natural_gas]],
|
69
|
-
|
70
30
|
[['Education', 1, 1], [:nil, :nil]],
|
71
31
|
[['Education', 1, 2], [:present, :present]],
|
72
32
|
])
|
73
|
-
|
74
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO check values
|
36
|
+
# [[:principal_building_activity, :census_region_number], [:electricity, :fuel_oil]],
|
37
|
+
# [['Education', 1], [46_800_000_000, 44_749_338_478]],
|
38
|
+
# [['Education', 2], [72_000_000_000, :nil]],
|
39
|
+
# [['Education', 3], [208_800_000_000, :nil]],
|
40
|
+
# [['Education', 4], [61_200_000_000, :nil]],
|
41
|
+
# [['Health Care', 1], [36_000_000_000, :nil]],
|
42
|
+
# [['Health Care', 2], [64_800_000_000, :nil]],
|
43
|
+
# [['Health Care', 3], [111_600_000_000, 2_697_655_156]],
|
44
|
+
# [['Health Care', 4], [43_200_000_000, 1_110_799_182]],
|
45
|
+
it 'checks cenusus regions' do
|
75
46
|
regionals = CbecsEnergyIntensity.regional
|
76
47
|
regionals.count.should == 52
|
77
48
|
spot_check(regionals, [
|
78
49
|
[[:principal_building_activity, :census_region_number], [:electricity, :fuel_oil]],
|
79
|
-
# Regional fuel oil
|
80
50
|
[['Education', 1], [:present, :present]],
|
81
51
|
[['Education', 2], [:present, :nil]],
|
82
52
|
[['Education', 3], [:present, :nil]],
|
83
53
|
[['Education', 4], [:present, :nil]],
|
84
|
-
|
85
54
|
[['Health Care', 1], [:present, :nil]],
|
86
55
|
[['Health Care', 2], [:present, :nil]],
|
87
56
|
[['Health Care', 3], [:present, :present]],
|
88
57
|
[['Health Care', 4], [:present, :present]],
|
58
|
+
|
89
59
|
])
|
90
|
-
|
91
|
-
|
60
|
+
end
|
61
|
+
|
62
|
+
#TODO check values
|
63
|
+
it 'checks US averages' do
|
92
64
|
nationals = CbecsEnergyIntensity.national
|
93
65
|
nationals.count.should == 13
|
94
66
|
spot_check(nationals, [
|
@@ -97,6 +69,69 @@ describe CbecsEnergyIntensity do
|
|
97
69
|
[['Lodging'], [:present, :present, :nil]],
|
98
70
|
[['Office'], [:present, :present, :present]],
|
99
71
|
])
|
100
|
-
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '.find_by_naics_code_and_census_division_number' do
|
76
|
+
it 'finds an exact match' do
|
77
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('445', 2).name.should == '445-1-2'
|
78
|
+
end
|
79
|
+
it 'finds a parent category when exact code is not present' do
|
80
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('4451', 2).name.should == '445-1-2'
|
81
|
+
end
|
82
|
+
it 'does not find a sibling category' do
|
83
|
+
create_cbecs '72221-1-2', :naics_code => '72221', :census_division_number => 2, :census_region_number => 1
|
84
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('72229', 2).name.should == '722-1-2'
|
85
|
+
CbecsEnergyIntensity.delete '72221-1-2'
|
86
|
+
end
|
87
|
+
it 'returns nil if no match found' do
|
88
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('48', 2).should be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '.find_by_naics_code_and_census_region_number' do
|
93
|
+
it 'finds an exact match' do
|
94
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('445', 2).name.should == '445-2'
|
95
|
+
end
|
96
|
+
it 'finds a parent category when exact code is not present' do
|
97
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('4451', 2).name.should == '445-2'
|
98
|
+
end
|
99
|
+
it 'does not find a sibling category' do
|
100
|
+
create_cbecs '72221-2', :naics_code => '72221', :census_region_number => 2
|
101
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('72229', 2).name.should == '722-2'
|
102
|
+
CbecsEnergyIntensity.delete '72221-2'
|
103
|
+
end
|
104
|
+
it 'returns nil if no match found' do
|
105
|
+
CbecsEnergyIntensity.find_by_naics_code_and_census_region_number('48', 2).should be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.find_by_naics_code' do
|
110
|
+
it 'finds an exact match' do
|
111
|
+
CbecsEnergyIntensity.find_by_naics_code('445').name.should == '445'
|
112
|
+
end
|
113
|
+
it 'finds a parent category when exact code is not present' do
|
114
|
+
CbecsEnergyIntensity.find_by_naics_code('4451').name.should == '445'
|
115
|
+
end
|
116
|
+
it 'does not find a sibling category' do
|
117
|
+
create_cbecs '72221', :naics_code => '72221'
|
118
|
+
CbecsEnergyIntensity.find_by_naics_code('72229').name.should == '722'
|
119
|
+
CbecsEnergyIntensity.delete '72221'
|
120
|
+
end
|
121
|
+
it 'returns nil if no match found' do
|
122
|
+
CbecsEnergyIntensity.find_by_naics_code('48').should be_nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#fuel_ratios' do
|
127
|
+
it 'makes ratios from fuel energies' do
|
128
|
+
cbecs = CbecsEnergyIntensity.new :name => '1', :electricity => 1000, :natural_gas => 2000, :fuel_oil => 500, :district_heat => 0
|
129
|
+
cbecs.fuel_ratios.should == {
|
130
|
+
:electricity => 0.2857142857142857,
|
131
|
+
:natural_gas => 0.5714285714285714,
|
132
|
+
:fuel_oil => 0.14285714285714285,
|
133
|
+
:district_heat => 0.0
|
134
|
+
}
|
135
|
+
end
|
101
136
|
end
|
102
137
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/industry'
|
3
|
+
|
4
|
+
describe Industry do
|
5
|
+
before :all do
|
6
|
+
Industry.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/industry/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "imports all naics codes" do
|
15
|
+
Industry.run_data_miner!
|
16
|
+
Industry.count.should == 2341
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "methods" do
|
21
|
+
it "knows whether it's a trade industry (wholesale or retail trade)" do
|
22
|
+
Industry.find('42331').trade_industry?.should == true
|
23
|
+
Industry.find('445110').trade_industry?.should == true
|
24
|
+
Industry.find('4539').trade_industry?.should == true
|
25
|
+
Industry.find('33291').trade_industry?.should == false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,35 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'earth/industry'
|
3
2
|
require 'earth/industry/mecs_energy'
|
4
|
-
require 'earth/industry/
|
3
|
+
require 'earth/industry/industry' # MecsEnergy's custom find by method calls an Industry method
|
5
4
|
|
6
5
|
describe MecsEnergy do
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe 'import', :slow => true do
|
7
|
+
before do
|
8
|
+
require 'earth/industry/mecs_energy/data_miner'
|
9
|
+
MecsEnergy.auto_upgrade!
|
10
|
+
MecsEnergy.delete_all
|
11
|
+
end
|
12
|
+
it 'retrieves Total US statistics' do
|
13
|
+
MecsEnergy.run_data_miner!
|
14
|
+
MecsEnergy.count.should == 395
|
15
|
+
end
|
10
16
|
end
|
11
17
|
|
12
|
-
describe 'data
|
13
|
-
it '
|
18
|
+
describe 'verify imported data', :sanity => true do
|
19
|
+
it 'spot checks the data' do
|
14
20
|
apparel = MecsEnergy.find_by_naics_code '315'
|
15
21
|
apparel.census_region_number.should be_nil
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
apparel.energy.should be_within(10_000).of(14.trillion_btus.to(:megajoules))
|
23
|
+
apparel.energy_units.should == 'megajoules'
|
24
|
+
apparel.electricity.should == be_within(1_000).of(7.trillion_btus.to(:megajoules))
|
25
|
+
apparel.electricity_units.should == 'megajoules'
|
26
|
+
apparel.residual_fuel_oil.should == 0
|
27
|
+
apparel.residual_fuel_oil_units.should == 'megajoules'
|
28
|
+
apparel.distillate_fuel_oil.should == 0
|
29
|
+
apparel.distillate_fuel_oil_units.should == 'megajoules'
|
30
|
+
apparel.natural_gas.should == be_within(1_000).of(7.trillion_btus.to(:megajoules))
|
31
|
+
apparel.natural_gas_units.should == 'megajoules'
|
32
|
+
apparel.lpg_and_ngl.should == 0
|
33
|
+
apparel.lpg_and_ngl_units.should == 'megajoules'
|
34
|
+
apparel.coal.should == 0
|
35
|
+
apparel.coal_units.should == 'megajoules'
|
36
|
+
apparel.coke_and_breeze.should == 0
|
37
|
+
apparel.coke_and_breeze_units.should == 'megajoules'
|
38
|
+
apparel.other_fuel.should == 0
|
39
|
+
apparel.other_fuel_units.should == 'megajoules'
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
@@ -52,6 +59,21 @@ describe MecsEnergy do
|
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
62
|
+
describe '.find_by_naics_code' do
|
63
|
+
it 'finds an exact match' do
|
64
|
+
MecsEnergy.find_by_naics_code('311221').name.should == '311221-'
|
65
|
+
end
|
66
|
+
it 'finds a parent category when exact code is not present' do
|
67
|
+
MecsEnergy.find_by_naics_code('3117').name.should == '311-'
|
68
|
+
end
|
69
|
+
it 'finds a parent category rather than a sibling category' do
|
70
|
+
MecsEnergy.find_by_naics_code('311225').name.should == '3112-'
|
71
|
+
end
|
72
|
+
it 'returns nil if no match found' do
|
73
|
+
MecsEnergy.find_by_naics_code('543211').should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
55
77
|
describe '#fuel_ratios' do
|
56
78
|
it 'returns a list of fuel ratios for a given NAICS' do
|
57
79
|
energy = MecsEnergy.new :energy => 100, :electricity => 20,
|
@@ -1,40 +1,60 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'earth/industry/mecs_ratio'
|
3
|
+
require 'earth/industry/industry' # MecsRatio's custom find by method calls an Industry method
|
3
4
|
|
4
5
|
describe MecsRatio do
|
5
|
-
|
6
|
-
|
6
|
+
describe 'import', :slow => true do
|
7
|
+
before do
|
8
|
+
require 'earth/industry/mecs_ratio/data_miner'
|
9
|
+
MecsRatio.auto_upgrade!
|
10
|
+
MecsRatio.delete_all
|
11
|
+
end
|
12
|
+
it 'retrieves Total US statistics' do
|
13
|
+
MecsRatio.run_data_miner!
|
14
|
+
MecsRatio.count.should == 395
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'verify imported data', :sanity => true do
|
19
|
+
it 'spot checks the data' do
|
20
|
+
apparel = MecsRatio.find_by_naics_code '315'
|
21
|
+
apparel.census_region_number.should be_nil
|
22
|
+
apparel.energy_per_dollar_of_shipments.should == be_within(0.000_001).of(0.5.kbtus.to(:megajoules))
|
23
|
+
apparel.energy_per_dollar_of_shipments_units.should == 'megajoules'
|
24
|
+
end
|
7
25
|
end
|
8
26
|
|
9
27
|
describe '.find_by_naics_code_and_census_region_number' do
|
10
|
-
before do
|
11
|
-
MecsRatio.create! :naics_code => '311', :census_region_number => 1, :energy_per_dollar_of_shipments => 11
|
12
|
-
MecsRatio.create! :naics_code => '3112', :census_region_number => 1, :energy_per_dollar_of_shipments => 12
|
13
|
-
MecsRatio.create! :naics_code => '311221', :census_region_number => 1, :energy_per_dollar_of_shipments => 13
|
14
|
-
MecsRatio.create! :naics_code => '31131', :census_region_number => 1, :energy_per_dollar_of_shipments => 13
|
15
|
-
MecsRatio.create! :naics_code => '311', :census_region_number => 2, :energy_per_dollar_of_shipments => 17
|
16
|
-
MecsRatio.create! :naics_code => '3112', :census_region_number => 2, :energy_per_dollar_of_shipments => 18
|
17
|
-
MecsRatio.create! :naics_code => '311221', :census_region_number => 2, :energy_per_dollar_of_shipments => 19
|
18
|
-
MecsRatio.create! :naics_code => '31131', :census_region_number => 2, :energy_per_dollar_of_shipments => 20
|
19
|
-
end
|
20
|
-
|
21
28
|
it 'finds an exact match' do
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
MecsRatio.find_by_naics_code_and_census_region_number('311221', 2).
|
30
|
+
name.should == '311221-2'
|
31
|
+
end
|
32
|
+
it 'finds a parent category when exact code is not present' do
|
33
|
+
MecsRatio.find_by_naics_code_and_census_region_number('3117', 2).
|
34
|
+
name.should == '311-2'
|
35
|
+
end
|
36
|
+
it 'finds a parent category rather than a sibling category' do
|
37
|
+
MecsRatio.find_by_naics_code_and_census_region_number('311225', 2).
|
38
|
+
name.should == '3112-2'
|
39
|
+
end
|
40
|
+
it 'returns nil if no match found' do
|
41
|
+
MecsRatio.find_by_naics_code_and_census_region_number('543211', 2).
|
42
|
+
should be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.find_by_naics_code' do
|
47
|
+
it 'finds an exact match' do
|
48
|
+
MecsRatio.find_by_naics_code('311221').name.should == '311221-'
|
25
49
|
end
|
26
50
|
it 'finds a parent category when exact code is not present' do
|
27
|
-
|
28
|
-
ratio.naics_code.should == '311'
|
29
|
-
ratio.census_region_number.should == 2
|
51
|
+
MecsRatio.find_by_naics_code('3117').name.should == '311-'
|
30
52
|
end
|
31
53
|
it 'finds a parent category rather than a sibling category' do
|
32
|
-
|
33
|
-
ratio.naics_code.should == '3112'
|
34
|
-
ratio.census_region_number.should == 2
|
54
|
+
MecsRatio.find_by_naics_code('311225').name.should == '3112-'
|
35
55
|
end
|
36
56
|
it 'returns nil if no match found' do
|
37
|
-
MecsRatio.
|
57
|
+
MecsRatio.find_by_naics_code('543211').should be_nil
|
38
58
|
end
|
39
59
|
end
|
40
60
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
3
|
+
|
4
|
+
describe Naics2002Naics2007Concordance do
|
5
|
+
before :all do
|
6
|
+
Naics2002Naics2007Concordance.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/naics_2002_naics_2007_concordance/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "extracts a note from a description" do
|
15
|
+
Naics2002Naics2007Concordance.extract_note("Internet Service Providers - Internet services providers providing services via client-supplied telecommunications connection").
|
16
|
+
should == "Internet services providers providing services via client-supplied telecommunications connection"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "imports all naics codes" do
|
20
|
+
Naics2002Naics2007Concordance.run_data_miner!
|
21
|
+
Naics2002Naics2007Concordance.count.should == 1200
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "relationships" do
|
26
|
+
before do
|
27
|
+
require 'earth/industry/naics_2002'
|
28
|
+
require 'earth/industry/naics_2007'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "belongs to :naics_2002" do
|
32
|
+
Naics2002Naics2007Concordance.find_by_naics_2002_code("111219").
|
33
|
+
naics_2002.should == Naics2002.find("111219")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "belongs to :naics_2007" do
|
37
|
+
Naics2002Naics2007Concordance.find_by_naics_2007_code("111211").
|
38
|
+
naics_2007.should == Naics2007.find("111211")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/naics_2002_sic_1987_concordance'
|
3
|
+
|
4
|
+
describe Naics2002Sic1987Concordance do
|
5
|
+
before :all do
|
6
|
+
Naics2002Sic1987Concordance.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/naics_2002_sic_1987_concordance/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "extracts a paranthetical note from a description" do
|
15
|
+
Naics2002Sic1987Concordance.extract_note("Wood Household Furniture, Except Upholstered (wood box spring frames(parts))").
|
16
|
+
should == "wood box spring frames(parts)"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "imports all naics codes" do
|
20
|
+
Naics2002Sic1987Concordance.run_data_miner!
|
21
|
+
Naics2002Sic1987Concordance.count.should == 2164
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "relationships" do
|
26
|
+
before do
|
27
|
+
require 'earth/industry/naics_2002'
|
28
|
+
require 'earth/industry/sic_1987'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "belongs to :naics_2002" do
|
32
|
+
Naics2002Sic1987Concordance.find_by_naics_2002_code("111150").
|
33
|
+
naics_2002.should == Naics2002.find("111150")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "belongs to :sic_1987" do
|
37
|
+
Naics2002Sic1987Concordance.find_by_sic_1987_code("0119").
|
38
|
+
sic_1987.should == Sic1987.find("0119")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/naics_2002'
|
3
|
+
|
4
|
+
describe Naics2002 do
|
5
|
+
before :all do
|
6
|
+
Naics2002.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/naics_2002/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "imports all naics codes" do
|
15
|
+
Naics2002.run_data_miner!
|
16
|
+
Naics2002.count.should == 2341
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "code translations" do
|
21
|
+
before do
|
22
|
+
require 'earth/industry/sic_1987'
|
23
|
+
require 'earth/industry/naics_2002_sic_1987_concordance'
|
24
|
+
require 'earth/industry/naics_2007'
|
25
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
26
|
+
require 'earth/industry/industry'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can be translated to a SIC 1987 code" do
|
30
|
+
{
|
31
|
+
'111140' => %w{ 0111 },
|
32
|
+
'111150' => %w{ 0115 0119 },
|
33
|
+
'111920' => %w{ 0131 },
|
34
|
+
'238910' => %w{ 1081 1241 1389 1481 1629 1711 1794 1795 1799 7353 },
|
35
|
+
'488119' => %w{ 4581 4959 7997 }
|
36
|
+
}.each do |naics, sics|
|
37
|
+
Naics2002.find(naics).sic_1987.map(&:code).sort.should == sics
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can be translated to a NAICS 2007 code" do
|
42
|
+
{
|
43
|
+
'111150' => %w{ 111150 },
|
44
|
+
'111219' => %w{ 111211 111219 }
|
45
|
+
}.each do |naics_2002, naics_2007|
|
46
|
+
Naics2002.find(naics_2002).naics_2007.map(&:code).sort.should == naics_2007
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can be translated to an industry" do
|
51
|
+
{
|
52
|
+
'111150' => '111150',
|
53
|
+
'111219' => '111219'
|
54
|
+
}.each do |naics, industry|
|
55
|
+
Naics2002.find(naics).industry.naics_code.should == industry
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/naics_2007'
|
3
|
+
|
4
|
+
describe Naics2007 do
|
5
|
+
before :all do
|
6
|
+
Naics2007.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/naics_2007/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "imports all naics codes" do
|
15
|
+
Naics2007.run_data_miner!
|
16
|
+
Naics2007.count.should == 2328
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "code translations" do
|
21
|
+
before do
|
22
|
+
require 'earth/industry/naics_2002'
|
23
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can be translated to a NAICS 2002 code" do
|
27
|
+
{
|
28
|
+
'111211' => %w{ 111211 111219 },
|
29
|
+
'111310' => %w{ 111310 },
|
30
|
+
}.each do |naics_2007, naics_2002|
|
31
|
+
Naics2007.find(naics_2007).naics_2002.map(&:code).sort.should == naics_2002
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/industry/sic_1987'
|
3
|
+
|
4
|
+
describe Sic1987 do
|
5
|
+
before :all do
|
6
|
+
Sic1987.auto_upgrade!
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when importing data", :slow => true do
|
10
|
+
before do
|
11
|
+
require 'earth/industry/sic_1987/data_miner'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "imports all naics codes" do
|
15
|
+
Sic1987.run_data_miner!
|
16
|
+
Sic1987.count.should == 1004
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "verify imported data", :sanity => true do
|
21
|
+
it "has a description for every code" do
|
22
|
+
Sic1987.find_by_description(nil).should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "code translations" do
|
27
|
+
before do
|
28
|
+
require 'earth/industry/naics_2002'
|
29
|
+
require 'earth/industry/naics_2002_sic_1987_concordance'
|
30
|
+
|
31
|
+
require 'earth/industry/naics_2007'
|
32
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
33
|
+
|
34
|
+
require 'earth/industry/industry'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can be translated to a NAICS 2002 code" do
|
38
|
+
{
|
39
|
+
'0119' => %w{ 111120 111130 111150 111191 111199 },
|
40
|
+
'0131' => %w{ 111920 },
|
41
|
+
}.each do |sic, naics|
|
42
|
+
Sic1987.find(sic).naics_2002.map(&:code).sort.should == naics
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can be translated to an industry code" do
|
47
|
+
{
|
48
|
+
'0119' => %w{ 111120 111130 111150 111191 111199 },
|
49
|
+
'0131' => %w{ 111920 },
|
50
|
+
}.each do |sic, industries|
|
51
|
+
Sic1987.find(sic).industries.map(&:naics_code).sort.should == industries
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/earth_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Earth do
|
|
22
22
|
|
23
23
|
describe '.resources' do
|
24
24
|
it 'should get a list of all resource names' do
|
25
|
-
Earth.resources.length.should ==
|
25
|
+
Earth.resources.length.should == 100
|
26
26
|
Earth.resources.should include('Aircraft')
|
27
27
|
Earth.resources.should include('Industry')
|
28
28
|
end
|
@@ -33,8 +33,8 @@ describe Earth do
|
|
33
33
|
Earth.resources('computation').length.should == 3
|
34
34
|
Earth.resources('diet').length.should == 2
|
35
35
|
Earth.resources('fuel').length.should == 5
|
36
|
-
Earth.resources('hospitality').length.should ==
|
37
|
-
Earth.resources('industry').length.should ==
|
36
|
+
Earth.resources('hospitality').length.should == 4
|
37
|
+
Earth.resources('industry').length.should == 18
|
38
38
|
Earth.resources('locality').length.should == 10
|
39
39
|
Earth.resources('pet').length.should == 4
|
40
40
|
Earth.resources('rail').length.should == 12
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: earth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.11.
|
5
|
+
version: 0.11.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Seamus Abshere
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2012-02-
|
15
|
+
date: 2012-02-20 00:00:00 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|
@@ -504,9 +504,19 @@ files:
|
|
504
504
|
- lib/earth/industry/merchant.rb
|
505
505
|
- lib/earth/industry/merchant_category.rb
|
506
506
|
- lib/earth/industry/merchant_category_industry.rb
|
507
|
+
- lib/earth/industry/naics_2002.rb
|
508
|
+
- lib/earth/industry/naics_2002/data_miner.rb
|
509
|
+
- lib/earth/industry/naics_2002_naics_2007_concordance.rb
|
510
|
+
- lib/earth/industry/naics_2002_naics_2007_concordance/data_miner.rb
|
511
|
+
- lib/earth/industry/naics_2002_sic_1987_concordance.rb
|
512
|
+
- lib/earth/industry/naics_2002_sic_1987_concordance/data_miner.rb
|
513
|
+
- lib/earth/industry/naics_2007.rb
|
514
|
+
- lib/earth/industry/naics_2007/data_miner.rb
|
507
515
|
- lib/earth/industry/product_line.rb
|
508
516
|
- lib/earth/industry/product_line_industry_product.rb
|
509
517
|
- lib/earth/industry/sector.rb
|
518
|
+
- lib/earth/industry/sic_1987.rb
|
519
|
+
- lib/earth/industry/sic_1987/data_miner.rb
|
510
520
|
- lib/earth/inflectors.rb
|
511
521
|
- lib/earth/locality.rb
|
512
522
|
- lib/earth/locality/census_division.rb
|
@@ -603,10 +613,15 @@ files:
|
|
603
613
|
- spec/earth/bus/bus_fuel_control_spec.rb
|
604
614
|
- spec/earth/bus/bus_fuel_year_control_spec.rb
|
605
615
|
- spec/earth/fuel/fuel_spec.rb
|
606
|
-
- spec/earth/hospitality/lodging_fuel_use_equation_spec.rb
|
607
616
|
- spec/earth/industry/cbecs_energy_intensity_spec.rb
|
617
|
+
- spec/earth/industry/industry_spec.rb
|
608
618
|
- spec/earth/industry/mecs_energy_spec.rb
|
609
619
|
- spec/earth/industry/mecs_ratio_spec.rb
|
620
|
+
- spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb
|
621
|
+
- spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb
|
622
|
+
- spec/earth/industry/naics_2002_spec.rb
|
623
|
+
- spec/earth/industry/naics_2007_spec.rb
|
624
|
+
- spec/earth/industry/sic_1987_spec.rb
|
610
625
|
- spec/earth/locality/country_spec.rb
|
611
626
|
- spec/earth/pet/species_spec.rb
|
612
627
|
- spec/earth_spec.rb
|
@@ -670,7 +685,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
670
685
|
requirements:
|
671
686
|
- - ">="
|
672
687
|
- !ruby/object:Gem::Version
|
673
|
-
hash: -
|
688
|
+
hash: -2879856841116714656
|
674
689
|
segments:
|
675
690
|
- 0
|
676
691
|
version: "0"
|
@@ -679,7 +694,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
679
694
|
requirements:
|
680
695
|
- - ">="
|
681
696
|
- !ruby/object:Gem::Version
|
682
|
-
hash: -
|
697
|
+
hash: -2879856841116714656
|
683
698
|
segments:
|
684
699
|
- 0
|
685
700
|
version: "0"
|
@@ -780,10 +795,15 @@ test_files:
|
|
780
795
|
- spec/earth/bus/bus_fuel_control_spec.rb
|
781
796
|
- spec/earth/bus/bus_fuel_year_control_spec.rb
|
782
797
|
- spec/earth/fuel/fuel_spec.rb
|
783
|
-
- spec/earth/hospitality/lodging_fuel_use_equation_spec.rb
|
784
798
|
- spec/earth/industry/cbecs_energy_intensity_spec.rb
|
799
|
+
- spec/earth/industry/industry_spec.rb
|
785
800
|
- spec/earth/industry/mecs_energy_spec.rb
|
786
801
|
- spec/earth/industry/mecs_ratio_spec.rb
|
802
|
+
- spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb
|
803
|
+
- spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb
|
804
|
+
- spec/earth/industry/naics_2002_spec.rb
|
805
|
+
- spec/earth/industry/naics_2007_spec.rb
|
806
|
+
- spec/earth/industry/sic_1987_spec.rb
|
787
807
|
- spec/earth/locality/country_spec.rb
|
788
808
|
- spec/earth/pet/species_spec.rb
|
789
809
|
- spec/earth_spec.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'earth/hospitality'
|
3
|
-
require 'earth/hospitality/data_miner'
|
4
|
-
require 'charisma'
|
5
|
-
|
6
|
-
describe LodgingFuelUseEquation do
|
7
|
-
describe 'import', :slow => true do
|
8
|
-
it 'should import data without problems' do
|
9
|
-
LodgingFuelUseEquation.run_data_miner!
|
10
|
-
LodgingFuelUseEquation.all.count.should == 48
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'climate zone numbers' do
|
15
|
-
it 'should be nil or 1 through 5' do
|
16
|
-
LodgingFuelUseEquation.select('DISTINCT climate_zone_number').map(&:climate_zone_number).should == [nil, 1, 2, 3, 4, 5]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'electricity factors' do
|
21
|
-
it 'should produce reasonable electricity use estimates' do
|
22
|
-
LodgingFuelUseEquation.where(:fuel => 'Electricity').each do |equation|
|
23
|
-
if equation.property_rooms == true and equation.construction_year == true
|
24
|
-
estimate = equation.rooms_factor * equation.year_factor * equation.constant
|
25
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
26
|
-
|
27
|
-
estimate = equation.rooms_factor**1000 * equation.year_factor * equation.constant
|
28
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
29
|
-
|
30
|
-
estimate = equation.rooms_factor * equation.year_factor**2020 * equation.constant
|
31
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
32
|
-
|
33
|
-
estimate = equation.rooms_factor**1000 * equation.year_factor**2020 * equation.constant
|
34
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
35
|
-
elsif equation.property_rooms == true
|
36
|
-
estimate = equation.rooms_factor * equation.constant
|
37
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
38
|
-
|
39
|
-
estimate = equation.rooms_factor**1000 * equation.constant
|
40
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
41
|
-
elsif equation.construction_year == true
|
42
|
-
estimate = equation.year_factor * equation.constant
|
43
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
44
|
-
|
45
|
-
estimate = equation.year_factor**2020 * equation.constant
|
46
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
47
|
-
else
|
48
|
-
equation.constant.should > 0.0
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'fuels factors' do
|
55
|
-
it 'should produce reasonable fuels use estimates' do
|
56
|
-
LodgingFuelUseEquation.where(:fuel => 'Fuels').each do |equation|
|
57
|
-
if equation.property_rooms == true and equation.construction_year == true
|
58
|
-
estimate = equation.rooms_factor + equation.year_factor + equation.constant
|
59
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
60
|
-
|
61
|
-
estimate = equation.rooms_factor * 1000 + equation.year_factor + equation.constant
|
62
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
63
|
-
|
64
|
-
estimate = equation.rooms_factor + equation.year_factor * 2020 + equation.constant
|
65
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
66
|
-
|
67
|
-
estimate = equation.rooms_factor * 1000 + equation.year_factor * 2020 + equation.constant
|
68
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
69
|
-
elsif equation.property_rooms == true
|
70
|
-
estimate = equation.rooms_factor + equation.constant
|
71
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
72
|
-
|
73
|
-
estimate = equation.rooms_factor * 1000 + equation.constant
|
74
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
75
|
-
elsif equation.construction_year == true
|
76
|
-
estimate = equation.year_factor + equation.constant
|
77
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
78
|
-
|
79
|
-
estimate = equation.year_factor * 2020 + equation.constant
|
80
|
-
estimate.should > 0.0 and estimate.should < 1000.0
|
81
|
-
else
|
82
|
-
equation.constant.should > 0.0
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'find_by_criteria' do
|
89
|
-
it 'should return the proper equation' do
|
90
|
-
LodgingFuelUseEquation.find_by_criteria('Fuels', {}).name.should == 'Fuels'
|
91
|
-
LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2) }).name.should == 'Fuels zone 2'
|
92
|
-
LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2), :property_rooms => 25}).name.should == 'Fuels zone 2 rooms'
|
93
|
-
LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2), :property_rooms => 25, :property_construction_year => 1998}).name.should == 'Fuels zone 2 rooms year'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|