earth 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -21
- data/data/rail/ntd_companies.csv +1 -0
- data/data/rail/ntd_fuel_consumption.csv +1 -0
- data/data/rail/ntd_modes.csv +1 -0
- data/data/rail/ntd_service.csv +1 -0
- data/errata/flight_segment/bts_errata.csv +6 -0
- data/lib/earth.rb +1 -0
- data/lib/earth/air/aircraft.rb +3 -5
- data/lib/earth/air/airline.rb +2 -3
- data/lib/earth/air/airport.rb +4 -5
- data/lib/earth/air/bts_aircraft.rb +1 -1
- data/lib/earth/air/flight_distance_class.rb +0 -1
- data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
- data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
- data/lib/earth/air/flight_segment.rb +12 -13
- data/lib/earth/air/flight_segment/data_miner.rb +13 -0
- data/lib/earth/automobile/automobile_activity_year.rb +0 -1
- data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_make.rb +0 -1
- data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
- data/lib/earth/automobile/automobile_make_model.rb +1 -2
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
- data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
- data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
- data/lib/earth/automobile/automobile_model.rb +0 -1
- data/lib/earth/automobile/automobile_size_class.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
- data/lib/earth/automobile/automobile_year.rb +0 -1
- data/lib/earth/bus/bus_class.rb +0 -1
- data/lib/earth/bus/bus_fuel.rb +1 -72
- data/lib/earth/bus/bus_fuel_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
- data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
- data/lib/earth/computation/computation_carrier.rb +1 -11
- data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
- data/lib/earth/computation/computation_carrier_region.rb +0 -1
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
- data/lib/earth/diet/diet_class.rb +0 -1
- data/lib/earth/diet/food_group.rb +1 -1
- data/lib/earth/electricity/electric_market.rb +2 -0
- data/lib/earth/electricity/electric_utility.rb +11 -4
- data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
- data/lib/earth/electricity/green_button_adoption.rb +2 -1
- data/lib/earth/fuel/fuel.rb +20 -81
- data/lib/earth/fuel/fuel_year.rb +0 -44
- data/lib/earth/fuel/greenhouse_gas.rb +0 -40
- data/lib/earth/hospitality/lodging_class.rb +0 -1
- data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
- data/lib/earth/industry/industry.rb +1 -2
- data/lib/earth/industry/mecs_energy.rb +9 -10
- data/lib/earth/industry/mecs_ratio.rb +2 -1
- data/lib/earth/industry/merchant_category.rb +1 -0
- data/lib/earth/industry/naics_2002.rb +2 -0
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
- data/lib/earth/industry/naics_2007.rb +1 -0
- data/lib/earth/industry/sic_1987.rb +1 -0
- data/lib/earth/locality/census_division.rb +1 -3
- data/lib/earth/locality/climate_division.rb +0 -1
- data/lib/earth/locality/country.rb +1 -2
- data/lib/earth/locality/country/data_miner.rb +4 -0
- data/lib/earth/locality/egrid_country.rb +0 -1
- data/lib/earth/locality/egrid_region.rb +1 -3
- data/lib/earth/locality/egrid_subregion.rb +1 -3
- data/lib/earth/locality/electricity_mix.rb +2 -4
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
- data/lib/earth/locality/state.rb +0 -1
- data/lib/earth/locality/zip_code.rb +0 -1
- data/lib/earth/model.rb +1 -1
- data/lib/earth/pet/breed.rb +0 -1
- data/lib/earth/pet/breed_gender.rb +0 -1
- data/lib/earth/pet/gender.rb +0 -1
- data/lib/earth/pet/species.rb +1 -3
- data/lib/earth/rail/country_rail_class.rb +0 -1
- data/lib/earth/rail/country_rail_traction.rb +0 -1
- data/lib/earth/rail/country_rail_traction_class.rb +0 -1
- data/lib/earth/rail/national_transit_database_company.rb +1 -3
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_mode.rb +0 -1
- data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_record.rb +0 -1
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
- data/lib/earth/rail/rail_class.rb +0 -1
- data/lib/earth/rail/rail_class/data_miner.rb +5 -4
- data/lib/earth/rail/rail_company.rb +0 -1
- data/lib/earth/rail/rail_fuel.rb +0 -1
- data/lib/earth/rail/rail_traction.rb +0 -1
- data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
- data/lib/earth/residence/air_conditioner_use.rb +0 -1
- data/lib/earth/residence/clothes_machine_use.rb +0 -1
- data/lib/earth/residence/dishwasher_use.rb +0 -1
- data/lib/earth/residence/residence_appliance.rb +0 -1
- data/lib/earth/residence/residence_class.rb +0 -1
- data/lib/earth/residence/residence_fuel_price.rb +1 -2
- data/lib/earth/residence/urbanity.rb +0 -1
- data/lib/earth/shipping/carrier.rb +1 -52
- data/lib/earth/shipping/carrier_mode.rb +0 -34
- data/lib/earth/shipping/shipment_mode.rb +0 -26
- data/lib/earth/tasks.rb +14 -4
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/aircraft_spec.rb +9 -1
- data/spec/earth/air/airline_spec.rb +2 -2
- data/spec/earth/air/airport_spec.rb +1 -2
- data/spec/earth/air/bts_aircraft_spec.rb +2 -2
- data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
- data/spec/earth/air/flight_distance_class_spec.rb +26 -18
- data/spec/earth/air/flight_seat_class_spec.rb +12 -0
- data/spec/earth/air/flight_segment_spec.rb +38 -33
- data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
- data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
- data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
- data/spec/earth/automobile/automobile_make_spec.rb +8 -8
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
- data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
- data/spec/earth/automobile/automobile_model_spec.rb +3 -0
- data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
- data/spec/earth/automobile/automobile_year_spec.rb +4 -2
- data/spec/earth/bus/bus_class_spec.rb +10 -0
- data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
- data/spec/earth/bus/bus_fuel_spec.rb +16 -8
- data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
- data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
- data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
- data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
- data/spec/earth/diet/diet_class_spec.rb +14 -0
- data/spec/earth/diet/food_group_spec.rb +26 -0
- data/spec/earth/electricity/electric_market_spec.rb +4 -5
- data/spec/earth/electricity/electric_utility_spec.rb +30 -19
- data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
- data/spec/earth/fuel/fuel_spec.rb +88 -14
- data/spec/earth/fuel/fuel_year_spec.rb +21 -0
- data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
- data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
- data/spec/earth/industry/industry_spec.rb +16 -9
- data/spec/earth/industry/mecs_energy_spec.rb +76 -72
- data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
- data/spec/earth/industry/merchant_category_spec.rb +7 -5
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
- data/spec/earth/industry/naics_2002_spec.rb +1 -11
- data/spec/earth/industry/naics_2007_spec.rb +2 -11
- data/spec/earth/industry/sic_1987_spec.rb +3 -14
- data/spec/earth/locality/census_division_spec.rb +25 -0
- data/spec/earth/locality/census_region_spec.rb +8 -0
- data/spec/earth/locality/climate_division_spec.rb +13 -0
- data/spec/earth/locality/country_spec.rb +24 -23
- data/spec/earth/locality/egrid_country_spec.rb +7 -6
- data/spec/earth/locality/egrid_region_spec.rb +6 -6
- data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
- data/spec/earth/locality/electricity_mix_spec.rb +17 -17
- data/spec/earth/locality/padd_spec.rb +21 -0
- data/spec/earth/locality/state_spec.rb +8 -11
- data/spec/earth/locality/zip_code_spec.rb +29 -22
- data/spec/earth/pet/breed_gender_spec.rb +8 -0
- data/spec/earth/pet/breed_spec.rb +8 -0
- data/spec/earth/pet/gender_spec.rb +8 -0
- data/spec/earth/pet/species_spec.rb +11 -5
- data/spec/earth/rail/country_rail_class_spec.rb +16 -0
- data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
- data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
- data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
- data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
- data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
- data/spec/earth/rail/rail_class_spec.rb +8 -0
- data/spec/earth/rail/rail_company_spec.rb +20 -0
- data/spec/earth/rail/rail_fuel_spec.rb +19 -0
- data/spec/earth/rail/rail_traction_spec.rb +8 -0
- data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
- data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
- data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
- data/spec/earth/residence/residence_appliance_spec.rb +19 -0
- data/spec/earth/residence/residence_class_spec.rb +15 -0
- data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
- data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
- data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
- data/spec/earth/residence/urbanity_spec.rb +8 -0
- data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
- data/spec/earth/shipping/carrier_spec.rb +27 -0
- data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
- data/spec/earth_spec.rb +1 -1
- data/spec/factories/airline.rb +0 -1
- data/spec/factories/airport.rb +0 -1
- data/spec/factories/automobile_activity_year.rb +8 -0
- data/spec/factories/automobile_activity_year_type.rb +8 -0
- data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
- data/spec/factories/automobile_fuel.rb +15 -0
- data/spec/factories/automobile_make.rb +9 -0
- data/spec/factories/automobile_make_model.rb +10 -0
- data/spec/factories/automobile_make_model_year.rb +9 -0
- data/spec/factories/automobile_model.rb +9 -0
- data/spec/factories/automobile_type_fuel.rb +7 -0
- data/spec/factories/automobile_type_fuel_control.rb +16 -0
- data/spec/factories/automobile_type_fuel_year.rb +9 -0
- data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
- data/spec/factories/bus_fuel.rb +7 -0
- data/spec/factories/bus_fuel_year_control.rb +9 -0
- data/spec/factories/cbecs_energy_intensity.rb +15 -0
- data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
- data/spec/factories/electric_utility.rb +8 -0
- data/spec/factories/flight_distance_class.rb +8 -0
- data/spec/factories/flight_segment.rb +0 -1
- data/spec/factories/food_group.rb +8 -0
- data/spec/factories/fuel.rb +8 -0
- data/spec/factories/fuel_year.rb +8 -0
- data/spec/factories/green_button_adoption.rb +8 -0
- data/spec/factories/greenhouse_gas.rb +7 -0
- data/spec/factories/industry.rb +9 -0
- data/spec/factories/mecs_energy.rb +15 -0
- data/spec/factories/mecs_ratio.rb +15 -0
- data/spec/factories/national_transit_database_company.rb +8 -0
- data/spec/factories/national_transit_database_mode.rb +8 -0
- data/spec/factories/national_transit_database_record.rb +9 -0
- data/spec/factories/residence_appliance.rb +7 -0
- data/spec/factories/zip_code.rb +9 -0
- data/spec/spec_helper.rb +36 -19
- metadata +346 -66
- data/lib/earth/acronyms.rb +0 -12
- data/lib/earth/rail/rail_company_traction.rb +0 -24
- data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
- data/lib/earth/rail/rail_company_traction_class.rb +0 -26
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
@@ -30,7 +30,6 @@ EOS
|
|
30
30
|
has_many :industry_sectors, :foreign_key => 'naics_code'
|
31
31
|
has_many :sectors, :through => :industry_sectors
|
32
32
|
|
33
|
-
|
34
33
|
class << self
|
35
34
|
def format_naics_code(input)
|
36
35
|
"%d" % input.to_i
|
@@ -39,7 +38,7 @@ EOS
|
|
39
38
|
|
40
39
|
def trade_industry?
|
41
40
|
prefix = naics_code.to_s[0,2]
|
42
|
-
%w{42 44 45}.include?
|
41
|
+
%w{42 44 45}.include? prefix
|
43
42
|
end
|
44
43
|
|
45
44
|
warn_unless_size 2341
|
@@ -36,20 +36,19 @@ EOS
|
|
36
36
|
|
37
37
|
self.primary_key = "name"
|
38
38
|
|
39
|
-
|
40
39
|
FUELS = [:electricity, :residual_fuel_oil, :distillate_fuel_oil,
|
41
40
|
:natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other_fuel]
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
# Find the first record whose naics_code matches code and that has valid fuel ratios.
|
43
|
+
# If no record found chop off the last character of code and try again, and so on.
|
44
|
+
def self.find_by_naics_code(code)
|
45
|
+
find_by_naics_code_and_census_region_number(code, nil)
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
# Find the first record whose census_region_number matches number, whose naics_code matches code, and that has valid fuel ratios.
|
49
|
+
# If none found and we know census region number, try looking nationwide
|
50
|
+
# If none found and looking nationwide, chop off the last character of code and try again looking in census region
|
51
|
+
# And so on
|
53
52
|
def self.find_by_naics_code_and_census_region_number(code, number, original_number = number)
|
54
53
|
if code.blank?
|
55
54
|
record = nil
|
@@ -22,7 +22,6 @@ EOS
|
|
22
22
|
|
23
23
|
belongs_to :industry
|
24
24
|
|
25
|
-
|
26
25
|
# Find the first record whose naics_code matches code and whose energy per dollar shipment is present.
|
27
26
|
# If no record found chop off the last character of code and try again, and so on.
|
28
27
|
def self.find_by_naics_code(code)
|
@@ -50,4 +49,6 @@ EOS
|
|
50
49
|
end
|
51
50
|
record
|
52
51
|
end
|
52
|
+
|
53
|
+
warn_unless_size 395
|
53
54
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
require 'earth/locality/census_region'
|
6
5
|
require 'earth/locality/climate_division'
|
@@ -46,6 +45,5 @@ EOS
|
|
46
45
|
:meeting_building_electricity_intensity => 0.0084323684 / 1.square_feet.to(:square_metres),
|
47
46
|
:meeting_building_district_heat_intensity => 0.0004776370.kbtus.to(:megajoules) / 1.square_feet.to(:square_metres)
|
48
47
|
|
49
|
-
|
50
48
|
warn_unless_size 9
|
51
49
|
end
|
@@ -23,6 +23,10 @@ Country.class_eval do
|
|
23
23
|
store 'name', :field_number => 5 # romanized version with utf-8 characters
|
24
24
|
end
|
25
25
|
|
26
|
+
process "Add Kosovo using the FIPS code 'KV'" do
|
27
|
+
Country.find_or_create_by_iso_3166_code_and_name 'KV', 'Kosovo'
|
28
|
+
end
|
29
|
+
|
26
30
|
import "heating and cooling degree day data from WRI CAIT",
|
27
31
|
:url => "file://#{Earth::DATA_DIR}/locality/wri_hdd_cdd_data.csv",
|
28
32
|
:select => proc { |record| record['country'] != 'European Union (27)' },
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
require 'earth/locality/egrid_country'
|
6
5
|
require 'earth/locality/egrid_subregion'
|
@@ -35,7 +34,6 @@ EOS
|
|
35
34
|
falls_back_on :name => 'fallback',
|
36
35
|
:loss_factor => lambda { EgridCountry.us.loss_factor }
|
37
36
|
|
38
|
-
|
39
37
|
warn_unless_size 5
|
40
38
|
warn_if_any_nulls
|
41
39
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
require 'earth/locality/egrid_region'
|
6
5
|
require 'earth/locality/electricity_mix'
|
@@ -50,7 +49,6 @@ EOS
|
|
50
49
|
:electricity_emission_factor => lambda { weighted_average(:electricity_emission_factor, :weighted_by => :net_generation) },
|
51
50
|
:electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour'
|
52
51
|
|
53
|
-
|
54
52
|
warn_unless_size 26
|
55
53
|
warn_if_any_nulls
|
56
54
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
class ElectricityMix < ActiveRecord::Base
|
6
5
|
extend Earth::Model
|
@@ -45,7 +44,6 @@ EOS
|
|
45
44
|
:n2o_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour',
|
46
45
|
:loss_factor => 0.096 # from ecometrica paper FIXME TODO calculate this
|
47
46
|
|
48
|
-
|
49
|
-
warn_unless_size 187
|
47
|
+
warn_unless_size 213
|
50
48
|
warn_if_any_nulls
|
51
49
|
end
|
data/lib/earth/locality/state.rb
CHANGED
data/lib/earth/model.rb
CHANGED
@@ -23,7 +23,7 @@ module Earth
|
|
23
23
|
require path if File.exist?(path + '.rb')
|
24
24
|
target.data_miner_script.prepend_once :process, :create_table!
|
25
25
|
else
|
26
|
-
target.data_miner_script.prepend_once :sql, "Brighter Planet's reference data", "http://data.brighterplanet.com/#{to_s.underscore.pluralize}.sql"
|
26
|
+
target.data_miner_script.prepend_once :sql, "Brighter Planet's reference data", "http://data.brighterplanet.com/#{target.to_s.underscore.pluralize}.sql"
|
27
27
|
end
|
28
28
|
target.data_miner_script.append_once :process, :run_data_miner_on_parent_associations!
|
29
29
|
end
|
data/lib/earth/pet/breed.rb
CHANGED
data/lib/earth/pet/gender.rb
CHANGED
data/lib/earth/pet/species.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
require 'earth/pet/breed'
|
6
5
|
|
@@ -31,7 +30,6 @@ EOS
|
|
31
30
|
|
32
31
|
self.primary_key = "name"
|
33
32
|
|
34
|
-
|
35
33
|
has_many :breeds, :foreign_key => 'species_name'
|
36
34
|
|
37
35
|
scope :thoroughly_researched, :conditions => 'marginal_dietary_requirement IS NOT NULL'
|
@@ -35,8 +35,7 @@ EOS
|
|
35
35
|
# Methods to calculate summary statistics from rail_records
|
36
36
|
[:rail_passengers, :rail_passenger_distance, :rail_vehicle_distance, :rail_vehicle_time, :rail_electricity, :rail_diesel].each do |method|
|
37
37
|
define_method method do
|
38
|
-
|
39
|
-
rail_records.sum(attribute) > 0 ? rail_records.sum(attribute) : nil
|
38
|
+
(sum = rail_records.sum(method.to_s.split('rail_')[1].to_sym)) > 0 ? sum : nil
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -50,7 +49,6 @@ EOS
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
|
54
52
|
warn_if_nulls_except(
|
55
53
|
:acronym,
|
56
54
|
:duns_number
|
@@ -1,7 +1,7 @@
|
|
1
1
|
NationalTransitDatabaseCompany.class_eval do
|
2
2
|
data_miner do
|
3
3
|
import "US transit companies from the National Transit Database",
|
4
|
-
:url =>
|
4
|
+
:url => "#{Earth::DATA_DIR}/rail/ntd_companies.csv" do
|
5
5
|
key 'id', :field_name => 'trs_id'
|
6
6
|
store 'name', :nullify => true
|
7
7
|
store 'acronym', :nullify => true
|
@@ -1,7 +1,7 @@
|
|
1
1
|
NationalTransitDatabaseMode.class_eval do
|
2
2
|
data_miner do
|
3
3
|
import "National Transit Database modes",
|
4
|
-
:url =>
|
4
|
+
:url => "#{Earth::DATA_DIR}/rail/ntd_modes.csv" do
|
5
5
|
key 'code'
|
6
6
|
store 'name', :nullify => true
|
7
7
|
store 'rail_mode', :nullify => true
|
@@ -1,7 +1,7 @@
|
|
1
1
|
NationalTransitDatabaseRecord.class_eval do
|
2
2
|
data_miner do
|
3
3
|
import "US National Transit Database service data",
|
4
|
-
:url =>
|
4
|
+
:url => "#{Earth::DATA_DIR}/rail/ntd_service.csv" do
|
5
5
|
key 'name', :synthesize => proc { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
|
6
6
|
store 'company_id', :field_name => 'trs_id'
|
7
7
|
store 'mode_code'
|
@@ -13,7 +13,7 @@ NationalTransitDatabaseRecord.class_eval do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
import "US National Transit Database fuel consumption data",
|
16
|
-
:url =>
|
16
|
+
:url => "#{Earth::DATA_DIR}/rail/ntd_fuel_consumption.csv" do
|
17
17
|
key 'name', :synthesize => proc { |row| [row['trs_id'], row['mode_code'], row['service_code']].join(' ') }
|
18
18
|
store 'company_id', :field_name => 'trs_id'
|
19
19
|
store 'mode_code'
|
@@ -1,16 +1,17 @@
|
|
1
|
+
require 'earth/rail/country_rail_class'
|
2
|
+
require 'earth/rail/country_rail_traction_class'
|
3
|
+
|
1
4
|
RailClass.class_eval do
|
2
5
|
data_miner do
|
3
|
-
process "Ensure CountryRailClass,
|
6
|
+
process "Ensure CountryRailClass, and CountryRailTractionClass are populated" do
|
4
7
|
CountryRailTractionClass.run_data_miner!
|
5
8
|
CountryRailClass.run_data_miner!
|
6
|
-
RailCompanyTractionClass.run_data_miner!
|
7
9
|
end
|
8
10
|
|
9
|
-
process "Derive rail class names from CountryRailClass
|
11
|
+
process "Derive rail class names from CountryRailClass and CountryRailTractionClass" do
|
10
12
|
names = []
|
11
13
|
names += CountryRailTractionClass.select("DISTINCT rail_class_name").map(&:rail_class_name)
|
12
14
|
names += CountryRailClass.select("DISTINCT rail_class_name").map(&:rail_class_name)
|
13
|
-
names += RailCompanyTractionClass.select("DISTINCT rail_class_name").map(&:rail_class_name)
|
14
15
|
names.uniq.each do |name|
|
15
16
|
RailClass.find_or_create_by_name(name)
|
16
17
|
end
|
data/lib/earth/rail/rail_fuel.rb
CHANGED