earth 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/earth_tester.rb +1 -0
- data/earth.gemspec +1 -1
- data/lib/earth.rb +1 -1
- data/lib/earth/air/flight_segment/data_miner.rb +5 -9
- data/lib/earth/automobile/automobile_size_class_year.rb +1 -0
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +1 -0
- data/lib/earth/data_miner.rb +1 -0
- data/lib/earth/fuel/fuel_type.rb +1 -0
- data/lib/earth/fuel/fuel_type/data_miner.rb +1 -0
- data/lib/earth/hospitality.rb +2 -0
- data/lib/earth/hospitality/census_region_lodging_class.rb +16 -0
- data/lib/earth/hospitality/census_region_lodging_class/data_miner.rb +40 -0
- data/lib/earth/hospitality/country_lodging_class.rb +16 -0
- data/lib/earth/hospitality/country_lodging_class/data_miner.rb +40 -0
- data/lib/earth/hospitality/data_miner.rb +2 -0
- data/lib/earth/hospitality/lodging_class.rb +3 -1
- data/lib/earth/hospitality/lodging_class/data_miner.rb +6 -5
- data/lib/earth/industry/data_miner.rb +1 -0
- data/lib/earth/industry/industry.rb +1 -1
- data/lib/earth/industry/industry/data_miner.rb +12 -0
- data/lib/earth/industry/merchant_category.rb +1 -1
- data/lib/earth/locality.rb +5 -7
- data/lib/earth/locality/census_division/data_miner.rb +7 -6
- data/lib/earth/locality/country.rb +25 -2
- data/lib/earth/locality/country/data_miner.rb +74 -23
- data/lib/earth/locality/data_miner.rb +5 -7
- data/lib/earth/locality/egrid_country.rb +17 -0
- data/lib/earth/locality/egrid_country/data_miner.rb +13 -0
- data/lib/earth/locality/egrid_region.rb +2 -14
- data/lib/earth/locality/egrid_region/data_miner.rb +15 -14
- data/lib/earth/locality/egrid_subregion.rb +3 -64
- data/lib/earth/locality/egrid_subregion/data_miner.rb +39 -25
- data/lib/earth/locality/zip_code/data_miner.rb +1 -0
- data/lib/earth/rail.rb +6 -0
- data/lib/earth/{locality → rail}/country_rail_class.rb +0 -0
- data/lib/earth/{locality → rail}/country_rail_class/data_miner.rb +0 -0
- data/lib/earth/{locality → rail}/country_rail_traction.rb +0 -0
- data/lib/earth/{locality → rail}/country_rail_traction/data_miner.rb +0 -0
- data/lib/earth/{locality → rail}/country_rail_traction_class.rb +0 -0
- data/lib/earth/{locality → rail}/country_rail_traction_class/data_miner.rb +0 -0
- data/lib/earth/rail/data_miner.rb +6 -0
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +1 -0
- data/lib/earth/rail/rail_company/data_miner.rb +6 -5
- data/lib/earth/residence.rb +1 -2
- data/lib/earth/residence/data_miner.rb +1 -2
- data/lib/earth/residence/residence_fuel_type.rb +5 -2
- data/lib/earth/{locality → residence}/urbanity.rb +0 -0
- data/lib/earth/{locality → residence}/urbanity/data_miner.rb +0 -0
- data/lib/earth/version.rb +1 -1
- data/spec/earth_spec.rb +6 -6
- metadata +216 -209
@@ -2,16 +2,14 @@ require 'earth/locality/census_division/data_miner'
|
|
2
2
|
require 'earth/locality/census_region/data_miner'
|
3
3
|
require 'earth/locality/climate_division/data_miner'
|
4
4
|
require 'earth/locality/country/data_miner'
|
5
|
-
require 'earth/locality/
|
6
|
-
require 'earth/locality/country_rail_class/data_miner'
|
7
|
-
require 'earth/locality/country_rail_traction_class/data_miner'
|
5
|
+
require 'earth/locality/egrid_country/data_miner'
|
8
6
|
require 'earth/locality/egrid_region/data_miner'
|
9
7
|
require 'earth/locality/egrid_subregion/data_miner'
|
10
8
|
require 'earth/locality/petroleum_administration_for_defense_district/data_miner'
|
11
9
|
require 'earth/locality/state/data_miner'
|
12
|
-
require 'earth/locality/urbanity/data_miner'
|
13
10
|
require 'earth/locality/zip_code/data_miner'
|
14
11
|
|
15
|
-
require 'earth/automobile/data_miner'
|
16
|
-
require 'earth/
|
17
|
-
require 'earth/
|
12
|
+
require 'earth/automobile/data_miner' # for automobile data on Country
|
13
|
+
require 'earth/fuel/data_miner' # for GWPs for EgridSubregion
|
14
|
+
require 'earth/hospitality/data_miner' # for lodging data on Country
|
15
|
+
require 'earth/rail/data_miner' # for rail data on Country
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class EgridCountry < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def us
|
6
|
+
find_by_name 'US'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
col :name
|
11
|
+
col :generation, :type => :float
|
12
|
+
col :generation_units
|
13
|
+
col :imports, :type => :float
|
14
|
+
col :imports_units
|
15
|
+
col :consumption, :type => :float
|
16
|
+
col :consumption_units
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
EgridCountry.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "the US average grid loss factor derived eGRID 2007 data",
|
4
|
+
:url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2010V1_1_STIE_USGC.xls',
|
5
|
+
:sheet => 'USGC',
|
6
|
+
:skip => 5 do
|
7
|
+
key 'name', :static => 'US'
|
8
|
+
store 'generation', :field_name => 'USTNGN07', :units => :gigawatt_hours
|
9
|
+
store 'imports', :field_name => 'USTNFI07', :units => :gigawatt_hours
|
10
|
+
store 'consumption', :field_name => 'USTCON07', :units => :gigawatt_hours
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -3,21 +3,9 @@ class EgridRegion < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
has_many :egrid_subregions, :foreign_key => 'egrid_region_name'
|
5
5
|
|
6
|
-
# FIXME TODO someday should calculate this from eGRID data: (USTNGN05 + USTNFI05 - USTCON05) / USTNGN05
|
7
6
|
falls_back_on :name => 'fallback',
|
8
|
-
:loss_factor =>
|
7
|
+
:loss_factor => lambda { (EgridCountry.us.generation + EgridCountry.us.imports - EgridCountry.us.consumption) / EgridCountry.us.generation }
|
9
8
|
|
10
9
|
col :name
|
11
10
|
col :loss_factor, :type => :float
|
12
|
-
|
13
|
-
# verify "Loss factor should be greater than zero and less than one" do
|
14
|
-
# EgridRegion.all.each do |region|
|
15
|
-
# unless region.loss_factor > 0 and region.loss_factor < 1
|
16
|
-
# raise "Invalid loss factor for EgridRegion #{region.name}: #{region.loss_factor} (should be > 0 and < 1)"
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
|
21
|
-
# FIXME TODO verify fallback loss factor
|
22
|
-
|
23
|
-
end
|
11
|
+
end
|
@@ -1,23 +1,24 @@
|
|
1
1
|
EgridRegion.class_eval do
|
2
2
|
data_miner do
|
3
|
-
import "eGRID regions and loss factors
|
4
|
-
:url => 'http://www.epa.gov/cleanenergy/documents/egridzips/
|
5
|
-
:
|
6
|
-
:sheet => 'STIE05',
|
3
|
+
import "eGRID 2010 regions and loss factors",
|
4
|
+
:url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2010V1_1_STIE_USGC.xls',
|
5
|
+
:sheet => 'STIE07',
|
7
6
|
:skip => 4,
|
8
|
-
:select => lambda { |row| row['
|
7
|
+
:select => lambda { |row| row['eGRID2010 year 2007 file state sequence number'].to_i.between?(1, 51) } do
|
9
8
|
key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
|
10
|
-
store 'loss_factor', :field_name => '
|
9
|
+
store 'loss_factor', :field_name => 'Year 2007 grid gross loss factor'
|
11
10
|
end
|
12
11
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
# Need this for fallback loss_factor calculation
|
13
|
+
process "Ensure EgridCountry is populated" do
|
14
|
+
EgridCountry.run_data_miner!
|
15
|
+
end
|
16
|
+
|
17
|
+
# DEPRECATED but don't remove until confirmed that all emitters use EgridRegion.fallback rather than EgridRegion.find_by_abbreviation 'US'
|
18
|
+
process "Calculate national averages" do
|
19
|
+
us_average = find_or_create_by_name 'US'
|
20
|
+
us_average.loss_factor = (EgridCountry.us.generation + EgridCountry.us.imports - EgridCountry.us.consumption) / EgridCountry.us.generation
|
21
|
+
us_average.save!
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -4,14 +4,8 @@ class EgridSubregion < ActiveRecord::Base
|
|
4
4
|
has_many :zip_codes, :foreign_key => 'egrid_subregion_abbreviation'
|
5
5
|
belongs_to :egrid_region, :foreign_key => 'egrid_region_name'
|
6
6
|
|
7
|
-
class << self
|
8
|
-
def fallback_egrid_region
|
9
|
-
EgridRegion.fallback
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
falls_back_on :name => 'fallback',
|
14
|
-
:egrid_region => lambda {
|
8
|
+
:egrid_region => lambda { EgridRegion.fallback },
|
15
9
|
:electricity_co2_emission_factor => lambda { weighted_average(:electricity_co2_emission_factor, :weighted_by => :net_generation) },
|
16
10
|
:electricity_co2_emission_factor_units => 'kilograms_per_kilowatt_hour',
|
17
11
|
:electricity_co2_biogenic_emission_factor => lambda { weighted_average(:electricity_co2_biogenic_emission_factor, :weighted_by => :net_generation) },
|
@@ -20,8 +14,8 @@ class EgridSubregion < ActiveRecord::Base
|
|
20
14
|
:electricity_ch4_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour',
|
21
15
|
:electricity_n2o_emission_factor => lambda { weighted_average(:electricity_n2o_emission_factor, :weighted_by => :net_generation) },
|
22
16
|
:electricity_n2o_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour',
|
23
|
-
:electricity_emission_factor => lambda { weighted_average(:electricity_emission_factor, :weighted_by => :net_generation) },
|
24
|
-
:electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour'
|
17
|
+
:electricity_emission_factor => lambda { weighted_average(:electricity_emission_factor, :weighted_by => :net_generation) },
|
18
|
+
:electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour'
|
25
19
|
|
26
20
|
col :abbreviation
|
27
21
|
col :name
|
@@ -39,59 +33,4 @@ class EgridSubregion < ActiveRecord::Base
|
|
39
33
|
col :electricity_n2o_emission_factor_units
|
40
34
|
col :electricity_emission_factor, :type => :float
|
41
35
|
col :electricity_emission_factor_units
|
42
|
-
|
43
|
-
# FIXME TODO verify egrid_region_name is found in EgridRegions
|
44
|
-
# %w{ egrid_region_name }.each do |attribute|
|
45
|
-
# verify "#{attribute.humanize} should never be missing" do
|
46
|
-
# EgridSubregion.all.each do |subregion|
|
47
|
-
# unless subregion.send("#{attribute}").present?
|
48
|
-
# raise "Missing #{attribute.humanize.downcase} for EgridSubregion #{subregion.name}"
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
# end
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# ["net_generation",
|
55
|
-
# "electricity_co2_emission_factor",
|
56
|
-
# "electricity_ch4_emission_factor",
|
57
|
-
# "electricity_n2o_emission_factor",
|
58
|
-
# "electricity_emission_factor" ].each do |attribute|
|
59
|
-
# verify "#{attribute.humanize} should be > 0" do
|
60
|
-
# EgridSubregion.all.each do |subregion|
|
61
|
-
# value = subregion.send(:"#{attribute}")
|
62
|
-
# unless value > 0
|
63
|
-
# raise "Invalid #{attribute.humanize.downcase} for EgridSubregion #{subregion.name}: #{value} (should be > 0)"
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# verify "Electricity co2 biogenic emission factor should be 0" do
|
70
|
-
# EgridSubregion.all.each do |subregion|
|
71
|
-
# value = subregion.electricity_co2_biogenic_emission_factor
|
72
|
-
# unless value == 0
|
73
|
-
# raise "Invalid electricity co2 biogenic emission factor for EgridSubregion #{subregion.name}: #{value} (should be 0)"
|
74
|
-
# end
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# [["net_generation_units","megawatt_hours"],
|
79
|
-
# ["electricity_co2_emission_factor_units","kilograms_per_kilowatt_hour"],
|
80
|
-
# ["electricity_co2_biogenic_emission_factor_units","kilograms_per_kilowatt_hour"],
|
81
|
-
# ["electricity_ch4_emission_factor_units","kilograms_co2e_per_kilowatt_hour"],
|
82
|
-
# ["electricity_n2o_emission_factor_units","kilograms_co2e_per_kilowatt_hour"],
|
83
|
-
# ["electricity_emission_factor_units","kilograms_co2e_per_kilowatt_hour"]].each do |pair|
|
84
|
-
# attribute = pair[0]
|
85
|
-
# proper_units = pair[1]
|
86
|
-
# verify "#{attribute.humanize} should be #{proper_units.humanize.downcase}" do
|
87
|
-
# EgridSubregion.all.each do |subregion|
|
88
|
-
# units = subregion.send(:"#{attribute}")
|
89
|
-
# unless units == proper_units
|
90
|
-
# raise "Invalid #{attribute.humanize.downcase} for EgridSubregion #{subregion.name}: #{units} (should be #{proper_units})"
|
91
|
-
# end
|
92
|
-
# end
|
93
|
-
# end
|
94
|
-
# end
|
95
|
-
|
96
|
-
# FIXME TODO verify fallbacks
|
97
36
|
end
|
@@ -1,33 +1,47 @@
|
|
1
1
|
EgridSubregion.class_eval do
|
2
2
|
data_miner do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# end
|
3
|
+
import "eGRID 2010 subregions and electricity emission factors",
|
4
|
+
:url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2010_Version1-1_xls_only.zip',
|
5
|
+
:filename => 'eGRID2010V1_1_year07_AGGREGATION.xls',
|
6
|
+
:sheet => 'SRL07',
|
7
|
+
:skip => 4,
|
8
|
+
:select => lambda { |row| row['SEQSRL07'].to_i.between?(1, 26) } do
|
9
|
+
key 'abbreviation', :field_name => 'SUBRGN'
|
10
|
+
store 'name', :field_name => 'SRNAME'
|
11
|
+
store 'nerc_abbreviation', :field_name => 'NERC'
|
12
|
+
store 'net_generation', :field_name => 'SRNGENAN', :units => :megawatt_hours
|
13
|
+
store 'electricity_co2_emission_factor', :field_name => 'SRCO2RTA', :units => :pounds_per_megawatt_hour
|
14
|
+
store 'electricity_co2_biogenic_emission_factor', :static => '0.0', :units => :kilograms_per_kilowatt_hour
|
15
|
+
store 'electricity_ch4_emission_factor', :field_name => 'SRCH4RTA', :units => :pounds_per_gigawatt_hour
|
16
|
+
store 'electricity_n2o_emission_factor', :field_name => 'SRN2ORTA', :units => :pounds_per_gigawatt_hour
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# FIXME TODO once 'US' subregion is no longer needed remove it from this source file
|
20
|
+
import "eGRID subregion to region associations",
|
21
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRORTJNSWRMQ1puRVprYlAtZHhDaFE&output=csv' do
|
22
22
|
key 'abbreviation'
|
23
|
-
store 'name'
|
24
|
-
store 'nerc_abbreviation'
|
25
23
|
store 'egrid_region_name'
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
# DEPRECATED but don't remove until confirmed that all emitters use EgridSubregion.fallback rather than EgridSubregion.find_by_abbreviation 'US'
|
27
|
+
process "Calculate national averages" do
|
28
|
+
us_average = find_by_abbreviation 'US'
|
29
|
+
subregions = where("abbreviation != 'US'")
|
30
|
+
|
31
|
+
us_average.name = 'United States'
|
32
|
+
us_average.nerc_abbreviation = 'US'
|
33
|
+
us_average.egrid_region_name = 'US'
|
34
|
+
us_average.net_generation = subregions.sum(:net_generation)
|
35
|
+
us_average.electricity_co2_emission_factor = subregions.weighted_average(:electricity_co2_emission_factor, :weighted_by => :net_generation)
|
36
|
+
us_average.electricity_co2_biogenic_emission_factor = subregions.weighted_average(:electricity_co2_biogenic_emission_factor, :weighted_by => :net_generation)
|
37
|
+
us_average.electricity_ch4_emission_factor = subregions.weighted_average(:electricity_ch4_emission_factor, :weighted_by => :net_generation)
|
38
|
+
us_average.electricity_n2o_emission_factor = subregions.weighted_average(:electricity_n2o_emission_factor, :weighted_by => :net_generation)
|
39
|
+
us_average.net_generation_units = 'megawatt_hours'
|
40
|
+
us_average.electricity_co2_emission_factor_units = 'pounds_per_megawatt_hour'
|
41
|
+
us_average.electricity_co2_biogenic_emission_factor_units = 'kilograms_per_kilowatt_hour'
|
42
|
+
us_average.electricity_ch4_emission_factor_units = 'pounds_per_gigawatt_hour'
|
43
|
+
us_average.electricity_n2o_emission_factor_units = 'pounds_per_gigawatt_hour'
|
44
|
+
us_average.save!
|
31
45
|
end
|
32
46
|
|
33
47
|
process "Convert co2 emission factor to metric units" do
|
data/lib/earth/rail.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'earth/rail/country_rail_traction'
|
2
|
+
require 'earth/rail/country_rail_class'
|
3
|
+
require 'earth/rail/country_rail_traction_class'
|
1
4
|
require 'earth/rail/rail_company'
|
2
5
|
require 'earth/rail/rail_company_traction'
|
3
6
|
require 'earth/rail/rail_company_traction_class'
|
@@ -7,3 +10,6 @@ require 'earth/rail/rail_traction'
|
|
7
10
|
require 'earth/rail/national_transit_database_company'
|
8
11
|
require 'earth/rail/national_transit_database_mode'
|
9
12
|
require 'earth/rail/national_transit_database_record'
|
13
|
+
|
14
|
+
require 'earth/fuel'
|
15
|
+
require 'earth/locality' # eGRID needed for US electricity emission factor in RailCompany import
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'earth/rail/country_rail_traction/data_miner'
|
2
|
+
require 'earth/rail/country_rail_class/data_miner'
|
3
|
+
require 'earth/rail/country_rail_traction_class/data_miner'
|
1
4
|
require 'earth/rail/rail_class/data_miner'
|
2
5
|
require 'earth/rail/rail_company/data_miner'
|
3
6
|
require 'earth/rail/rail_company_traction/data_miner'
|
@@ -8,3 +11,6 @@ require 'earth/rail/rail_traction/data_miner'
|
|
8
11
|
require 'earth/rail/national_transit_database_company/data_miner'
|
9
12
|
require 'earth/rail/national_transit_database_mode/data_miner'
|
10
13
|
require 'earth/rail/national_transit_database_record/data_miner'
|
14
|
+
|
15
|
+
require 'earth/fuel/data_miner'
|
16
|
+
require 'earth/locality/data_miner' # eGRID needed for US electricity emission factor in RailCompany import
|
@@ -12,6 +12,7 @@ NationalTransitDatabaseRecord.class_eval do
|
|
12
12
|
store 'passengers'
|
13
13
|
end
|
14
14
|
|
15
|
+
# FIXME TODO electricity synthesization should return NULL rather than 0
|
15
16
|
import "US National Transit Database fuel consumption data",
|
16
17
|
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDItVVR5NjA2Y3FCVjgza25Ccy0zS2c&output=csv' do
|
17
18
|
key 'name', :synthesize => lambda { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
|
@@ -29,7 +29,7 @@ RailCompany.class_eval do
|
|
29
29
|
|
30
30
|
process "Derive US transit rail company data from the National Transit Database" do
|
31
31
|
NationalTransitDatabaseCompany.rail_companies.each do |ntd_company|
|
32
|
-
company =
|
32
|
+
company = find_or_create_by_name(ntd_company.name)
|
33
33
|
company.country_iso_3166_code = 'US'
|
34
34
|
company.duns_number = ntd_company.duns_number
|
35
35
|
company.passengers = ntd_company.rail_passengers
|
@@ -55,7 +55,7 @@ RailCompany.class_eval do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
process "Calculate average trip distance" do
|
58
|
-
|
58
|
+
find_each do |company|
|
59
59
|
if company.passenger_distance.present? and company.passengers.present? and company.passengers > 0
|
60
60
|
company.trip_distance = company.passenger_distance / company.passengers
|
61
61
|
company.trip_distance_units = company.passenger_distance_units
|
@@ -65,7 +65,7 @@ RailCompany.class_eval do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
process "Calculate average trip speed" do
|
68
|
-
|
68
|
+
find_each do |company|
|
69
69
|
if company.train_distance.present? and company.train_time.present? and company.train_time > 0
|
70
70
|
company.speed = company.train_distance / company.train_time
|
71
71
|
company.speed_units = "#{company.train_distance_units}_per_#{company.train_time_units.singularize}"
|
@@ -74,12 +74,13 @@ RailCompany.class_eval do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
process "Ensure RailFuel
|
77
|
+
process "Ensure RailFuel and EgridSubregion are populated" do
|
78
78
|
RailFuel.run_data_miner!
|
79
|
+
EgridSubregion.run_data_miner!
|
79
80
|
end
|
80
81
|
|
81
82
|
process "Calculate co2 emission factor for US rail companies" do
|
82
|
-
|
83
|
+
where(:country_iso_3166_code => 'US').find_each do |company|
|
83
84
|
company.co2_emission_factor = 0
|
84
85
|
|
85
86
|
if company.diesel_intensity.present?
|
data/lib/earth/residence.rb
CHANGED
@@ -6,5 +6,4 @@ require 'earth/residence/residence_class'
|
|
6
6
|
require 'earth/residence/residence_fuel_price'
|
7
7
|
require 'earth/residence/residence_fuel_type'
|
8
8
|
require 'earth/residence/residential_energy_consumption_survey_response'
|
9
|
-
|
10
|
-
require 'earth/locality'
|
9
|
+
require 'earth/residence/urbanity'
|
@@ -6,5 +6,4 @@ require 'earth/residence/residence_class/data_miner'
|
|
6
6
|
require 'earth/residence/residence_fuel_price/data_miner'
|
7
7
|
require 'earth/residence/residence_fuel_type/data_miner'
|
8
8
|
require 'earth/residence/residential_energy_consumption_survey_response/data_miner'
|
9
|
-
|
10
|
-
require 'earth/locality/data_miner'
|
9
|
+
require 'earth/residence/urbanity/data_miner'
|
@@ -12,7 +12,7 @@ class ResidenceFuelType < ActiveRecord::Base
|
|
12
12
|
def price_per_unit(relaxations = [])
|
13
13
|
conditions = { :residence_fuel_type_name => self }
|
14
14
|
relaxations.push Hash.new
|
15
|
-
relaxations.
|
15
|
+
relaxations.each do |relaxation|
|
16
16
|
relaxation_conditions = Hash.new
|
17
17
|
if timeframe = relaxation[:timeframe]
|
18
18
|
relaxation_conditions[:year] = timeframe.from.year
|
@@ -22,8 +22,11 @@ class ResidenceFuelType < ActiveRecord::Base
|
|
22
22
|
relaxation_conditions[:locatable_type] = location.class.to_s
|
23
23
|
relaxation_conditions[:locatable_id] = location.id
|
24
24
|
end
|
25
|
-
ResidenceFuelPrice.average
|
25
|
+
if non_nil_result = ResidenceFuelPrice.average(:price, :conditions => conditions.merge(relaxation_conditions))
|
26
|
+
return non_nil_result
|
27
|
+
end
|
26
28
|
end
|
29
|
+
nil
|
27
30
|
end
|
28
31
|
|
29
32
|
class << self
|
File without changes
|
File without changes
|
data/lib/earth/version.rb
CHANGED
data/spec/earth_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Earth do
|
|
23
23
|
describe '.resource_map' do
|
24
24
|
it 'should get a list of resource_map' do
|
25
25
|
resource_map = Earth.resource_map
|
26
|
-
resource_map.keys.count.should ==
|
26
|
+
resource_map.keys.count.should == 91
|
27
27
|
resource_map['FuelType'].should == 'fuel'
|
28
28
|
end
|
29
29
|
it 'should exclude data_miner files' do
|
@@ -33,7 +33,7 @@ describe Earth do
|
|
33
33
|
|
34
34
|
describe '.search' do
|
35
35
|
it 'should get a list of all resource names' do
|
36
|
-
Earth.search.length.should ==
|
36
|
+
Earth.search.length.should == 91
|
37
37
|
Earth.search.should include('Aircraft')
|
38
38
|
Earth.search.should include('Industry')
|
39
39
|
end
|
@@ -44,12 +44,12 @@ describe Earth do
|
|
44
44
|
Earth.search('computation').length.should == 3
|
45
45
|
Earth.search('diet').length.should == 2
|
46
46
|
Earth.search('fuel').length.should == 5
|
47
|
-
Earth.search('hospitality').length.should ==
|
47
|
+
Earth.search('hospitality').length.should == 3
|
48
48
|
Earth.search('industry').length.should == 10
|
49
|
-
Earth.search('locality').length.should ==
|
49
|
+
Earth.search('locality').length.should == 10
|
50
50
|
Earth.search('pet').length.should == 4
|
51
|
-
Earth.search('rail').length.should ==
|
52
|
-
Earth.search('residence').length.should ==
|
51
|
+
Earth.search('rail').length.should == 12
|
52
|
+
Earth.search('residence').length.should == 9
|
53
53
|
Earth.search('shipping').length.should == 3
|
54
54
|
Earth.search('fuel').should include('FuelType')
|
55
55
|
end
|