earth 0.6.6 → 0.7.0
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.rb +1 -1
- data/lib/earth/air/flight_distance_class/data_miner.rb +3 -2
- data/lib/earth/air/flight_seat_class/data_miner.rb +4 -29
- data/lib/earth/air/flight_segment.rb +4 -0
- data/lib/earth/automobile.rb +1 -0
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +3 -3
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -1
- data/lib/earth/locality.rb +3 -0
- data/lib/earth/locality/country.rb +32 -9
- data/lib/earth/locality/country/data_miner.rb +38 -2
- data/lib/earth/locality/country_rail_class.rb +18 -0
- data/lib/earth/locality/country_rail_class/data_miner.rb +16 -0
- data/lib/earth/locality/country_rail_traction.rb +13 -0
- data/lib/earth/locality/country_rail_traction/data_miner.rb +34 -0
- data/lib/earth/locality/country_rail_traction_class.rb +14 -0
- data/lib/earth/locality/country_rail_traction_class/data_miner.rb +35 -0
- data/lib/earth/locality/data_miner.rb +3 -0
- data/lib/earth/locality/zip_code.rb +9 -7
- data/lib/earth/rail.rb +8 -0
- data/lib/earth/rail/data_miner.rb +9 -0
- data/lib/earth/rail/national_transit_database_company.rb +37 -0
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +12 -0
- data/lib/earth/rail/national_transit_database_mode.rb +12 -0
- data/lib/earth/rail/national_transit_database_mode/data_miner.rb +10 -0
- data/lib/earth/rail/national_transit_database_record.rb +41 -0
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +57 -0
- data/lib/earth/rail/rail_class.rb +2 -63
- data/lib/earth/rail/rail_class/data_miner.rb +13 -12
- data/lib/earth/rail/rail_company.rb +26 -0
- data/lib/earth/rail/rail_company/data_miner.rb +98 -0
- data/lib/earth/rail/rail_company_traction.rb +12 -0
- data/lib/earth/rail/rail_company_traction/data_miner.rb +4 -0
- data/lib/earth/rail/rail_company_traction_class.rb +14 -0
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +4 -0
- data/lib/earth/rail/rail_fuel.rb +18 -0
- data/lib/earth/rail/rail_fuel/data_miner.rb +36 -0
- data/lib/earth/rail/rail_traction.rb +5 -0
- data/lib/earth/rail/rail_traction/data_miner.rb +21 -0
- data/lib/earth/version.rb +1 -1
- data/spec/earth_spec.rb +14 -2
- metadata +46 -30
data/earth.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.add_runtime_dependency 'fixed_width-multibyte'
|
37
37
|
s.add_runtime_dependency 'geokit-rails'
|
38
38
|
s.add_runtime_dependency 'loose_tight_dictionary', '>=0.2.3'
|
39
|
-
s.add_runtime_dependency 'weighted_average', '>=1.0.
|
39
|
+
s.add_runtime_dependency 'weighted_average', '>=1.0.2'
|
40
40
|
s.add_runtime_dependency 'mini_record-compat' # need https://github.com/DAddYE/mini_record/pull/7
|
41
41
|
s.add_runtime_dependency 'activesupport'
|
42
42
|
s.add_runtime_dependency 'activerecord'
|
@@ -2,7 +2,7 @@ class FlightDistanceClass < ActiveRecord::Base
|
|
2
2
|
set_primary_key :name
|
3
3
|
|
4
4
|
def self.find_by_distance(distance)
|
5
|
-
|
5
|
+
first :conditions => arel_table[:min_distance].lteq(distance).and(arel_table[:max_distance].gt(distance))
|
6
6
|
end
|
7
7
|
|
8
8
|
col :name
|
@@ -17,8 +17,9 @@ FlightDistanceClass.class_eval do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
process "Calculate passengers for each distance class" do
|
20
|
-
|
21
|
-
distance_class.passengers = FlightSegment.
|
20
|
+
find_each do |distance_class|
|
21
|
+
distance_class.passengers = FlightSegment.distances_between(distance_class.min_distance, distance_class.max_distance).sum(:passengers)
|
22
|
+
distance_class.save!
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -5,41 +5,16 @@ FlightSeatClass.class_eval do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
process "Derive flight seat classes names from FlightDistanceClassSeatClass" do
|
8
|
-
|
9
|
-
|
8
|
+
connection.select_values("SELECT DISTINCT seat_class_name FROM #{FlightDistanceClassSeatClass.quoted_table_name}").each do |seat_class_name|
|
9
|
+
find_or_create_by_name seat_class_name
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
process "Calculate multipliers from FlightDistanceClassSeatClass and FlightDistanceClass" do
|
14
|
-
|
15
|
-
seat_class.multiplier =
|
16
|
-
seat_class.distance_class_seat_classes.map do |dcsc|
|
17
|
-
dcsc.multiplier * dcsc.distance_class.passengers
|
18
|
-
end.sum / seat_class.distance_class_seat_classes.map(&:distance_class).map(&:passengers).sum
|
14
|
+
find_each do |seat_class|
|
15
|
+
seat_class.multiplier = seat_class.distance_class_seat_classes.weighted_average(:multiplier, :weighted_by => [:distance_class, :passengers])
|
19
16
|
seat_class.save!
|
20
17
|
end
|
21
18
|
end
|
22
|
-
|
23
|
-
# FIXME TODO verify this
|
24
|
-
|
25
|
-
# sabshere 5/21/10 in case we ever need this
|
26
|
-
# class << self
|
27
|
-
# def refresh
|
28
|
-
# update_all_weighted_averages(:seats, :weighted_by => :airline_aircraft_seat_classes)
|
29
|
-
# update_all_weighted_averages(:multiplier, :weighted_by => :airline_aircraft_seat_classes)
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# def safe_find_by_name(name)
|
33
|
-
# guess = case name.to_s.downcase.gsub(/[^a-z]/, '')
|
34
|
-
# when /first/
|
35
|
-
# 'first'
|
36
|
-
# when /busi/, /exec/
|
37
|
-
# 'business'
|
38
|
-
# when /econ/, /coach/
|
39
|
-
# 'economy'
|
40
|
-
# end
|
41
|
-
# find_or_create_by_name(guess) unless guess.nil?
|
42
|
-
# end
|
43
|
-
# end
|
44
19
|
end
|
45
20
|
end
|
@@ -60,6 +60,10 @@ class FlightSegment < ActiveRecord::Base
|
|
60
60
|
add_index :aircraft_description
|
61
61
|
add_index :year
|
62
62
|
|
63
|
+
def self.distances_between(floor, ceiling)
|
64
|
+
where arel_table[:distance].gteq(floor).and(arel_table[:distance].lt(ceiling))
|
65
|
+
end
|
66
|
+
|
63
67
|
def self.update_averages!
|
64
68
|
# Derive load factor, which is passengers divided by available seats
|
65
69
|
update_all 'load_factor = 1.0 * passengers / seats', 'seats > 0'
|
data/lib/earth/automobile.rb
CHANGED
@@ -32,7 +32,7 @@ AutomobileFuel.class_eval do
|
|
32
32
|
scope = record.type_fuel_year_ages.where(:year => record.type_fuel_year_ages.maximum('year'))
|
33
33
|
record.annual_distance = scope.weighted_average(:annual_distance, :weighted_by => :vehicles)
|
34
34
|
record.annual_distance_units = scope.first.annual_distance_units
|
35
|
-
record.save
|
35
|
+
record.save!
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -47,7 +47,7 @@ AutomobileFuel.class_eval do
|
|
47
47
|
end
|
48
48
|
record.co2_emission_factor_units = record.base_fuel.co2_emission_factor_units
|
49
49
|
record.co2_biogenic_emission_factor_units = record.base_fuel.co2_biogenic_emission_factor_units
|
50
|
-
record.save
|
50
|
+
record.save!
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -70,7 +70,7 @@ AutomobileFuel.class_eval do
|
|
70
70
|
end.sum / scope.sum('total_travel')
|
71
71
|
record.hfc_emission_factor_units = scope.first.type_year.hfc_emission_factor_units
|
72
72
|
|
73
|
-
record.save
|
73
|
+
record.save!
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
data/lib/earth/locality.rb
CHANGED
@@ -2,6 +2,9 @@ require 'earth/locality/census_division'
|
|
2
2
|
require 'earth/locality/census_region'
|
3
3
|
require 'earth/locality/climate_division'
|
4
4
|
require 'earth/locality/country'
|
5
|
+
require 'earth/locality/country_rail_traction'
|
6
|
+
require 'earth/locality/country_rail_class'
|
7
|
+
require 'earth/locality/country_rail_traction_class'
|
5
8
|
require 'earth/locality/egrid_region'
|
6
9
|
require 'earth/locality/egrid_subregion'
|
7
10
|
require 'earth/locality/petroleum_administration_for_defense_district'
|
@@ -1,17 +1,29 @@
|
|
1
1
|
class Country < ActiveRecord::Base
|
2
2
|
set_primary_key :iso_3166_code
|
3
3
|
|
4
|
+
has_many :rail_companies, :foreign_key => 'country_iso_3166_code'
|
5
|
+
|
4
6
|
falls_back_on :name => 'fallback',
|
5
|
-
:automobile_urbanity => lambda {
|
7
|
+
:automobile_urbanity => lambda { united_states.automobile_urbanity }, # for now assume US represents world
|
6
8
|
:automobile_fuel_efficiency => ((22.5 + 16.2) / 2.0).miles_per_gallon.to(:kilometres_per_litre), # average of passenger car fuel unknown and light goods vehicle fuel unknown - WRI Mobile Combustion calculation tool v2.0
|
7
9
|
:automobile_fuel_efficiency_units => 'kilometres_per_litre',
|
8
|
-
:automobile_city_speed => lambda {
|
9
|
-
:automobile_city_speed_units => lambda {
|
10
|
-
:automobile_highway_speed => lambda {
|
11
|
-
:automobile_highway_speed_units => lambda {
|
12
|
-
:automobile_trip_distance => lambda {
|
13
|
-
:automobile_trip_distance_units => lambda {
|
14
|
-
:flight_route_inefficiency_factor => lambda {
|
10
|
+
:automobile_city_speed => lambda { united_states.automobile_city_speed }, # for now assume US represents world
|
11
|
+
:automobile_city_speed_units => lambda { united_states.automobile_city_speed_units }, # for now assume US represents world
|
12
|
+
:automobile_highway_speed => lambda { united_states.automobile_highway_speed }, # for now assume US represents world
|
13
|
+
:automobile_highway_speed_units => lambda { united_states.automobile_highway_speed_units }, # for now assume US represents world
|
14
|
+
:automobile_trip_distance => lambda { united_states.automobile_trip_distance }, # for now assume US represents world
|
15
|
+
:automobile_trip_distance_units => lambda { united_states.automobile_trip_distance_units }, # for now assume US represents world
|
16
|
+
:flight_route_inefficiency_factor => lambda { maximum(:flight_route_inefficiency_factor) }, # default to the largest inefficiency factor
|
17
|
+
:rail_trip_distance => lambda { weighted_average(:rail_trip_distance, :weighted_by => :rail_passengers) },
|
18
|
+
:rail_trip_distance_units => 'kilometres', # FIXME TODO derive this
|
19
|
+
:rail_speed => lambda { weighted_average(:rail_speed, :weighted_by => :rail_passengers) },
|
20
|
+
:rail_speed_units => 'kilometres_per_hour', # FIXME TODO derive this
|
21
|
+
:rail_trip_electricity_intensity => lambda { weighted_average(:rail_trip_electricity_intensity, :weighted_by => :rail_passengers) },
|
22
|
+
:rail_trip_electricity_intensity_units => 'kilowatt_hour_per_passenger_kilometre', # FIXME TODO derive this
|
23
|
+
:rail_trip_diesel_intensity => lambda { weighted_average(:rail_trip_diesel_intensity, :weighted_by => :rail_passengers) },
|
24
|
+
:rail_trip_diesel_intensity_units => 'litres_per_passenger_kilometre', # FIXME TODO derive this
|
25
|
+
:rail_trip_co2_emission_factor => lambda { weighted_average(:rail_trip_co2_emission_factor, :weighted_by => :rail_passengers) },
|
26
|
+
:rail_trip_co2_emission_factor_units => 'kilograms' # FIXME TODO derive this
|
15
27
|
|
16
28
|
class << self
|
17
29
|
def united_states
|
@@ -31,4 +43,15 @@ class Country < ActiveRecord::Base
|
|
31
43
|
col :automobile_trip_distance, :type => :float
|
32
44
|
col :automobile_trip_distance_units
|
33
45
|
col :flight_route_inefficiency_factor, :type => :float
|
34
|
-
|
46
|
+
col :rail_passengers, :type => :float
|
47
|
+
col :rail_trip_distance, :type => :float
|
48
|
+
col :rail_trip_distance_units
|
49
|
+
col :rail_speed, :type => :float
|
50
|
+
col :rail_speed_units
|
51
|
+
col :rail_trip_electricity_intensity, :type => :float
|
52
|
+
col :rail_trip_electricity_intensity_units
|
53
|
+
col :rail_trip_diesel_intensity, :type => :float
|
54
|
+
col :rail_trip_diesel_intensity_units
|
55
|
+
col :rail_trip_co2_emission_factor, :type => :float
|
56
|
+
col :rail_trip_co2_emission_factor_units
|
57
|
+
end
|
@@ -16,8 +16,8 @@ Country.class_eval do
|
|
16
16
|
store 'flight_route_inefficiency_factor'
|
17
17
|
end
|
18
18
|
|
19
|
-
import "automobile
|
20
|
-
:url => 'https://spreadsheets.google.com/pub?
|
19
|
+
import "automobile-related data for the US",
|
20
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDdZRm1tNjY0c2dYNG00bXJ3TXRqUVE&gid=0&output=csv' do
|
21
21
|
key 'iso_3166_code'
|
22
22
|
store 'automobile_urbanity'
|
23
23
|
store 'automobile_city_speed', :units_field_name => 'automobile_city_speed_units'
|
@@ -73,6 +73,42 @@ Country.class_eval do
|
|
73
73
|
}
|
74
74
|
end
|
75
75
|
|
76
|
+
process "Ensure RailCompany is populated" do
|
77
|
+
RailCompany.run_data_miner!
|
78
|
+
end
|
79
|
+
|
80
|
+
process "Calculate rail passengers, trip distance, and speed from RailCompany" do
|
81
|
+
find_each do |country|
|
82
|
+
if country.rail_companies.any?
|
83
|
+
country.rail_passengers = country.rail_companies.sum(:passengers)
|
84
|
+
country.rail_trip_distance = country.rail_companies.weighted_average(:trip_distance, :weighted_by => :passengers)
|
85
|
+
country.rail_trip_distance_units = 'kilometres' if country.rail_trip_distance.present?
|
86
|
+
country.rail_speed = country.rail_companies.weighted_average(:speed, :weighted_by => :passengers)
|
87
|
+
country.rail_speed_units = 'kilometres_per_hour' if country.rail_speed.present?
|
88
|
+
country.save!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
import "european rail fuel and emission data derived from the UIC",
|
94
|
+
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDczWnlPN2VtX1RmU0EtOVBYRFo4REE&output=csv' do
|
95
|
+
key 'iso_3166_code'
|
96
|
+
store 'rail_trip_electricity_intensity', :units_field_name => 'rail_trip_electricity_intensity_units'
|
97
|
+
store 'rail_trip_diesel_intensity', :units_field_name => 'rail_trip_diesel_intensity_units'
|
98
|
+
store 'rail_trip_co2_emission_factor', :units_field_name => 'rail_trip_co2_emission_factor_units'
|
99
|
+
end
|
100
|
+
|
101
|
+
process "Derive US rail fuel and emission data from RailCompany" do
|
102
|
+
country = Country.united_states
|
103
|
+
country.rail_trip_electricity_intensity = country.rail_companies.weighted_average(:electricity_intensity, :weighted_by => :passengers)
|
104
|
+
country.rail_trip_electricity_intensity_units = 'kilowatt_hours_per_passenger_kilometre'
|
105
|
+
country.rail_trip_diesel_intensity = country.rail_companies.weighted_average(:diesel_intensity, :weighted_by => :passengers)
|
106
|
+
country.rail_trip_diesel_intensity_units = 'litres_per_passenger_kilometre'
|
107
|
+
country.rail_trip_co2_emission_factor = country.rail_companies.weighted_average(:co2_emission_factor, :weighted_by => :passengers)
|
108
|
+
country.rail_trip_co2_emission_factor_units = 'kilograms_per_passenger_kilometre'
|
109
|
+
country.save!
|
110
|
+
end
|
111
|
+
|
76
112
|
# FIXME TODO verify this
|
77
113
|
end
|
78
114
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CountryRailClass < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
col :name
|
5
|
+
col :country_iso_3166_code
|
6
|
+
col :rail_class_name
|
7
|
+
col :passengers, :type => :float
|
8
|
+
col :speed, :type => :float
|
9
|
+
col :speed_units
|
10
|
+
col :trip_distance, :type => :float
|
11
|
+
col :trip_distance_units
|
12
|
+
col :electricity_intensity, :type => :float
|
13
|
+
col :electricity_intensity_units
|
14
|
+
col :diesel_intensity, :type => :float
|
15
|
+
col :diesel_intensity_units
|
16
|
+
col :co2_emission_factor, :type => :float
|
17
|
+
col :co2_emission_factor_units
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
CountryRailClass.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "a list of country-specific rail classes and their pre-calculated characteristics",
|
4
|
+
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdFg3YVptS2FYdHBsb2kyZFRxSm5FdlE&output=csv' do
|
5
|
+
key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_class_name']].join(' ') }
|
6
|
+
store 'country_iso_3166_code'
|
7
|
+
store 'rail_class_name'
|
8
|
+
store 'passengers'
|
9
|
+
store 'speed', :units_field_name => 'speed_units'
|
10
|
+
store 'trip_distance', :units_field_name => 'trip_distance_units'
|
11
|
+
store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
|
12
|
+
store 'diesel_intensity', :units_field_name => 'diesel_intensity_units'
|
13
|
+
store 'co2_emission_factor', :units_field_name => 'co2_emission_factor_units'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CountryRailTraction < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
col :name
|
5
|
+
col :country_iso_3166_code
|
6
|
+
col :rail_traction_name
|
7
|
+
col :electricity_intensity, :type => :float
|
8
|
+
col :electricity_intensity_units
|
9
|
+
col :diesel_intensity, :type => :float
|
10
|
+
col :diesel_intensity_units
|
11
|
+
col :co2_emission_factor, :type => :float
|
12
|
+
col :co2_emission_factor_units
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
CountryRailTraction.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "european rail traction data from the UIC",
|
4
|
+
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHA1RmZ0SlN6ZkVOenRodGFBQ1N0Q2c&output=csv' do
|
5
|
+
key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_traction_name']].join(' ') }
|
6
|
+
store 'country_iso_3166_code'
|
7
|
+
store 'rail_traction_name'
|
8
|
+
store 'electricity_intensity', :nullify => :true, :units_field_name => 'electricity_intensity_units'
|
9
|
+
store 'diesel_intensity', :nullify => :true, :units_field_name => 'diesel_intensity_units'
|
10
|
+
store 'co2_emission_factor', :nullify => :true, :units_field_name => 'co2_emission_factor_units'
|
11
|
+
end
|
12
|
+
|
13
|
+
process "Ensure RailFuel is populated" do
|
14
|
+
RailFuel.run_data_miner!
|
15
|
+
end
|
16
|
+
|
17
|
+
process "Standardize diesel intensity units" do
|
18
|
+
CountryRailTraction.where(:diesel_intensity_units => 'grams_per_passenger_kilometre').find_each do |record|
|
19
|
+
diesel = RailFuel.find_by_name("diesel")
|
20
|
+
record.diesel_intensity = record.diesel_intensity.grams.to(:kilograms) / diesel.density
|
21
|
+
record.diesel_intensity_units = [diesel.density_units.split("_per_")[1].pluralize, record.diesel_intensity_units.split("_per_")[1]].join('_per_')
|
22
|
+
record.save!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
process "Standardize co2 emission factor units" do
|
27
|
+
CountryRailTraction.where(:co2_emission_factor_units => 'grams_per_passenger_kilometre').find_each do |record|
|
28
|
+
record.co2_emission_factor = record.co2_emission_factor.grams.to(:kilograms)
|
29
|
+
record.co2_emission_factor_units = ['kilograms', record.co2_emission_factor_units.split("_per_")[1]].join('_per_')
|
30
|
+
record.save!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CountryRailTractionClass < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
col :name
|
5
|
+
col :country_iso_3166_code
|
6
|
+
col :rail_traction_name
|
7
|
+
col :rail_class_name
|
8
|
+
col :electricity_intensity, :type => :float
|
9
|
+
col :electricity_intensity_units
|
10
|
+
col :diesel_intensity, :type => :float
|
11
|
+
col :diesel_intensity_units
|
12
|
+
col :co2_emission_factor, :type => :float
|
13
|
+
col :co2_emission_factor_units
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
CountryRailTractionClass.class_eval do
|
2
|
+
data_miner do
|
3
|
+
import "european rail traction class data from the UIC",
|
4
|
+
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdDBiV0VPdkg2UkNSV0pVdWNNcG9fMHc&output=csv' do
|
5
|
+
key 'name', :synthesize => lambda { |record| [record['country_iso_3166_code'], record['rail_traction_name'], record['rail_class_name']].join(' ') }
|
6
|
+
store 'country_iso_3166_code'
|
7
|
+
store 'rail_traction_name'
|
8
|
+
store 'rail_class_name'
|
9
|
+
store 'electricity_intensity', :nullify => true, :units_field_name => 'electricity_intensity_units'
|
10
|
+
store 'diesel_intensity', :nullify => true, :units_field_name => 'diesel_intensity_units'
|
11
|
+
store 'co2_emission_factor', :nullify => true, :units_field_name => 'co2_emission_factor_units'
|
12
|
+
end
|
13
|
+
|
14
|
+
process "Ensure RailFuel is populated" do
|
15
|
+
RailFuel.run_data_miner!
|
16
|
+
end
|
17
|
+
|
18
|
+
process "Standardize diesel intensity units" do
|
19
|
+
CountryRailTractionClass.where(:diesel_intensity_units => 'grams_per_passenger_kilometre').find_each do |record|
|
20
|
+
diesel = RailFuel.find_by_name("diesel")
|
21
|
+
record.diesel_intensity = record.diesel_intensity.grams.to(:kilograms) / diesel.density
|
22
|
+
record.diesel_intensity_units = [diesel.density_units.split("_per_")[1].pluralize, record.diesel_intensity_units.split("_per_")[1]].join('_per_')
|
23
|
+
record.save!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
process "Standardize co2 emission factor units" do
|
28
|
+
CountryRailTractionClass.where(:co2_emission_factor_units => 'grams_per_passenger_kilometre').find_each do |record|
|
29
|
+
record.co2_emission_factor = record.co2_emission_factor.grams.to(:kilograms)
|
30
|
+
record.co2_emission_factor_units = ['kilograms', record.co2_emission_factor_units.split("_per_")[1]].join('_per_')
|
31
|
+
record.save!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,6 +2,9 @@ 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/country_rail_traction/data_miner'
|
6
|
+
require 'earth/locality/country_rail_class/data_miner'
|
7
|
+
require 'earth/locality/country_rail_traction_class/data_miner'
|
5
8
|
require 'earth/locality/egrid_region/data_miner'
|
6
9
|
require 'earth/locality/egrid_subregion/data_miner'
|
7
10
|
require 'earth/locality/petroleum_administration_for_defense_district/data_miner'
|
@@ -1,16 +1,18 @@
|
|
1
1
|
class ZipCode < ActiveRecord::Base
|
2
2
|
set_primary_key :name
|
3
3
|
|
4
|
-
belongs_to :egrid_subregion,
|
4
|
+
belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
|
5
5
|
belongs_to :climate_division, :foreign_key => 'climate_division_name'
|
6
|
-
belongs_to :state,
|
7
|
-
# has_one :census_division, :through => :state
|
8
|
-
# has_one :census_region, :through => :state
|
6
|
+
belongs_to :state, :foreign_key => 'state_postal_abbreviation'
|
9
7
|
|
10
|
-
|
8
|
+
def country
|
9
|
+
Country.united_states
|
10
|
+
end
|
11
|
+
|
12
|
+
acts_as_mappable :default_units => :kilometres,
|
11
13
|
:lat_column_name => :latitude,
|
12
14
|
:lng_column_name => :longitude
|
13
|
-
|
15
|
+
|
14
16
|
col :name
|
15
17
|
col :state_postal_abbreviation
|
16
18
|
col :description
|
@@ -18,4 +20,4 @@ class ZipCode < ActiveRecord::Base
|
|
18
20
|
col :longitude
|
19
21
|
col :egrid_subregion_abbreviation
|
20
22
|
col :climate_division_name
|
21
|
-
end
|
23
|
+
end
|
data/lib/earth/rail.rb
CHANGED
@@ -1 +1,9 @@
|
|
1
|
+
require 'earth/rail/rail_company'
|
2
|
+
require 'earth/rail/rail_company_traction'
|
3
|
+
require 'earth/rail/rail_company_traction_class'
|
1
4
|
require 'earth/rail/rail_class'
|
5
|
+
require 'earth/rail/rail_fuel'
|
6
|
+
require 'earth/rail/rail_traction'
|
7
|
+
require 'earth/rail/national_transit_database_company'
|
8
|
+
require 'earth/rail/national_transit_database_mode'
|
9
|
+
require 'earth/rail/national_transit_database_record'
|