earth 0.12.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +0 -5
- data/README.markdown +32 -19
- data/Rakefile +4 -0
- data/bin/earth_tester.rb +66 -54
- data/earth.gemspec +6 -3
- data/lib/earth.rb +67 -114
- data/lib/earth/air.rb +1 -1
- data/lib/earth/air/aircraft.rb +37 -21
- data/lib/earth/air/aircraft/data_miner.rb +0 -4
- data/lib/earth/air/airline.rb +19 -5
- data/lib/earth/air/airline/data_miner.rb +0 -4
- data/lib/earth/air/airport.rb +23 -9
- data/lib/earth/air/airport/data_miner.rb +1 -5
- data/lib/earth/air/bts_aircraft.rb +14 -2
- data/lib/earth/air/flight_distance_class.rb +19 -7
- data/lib/earth/air/flight_distance_class_seat_class.rb +21 -4
- data/lib/earth/air/flight_seat_class.rb +13 -1
- data/lib/earth/air/flight_seat_class/data_miner.rb +2 -0
- data/lib/earth/air/flight_segment.rb +64 -59
- data/lib/earth/air/flight_segment/data_miner.rb +4 -5
- data/lib/earth/all.rb +1 -1
- data/lib/earth/automobile.rb +1 -1
- data/lib/earth/automobile/automobile_activity_year.rb +17 -3
- data/lib/earth/automobile/automobile_activity_year/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_activity_year_type.rb +21 -7
- data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +20 -8
- data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_fuel.rb +37 -23
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +3 -5
- data/lib/earth/automobile/automobile_make.rb +17 -3
- data/lib/earth/automobile/automobile_make/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_make_model.rb +29 -14
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +2 -5
- data/lib/earth/automobile/automobile_make_model_year.rb +31 -18
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +3 -4
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +43 -31
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_make_year.rb +18 -7
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +4 -4
- data/lib/earth/automobile/automobile_make_year_fleet.rb +19 -7
- data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_model.rb +13 -1
- data/lib/earth/automobile/automobile_model/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_size_class.rb +24 -10
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_type_fuel.rb +26 -12
- data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_type_fuel_control.rb +20 -8
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +25 -11
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +21 -7
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_year.rb +13 -1
- data/lib/earth/automobile/automobile_year/data_miner.rb +2 -0
- data/lib/earth/bus.rb +1 -1
- data/lib/earth/bus/bus_class.rb +38 -25
- data/lib/earth/bus/bus_class/data_miner.rb +0 -1
- data/lib/earth/bus/bus_fuel.rb +27 -13
- data/lib/earth/bus/bus_fuel/data_miner.rb +5 -1
- data/lib/earth/bus/bus_fuel_control.rb +19 -7
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -1
- data/lib/earth/bus/bus_fuel_year_control.rb +20 -7
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +2 -1
- data/lib/earth/computation.rb +1 -1
- data/lib/earth/computation/computation_carrier.rb +16 -3
- data/lib/earth/computation/computation_carrier/data_miner.rb +0 -1
- data/lib/earth/computation/computation_carrier_instance_class.rb +21 -6
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -1
- data/lib/earth/computation/computation_carrier_region.rb +18 -5
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -1
- data/lib/earth/diet.rb +1 -1
- data/lib/earth/diet/diet_class.rb +25 -13
- data/lib/earth/diet/food_group.rb +18 -7
- data/lib/earth/electricity.rb +1 -1
- data/lib/earth/electricity/electric_market.rb +17 -5
- data/lib/earth/electricity/electric_market/data_miner.rb +0 -2
- data/lib/earth/electricity/electric_utility.rb +22 -7
- data/lib/earth/electricity/electric_utility/data_miner.rb +1 -1
- data/lib/earth/electricity/green_button_adoption.rb +15 -3
- data/lib/earth/fuel.rb +1 -1
- data/lib/earth/fuel/fuel.rb +32 -19
- data/lib/earth/fuel/fuel/data_miner.rb +2 -4
- data/lib/earth/fuel/fuel_price.rb +17 -3
- data/lib/earth/fuel/fuel_type.rb +23 -12
- data/lib/earth/fuel/fuel_year.rb +27 -13
- data/lib/earth/fuel/greenhouse_gas.rb +18 -6
- data/lib/earth/hospitality.rb +1 -1
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +68 -56
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +0 -4
- data/lib/earth/hospitality/lodging_class.rb +13 -1
- data/lib/earth/industry.rb +1 -1
- data/lib/earth/industry/cbecs_energy_intensity.rb +43 -32
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +0 -1
- data/lib/earth/industry/industry.rb +20 -2
- data/lib/earth/industry/industry/data_miner.rb +0 -4
- data/lib/earth/industry/industry_product.rb +20 -6
- data/lib/earth/industry/industry_product_line.rb +19 -5
- data/lib/earth/industry/industry_sector.rb +19 -6
- data/lib/earth/industry/mecs_energy.rb +34 -22
- data/lib/earth/industry/mecs_ratio.rb +17 -6
- data/lib/earth/industry/mecs_ratio/data_miner.rb +1 -1
- data/lib/earth/industry/merchant_category.rb +17 -2
- data/lib/earth/industry/merchant_category/data_miner.rb +0 -4
- data/lib/earth/industry/merchant_category_industry.rb +19 -4
- data/lib/earth/industry/naics_2002.rb +20 -3
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +19 -4
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +19 -4
- data/lib/earth/industry/naics_2007.rb +17 -2
- data/lib/earth/industry/product_line.rb +20 -5
- data/lib/earth/industry/product_line_industry_product.rb +19 -5
- data/lib/earth/industry/sector.rb +18 -5
- data/lib/earth/industry/sic_1987.rb +17 -2
- data/lib/earth/loader.rb +47 -0
- data/lib/earth/locality.rb +1 -1
- data/lib/earth/locality/census_division.rb +32 -13
- data/lib/earth/locality/census_division/data_miner.rb +0 -1
- data/lib/earth/locality/census_region.rb +18 -5
- data/lib/earth/locality/climate_division.rb +21 -6
- data/lib/earth/locality/country.rb +68 -56
- data/lib/earth/locality/country/data_miner.rb +8 -8
- data/lib/earth/locality/egrid_country.rb +22 -10
- data/lib/earth/locality/egrid_region.rb +25 -10
- data/lib/earth/locality/egrid_region/data_miner.rb +0 -4
- data/lib/earth/locality/egrid_subregion.rb +31 -16
- data/lib/earth/locality/egrid_subregion/data_miner.rb +7 -6
- data/lib/earth/locality/electricity_mix.rb +27 -13
- data/lib/earth/locality/electricity_mix/data_miner.rb +8 -8
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +17 -5
- data/lib/earth/locality/state.rb +36 -16
- data/lib/earth/locality/state/data_miner.rb +0 -4
- data/lib/earth/locality/zip_code.rb +34 -15
- data/lib/earth/locality/zip_code/data_miner.rb +0 -4
- data/lib/earth/model.rb +90 -0
- data/lib/earth/pet.rb +1 -1
- data/lib/earth/pet/breed.rb +19 -4
- data/lib/earth/pet/breed_gender.rb +20 -5
- data/lib/earth/pet/gender.rb +15 -1
- data/lib/earth/pet/species.rb +30 -14
- data/lib/earth/rail.rb +1 -1
- data/lib/earth/rail/country_rail_class.rb +26 -15
- data/lib/earth/rail/country_rail_class/data_miner.rb +0 -1
- data/lib/earth/rail/country_rail_traction.rb +21 -11
- data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -2
- data/lib/earth/rail/country_rail_traction_class.rb +22 -12
- data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -2
- data/lib/earth/rail/national_transit_database_company.rb +20 -6
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +0 -1
- data/lib/earth/rail/national_transit_database_mode.rb +15 -3
- data/lib/earth/rail/national_transit_database_record.rb +45 -31
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +0 -1
- data/lib/earth/rail/rail_class.rb +13 -1
- data/lib/earth/rail/rail_company.rb +34 -22
- data/lib/earth/rail/rail_company/data_miner.rb +7 -2
- data/lib/earth/rail/rail_company_traction.rb +21 -10
- data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -1
- data/lib/earth/rail/rail_company_traction_class.rb +22 -11
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -1
- data/lib/earth/rail/rail_fuel.rb +20 -7
- data/lib/earth/rail/rail_fuel/data_miner.rb +3 -1
- data/lib/earth/rail/rail_traction.rb +13 -1
- data/lib/earth/rail/rail_traction/data_miner.rb +5 -0
- data/lib/earth/residence.rb +1 -1
- data/lib/earth/residence/air_conditioner_use.rb +19 -3
- data/lib/earth/residence/clothes_machine_use.rb +17 -3
- data/lib/earth/residence/dishwasher_use.rb +17 -3
- data/lib/earth/residence/residence_appliance.rb +15 -3
- data/lib/earth/residence/residence_appliance/data_miner.rb +2 -0
- data/lib/earth/residence/residence_class.rb +15 -1
- data/lib/earth/residence/residence_fuel_price.rb +25 -12
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -1
- data/lib/earth/residence/residence_fuel_type.rb +17 -6
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +110 -91
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -1
- data/lib/earth/residence/urbanity.rb +15 -1
- data/lib/earth/shipping.rb +1 -1
- data/lib/earth/shipping/carrier.rb +24 -8
- data/lib/earth/shipping/carrier_mode.rb +22 -7
- data/lib/earth/shipping/shipment_mode.rb +18 -4
- data/lib/earth/tasks.rb +62 -0
- data/lib/earth/version.rb +1 -1
- data/lib/earth/warnings.rb +12 -0
- data/spec/data_mining_spec.rb +31 -0
- data/spec/earth/air/aircraft_spec.rb +0 -10
- data/spec/earth/air/airline_spec.rb +1 -11
- data/spec/earth/air/airport_spec.rb +0 -10
- data/spec/earth/air/bts_aircraft_spec.rb +0 -10
- data/spec/earth/air/flight_distance_class_spec.rb +0 -10
- data/spec/earth/air/flight_segment_spec.rb +27 -10
- data/spec/earth/automobile/automobile_activity_year_spec.rb +0 -7
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +0 -7
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +0 -7
- data/spec/earth/automobile/automobile_fuel_spec.rb +0 -10
- data/spec/earth/automobile/automobile_make_model_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_spec.rb +0 -11
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +0 -11
- data/spec/earth/automobile/automobile_make_year_spec.rb +0 -8
- data/spec/earth/automobile/automobile_model_spec.rb +0 -10
- data/spec/earth/automobile/automobile_size_class_spec.rb +0 -10
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +0 -7
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +0 -10
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +0 -7
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +1 -8
- data/spec/earth/automobile/automobile_year_spec.rb +2 -11
- data/spec/earth/bus/bus_fuel_control_spec.rb +0 -10
- data/spec/earth/bus/bus_fuel_spec.rb +0 -10
- data/spec/earth/bus/bus_fuel_year_control_spec.rb +0 -10
- data/spec/earth/electricity/electric_market_spec.rb +0 -10
- data/spec/earth/electricity/electric_utility_spec.rb +0 -10
- data/spec/earth/electricity/green_button_adoption_spec.rb +0 -10
- data/spec/earth/fuel/fuel_spec.rb +1 -10
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +0 -10
- data/spec/earth/hospitality/lodging_class_spec.rb +0 -10
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +3 -11
- data/spec/earth/industry/industry_spec.rb +0 -10
- data/spec/earth/industry/mecs_energy_spec.rb +0 -9
- data/spec/earth/industry/mecs_ratio_spec.rb +0 -9
- data/spec/earth/industry/merchant_category_spec.rb +2 -7
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +1 -12
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +3 -13
- data/spec/earth/industry/naics_2002_spec.rb +0 -10
- data/spec/earth/industry/naics_2007_spec.rb +0 -10
- data/spec/earth/industry/sic_1987_spec.rb +0 -10
- data/spec/earth/locality/country_spec.rb +0 -10
- data/spec/earth/locality/egrid_country_spec.rb +0 -11
- data/spec/earth/locality/egrid_region_spec.rb +0 -10
- data/spec/earth/locality/egrid_subregion_spec.rb +0 -10
- data/spec/earth/locality/electricity_mix_spec.rb +0 -10
- data/spec/earth/locality/state_spec.rb +0 -10
- data/spec/earth/locality/zip_code_spec.rb +7 -15
- data/spec/earth/model_spec.rb +27 -0
- data/spec/earth/pet/species_spec.rb +1 -1
- data/spec/earth_spec.rb +1 -30
- data/spec/factories/airline.rb +10 -0
- data/spec/factories/airport.rb +12 -0
- data/spec/factories/flight_segment.rb +38 -0
- data/spec/spec_helper.rb +27 -36
- metadata +249 -223
- data/lib/earth/active_record_base_class_methods.rb +0 -25
- data/lib/earth/air/data_miner.rb +0 -3
- data/lib/earth/automobile/data_miner.rb +0 -3
- data/lib/earth/bus/data_miner.rb +0 -3
- data/lib/earth/computation/data_miner.rb +0 -3
- data/lib/earth/data_miner.rb +0 -3
- data/lib/earth/diet/data_miner.rb +0 -3
- data/lib/earth/fuel/data_miner.rb +0 -3
- data/lib/earth/hospitality/data_miner.rb +0 -3
- data/lib/earth/industry/data_miner.rb +0 -3
- data/lib/earth/locality/data_miner.rb +0 -3
- data/lib/earth/pet/data_miner.rb +0 -3
- data/lib/earth/rail/data_miner.rb +0 -3
- data/lib/earth/residence/data_miner.rb +0 -3
- data/lib/earth/shipping/data_miner.rb +0 -3
@@ -2,25 +2,15 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/industry/naics_2002_sic_1987_concordance'
|
3
3
|
|
4
4
|
describe Naics2002Sic1987Concordance do
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
5
|
+
describe 'verify imported data', :sanity => true do
|
6
|
+
it 'should have all the data' do
|
7
|
+
Naics2002Sic1987Concordance.count.should == 2164
|
8
8
|
end
|
9
9
|
|
10
10
|
it "extracts a paranthetical note from a description" do
|
11
11
|
Naics2002Sic1987Concordance.extract_note("Wood Household Furniture, Except Upholstered (wood box spring frames(parts))").
|
12
12
|
should == "wood box spring frames(parts)"
|
13
13
|
end
|
14
|
-
|
15
|
-
it "imports all naics codes" do
|
16
|
-
Naics2002Sic1987Concordance.run_data_miner!
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'verify imported data', :sanity => true do
|
21
|
-
it 'should have all the data' do
|
22
|
-
Naics2002Sic1987Concordance.count.should == 2164
|
23
|
-
end
|
24
14
|
end
|
25
15
|
|
26
16
|
describe "relationships" do
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/industry/naics_2002'
|
3
3
|
|
4
4
|
describe Naics2002 do
|
5
|
-
describe "when importing data", :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :industry, :load_data_miner => true, :skip_parent_associations => :true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "imports all naics codes" do
|
11
|
-
Naics2002.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe "verify imported data", :sanity => true do
|
16
6
|
it "should have all the data" do
|
17
7
|
Naics2002.count.should == 2341
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/industry/naics_2007'
|
3
3
|
|
4
4
|
describe Naics2007 do
|
5
|
-
describe "when importing data", :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :industry, :load_data_miner => true, :skip_parent_associations => :true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "imports all naics codes" do
|
11
|
-
Naics2007.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
it 'should have all the data' do
|
17
7
|
Naics2007.count.should == 2328
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/industry/sic_1987'
|
3
3
|
|
4
4
|
describe Sic1987 do
|
5
|
-
describe "when importing data", :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :industry, :load_data_miner => true, :skip_parent_associations => :true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "imports all naics codes" do
|
11
|
-
Sic1987.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe "verify imported data", :sanity => true do
|
16
6
|
it "should have all the data" do
|
17
7
|
Sic1987.count.should == 1004
|
@@ -4,16 +4,6 @@ require 'spec_helper'
|
|
4
4
|
require 'earth/locality/country'
|
5
5
|
|
6
6
|
describe Country do
|
7
|
-
describe 'import', :data_miner => true do
|
8
|
-
before do
|
9
|
-
Earth.init :locality, :load_data_miner => true
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should import data' do
|
13
|
-
Country.run_data_miner!
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
describe 'verify imported data', :sanity => true do
|
18
8
|
let(:us) { Country.united_states }
|
19
9
|
let(:uk) { Country.find 'GB' }
|
@@ -2,17 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/egrid_country'
|
3
3
|
|
4
4
|
describe EgridCountry do
|
5
|
-
describe 'import', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should import data' do
|
11
|
-
EgridCountry.delete_all if EgridCountry.table_exists?
|
12
|
-
EgridCountry.run_data_miner!
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
5
|
describe 'verify imported data', :sanity => true do
|
17
6
|
it { EgridCountry.count.should == 1 }
|
18
7
|
it { EgridCountry.us.loss_factor.should be_within(5e-6).of(0.06503) }
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/egrid_region'
|
3
3
|
|
4
4
|
describe EgridRegion do
|
5
|
-
describe 'import', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should import data' do
|
11
|
-
EgridRegion.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
it { EgridRegion.count.should == 5 }
|
17
7
|
it { EgridRegion.where("loss_factor > 0").count.should == EgridRegion.count }
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/egrid_subregion'
|
3
3
|
|
4
4
|
describe EgridSubregion do
|
5
|
-
describe 'import', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should import data' do
|
11
|
-
EgridSubregion.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
let(:total) { EgridSubregion.count }
|
17
7
|
let(:akgd) { EgridSubregion.find 'akgd' }
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/electricity_mix'
|
3
3
|
|
4
4
|
describe ElectricityMix do
|
5
|
-
describe 'import', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should import data' do
|
11
|
-
ElectricityMix.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
let(:total) { ElectricityMix.count }
|
17
7
|
let(:uk) { ElectricityMix.find_by_country_iso_3166_code 'GB' }
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/state'
|
3
3
|
|
4
4
|
describe State do
|
5
|
-
describe 'when importing data', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'imports data' do
|
11
|
-
State.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
it 'should have all the data' do
|
17
7
|
State.count.should == 51 # includes DC but not any territories
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'earth/locality/zip_code'
|
3
3
|
|
4
4
|
describe ZipCode do
|
5
|
-
describe 'when importing data', :data_miner => true do
|
6
|
-
before do
|
7
|
-
Earth.init :locality, :load_data_miner => true, :skip_parent_associations => :true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'imports data' do
|
11
|
-
ZipCode.run_data_miner!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
describe 'verify imported data', :sanity => true do
|
16
6
|
it { ZipCode.count.should == 43770 }
|
17
7
|
it { ZipCode.where(:state_postal_abbreviation => nil).count.should == 0 }
|
@@ -35,16 +25,18 @@ describe ZipCode do
|
|
35
25
|
require 'earth/locality/country'
|
36
26
|
end
|
37
27
|
|
38
|
-
it '
|
39
|
-
ZipCode.
|
40
|
-
ZipCode.last.country.should == Country.united_states
|
28
|
+
it 'returns the US' do
|
29
|
+
ZipCode.new.country.should == Country.united_states
|
41
30
|
end
|
42
31
|
end
|
43
32
|
|
44
33
|
describe '#latitude_longitude' do
|
34
|
+
it 'returns an array of nils for missing lat/lon' do
|
35
|
+
ZipCode.new.latitude_longitude.should == [nil, nil]
|
36
|
+
end
|
45
37
|
it 'should return the lat and lng as an array of strings' do
|
46
|
-
ZipCode.
|
47
|
-
|
38
|
+
zip = ZipCode.new :latitude => '43.005895', :longitude => '-71.013202'
|
39
|
+
zip.latitude_longitude.should == ['43.005895', '-71.013202']
|
48
40
|
end
|
49
41
|
end
|
50
42
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'earth/model'
|
3
|
+
|
4
|
+
class FooBaloo < ActiveRecord::Base
|
5
|
+
extend Earth::Model
|
6
|
+
|
7
|
+
TABLE_STRUCTURE = "CREATE TABLE foo_baloos (id integer);"
|
8
|
+
|
9
|
+
data_miner {}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Earth::Model do
|
13
|
+
it 'manages its Schema' do
|
14
|
+
expect { FooBaloo.create_table! }.not_to raise_error
|
15
|
+
end
|
16
|
+
it 'has SafeFinders' do
|
17
|
+
FooBaloo.should respond_to(:safe_find_in_batches)
|
18
|
+
FooBaloo.should respond_to(:safe_find_each)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#registry' do
|
22
|
+
it 'catalogues each Earth model' do
|
23
|
+
Earth::Model.registry.should include(FooBaloo)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -4,7 +4,7 @@ describe 'Species' do
|
|
4
4
|
describe 'fallback' do
|
5
5
|
describe 'marginal_dietary_requirement' do
|
6
6
|
it 'should return 0 when there is no data' do
|
7
|
-
Earth.init :pet, :
|
7
|
+
Earth.init :pet, :mine_original_sources => true
|
8
8
|
Species.delete_all
|
9
9
|
Species.fallback.marginal_dietary_requirement.should == 0
|
10
10
|
end
|
data/spec/earth_spec.rb
CHANGED
@@ -11,43 +11,14 @@ describe Earth do
|
|
11
11
|
Earth.resources.each { |k| k.constantize }
|
12
12
|
end.should_not raise_error(NameError)
|
13
13
|
end
|
14
|
-
|
15
|
-
it 'should include data_miner definitions' do
|
16
|
-
lambda do
|
17
|
-
Earth.resources.each { |k| k.constantize.should_receive(:data_miner) }
|
18
|
-
end
|
19
|
-
require 'earth/data_miner'
|
20
|
-
end
|
21
14
|
end
|
22
15
|
|
23
16
|
describe '.resources' do
|
24
17
|
it 'should get a list of all resource names' do
|
18
|
+
Earth.init :all
|
25
19
|
Earth.resources.length.should == 100
|
26
20
|
Earth.resources.should include('Aircraft')
|
27
21
|
Earth.resources.should include('Industry')
|
28
22
|
end
|
29
|
-
it 'should filter resource_map by domain' do
|
30
|
-
Earth.resources('air').length.should == 8
|
31
|
-
Earth.resources('automobile').length.should == 17
|
32
|
-
Earth.resources('bus').length.should == 4
|
33
|
-
Earth.resources('computation').length.should == 3
|
34
|
-
Earth.resources('diet').length.should == 2
|
35
|
-
Earth.resources('electricity').length.should == 3
|
36
|
-
Earth.resources('fuel').length.should == 5
|
37
|
-
Earth.resources('hospitality').length.should == 2
|
38
|
-
Earth.resources('industry').length.should == 17
|
39
|
-
Earth.resources('locality').length.should == 11
|
40
|
-
Earth.resources('pet').length.should == 4
|
41
|
-
Earth.resources('rail').length.should == 12
|
42
|
-
Earth.resources('residence').length.should == 9
|
43
|
-
Earth.resources('shipping').length.should == 3
|
44
|
-
Earth.resources('fuel').should include('FuelType')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '.domains' do
|
49
|
-
it 'should return a list of all domains' do
|
50
|
-
Earth.domains.should == %w{air automobile bus computation diet electricity fuel hospitality industry locality pet rail residence shipping}
|
51
|
-
end
|
52
23
|
end
|
53
24
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
require 'earth/air/airline'
|
3
|
+
|
4
|
+
FactoryGirl.define do
|
5
|
+
factory :airline, :class => Airline do
|
6
|
+
trait(:delta) { iata_code 'DL'; name 'Delta'; icao_code 'DAL'; bts_code 'DL' }
|
7
|
+
trait(:united) { iata_code 'UA'; name 'United'; icao_code 'UAL'; bts_code 'UL' }
|
8
|
+
trait(:lufthansa) { iata_code 'LH'; name 'Lufthansa'; icao_code 'DLH'; bts_code 'LH' }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
require 'earth/air/airport'
|
3
|
+
|
4
|
+
FactoryGirl.define do
|
5
|
+
factory :airport, :class => Airport do
|
6
|
+
trait(:lax) { iata_code 'LAX'; city 'Los Angeles' }
|
7
|
+
trait(:mdw) { iata_code 'MDW'; city 'Chicago' }
|
8
|
+
trait(:msn) { iata_code 'MSN'; city 'Madison' }
|
9
|
+
trait(:ord) { iata_code 'ORD'; city 'Chicago' }
|
10
|
+
trait(:sfo) { iata_code 'SFO'; city 'San Francisco' }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
require 'earth/air/flight_segment'
|
3
|
+
|
4
|
+
FactoryGirl.define do
|
5
|
+
factory :flight_segment, :class => FlightSegment do
|
6
|
+
row_hash { "fake-#{rand(1e11)}" }
|
7
|
+
|
8
|
+
trait(:from_lax) { origin_airport_iata_code 'LAX' }
|
9
|
+
trait(:from_ord) { origin_airport_iata_code 'ORD' }
|
10
|
+
|
11
|
+
trait(:from_los_angeles) { origin_airport_city 'Los Angeles' }
|
12
|
+
trait(:from_chicago) { origin_airport_city 'Chicago' }
|
13
|
+
|
14
|
+
trait(:to_sfo) { destination_airport_iata_code 'SFO' }
|
15
|
+
trait(:to_msn) { destination_airport_iata_code 'MSN' }
|
16
|
+
trait(:to_lax) { destination_airport_iata_code 'LAX' }
|
17
|
+
trait(:to_ord) { destination_airport_iata_code 'ORD' }
|
18
|
+
|
19
|
+
trait(:to_los_angeles) { destination_airport_city 'Los Angeles' }
|
20
|
+
trait(:to_chicago) { destination_airport_city 'Chicago' }
|
21
|
+
|
22
|
+
trait(:june_2010) { month 6; year 2010 }
|
23
|
+
trait(:may_2011) { year 2011; month 5 }
|
24
|
+
trait(:june_2011) { year 2011; month 6 }
|
25
|
+
trait(:may_25_2011) { year 2011; month 5 }
|
26
|
+
trait(:july_2011) { year 2011; month 7 }
|
27
|
+
|
28
|
+
trait(:united) { airline_bts_code 'UA' }
|
29
|
+
trait(:delta) { airline_bts_code 'DL' }
|
30
|
+
trait(:lufthansa) { airline_bts_code 'LH' }
|
31
|
+
trait(:united_icao) { airline_icao_code 'UAL' }
|
32
|
+
trait(:delta_icao) { airline_icao_code 'DAL' }
|
33
|
+
trait(:lufthansa_icao) { airline_icao_code 'DLH' }
|
34
|
+
|
35
|
+
trait(:loaded) { load_factor 0.99 }
|
36
|
+
trait(:empty) { load_factor 0.01 }
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,56 +1,47 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
Bundler.setup
|
4
|
-
require 'logger'
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
5
3
|
require 'active_record'
|
6
4
|
require 'data_miner'
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
-
require 'earth'
|
10
|
-
|
11
|
-
require 'support/integration'
|
12
|
-
include Integration
|
13
5
|
|
14
|
-
|
15
|
-
when 'mysql'
|
16
|
-
adapter = 'mysql2'
|
17
|
-
database = 'test_earth'
|
18
|
-
username = 'root'
|
19
|
-
password = 'password'
|
20
|
-
|
21
|
-
# system %{mysql -u #{username} -p#{password} -e "DROP DATABASE #{database}"}
|
22
|
-
# system %{mysql -u #{username} -p#{password} -e "CREATE DATABASE #{database}"}
|
23
|
-
else
|
24
|
-
adapter = 'postgresql'
|
25
|
-
database = 'test_earth'
|
26
|
-
username = nil
|
27
|
-
password = nil
|
28
|
-
end
|
6
|
+
require 'factory_girl'
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
'adapter' => adapter,
|
33
|
-
'database' => database,
|
34
|
-
}
|
35
|
-
config['username'] = username if username
|
36
|
-
config['password'] = password if password
|
8
|
+
ENV['EARTH_ENV'] ||= 'test'
|
9
|
+
ENV['DATABASE_URL'] ||= 'mysql2://root:password@localhost/test_earth'
|
37
10
|
|
38
|
-
|
11
|
+
require 'support/integration'
|
12
|
+
include Integration
|
39
13
|
|
14
|
+
require 'logger'
|
40
15
|
logger = Logger.new 'log/test.log'
|
41
|
-
logger.level = Logger::DEBUG
|
42
|
-
|
43
16
|
ActiveRecord::Base.logger = logger
|
44
17
|
DataMiner.logger = logger
|
45
18
|
|
46
|
-
DataMiner::Run.auto_upgrade!
|
47
19
|
DataMiner.unit_converter = :conversions
|
48
20
|
|
49
21
|
RSpec.configure do |c|
|
50
22
|
unless ENV['ALL'] == 'true'
|
23
|
+
c.filter_run_excluding :sanity => true
|
51
24
|
c.filter_run_excluding :data_miner => true
|
52
25
|
end
|
53
26
|
if ENV['SKIP_FLIGHT_SEGMENT'] == 'true'
|
54
27
|
c.filter_run_excluding :flight_segment => true
|
55
28
|
end
|
29
|
+
|
30
|
+
c.before :all do
|
31
|
+
require 'earth'
|
32
|
+
Earth.init :mine_original_sources => true, :connect => true
|
33
|
+
end
|
34
|
+
c.before :all, :sanity => true do
|
35
|
+
described_class.run_data_miner!
|
36
|
+
end
|
37
|
+
|
38
|
+
c.before(:each) do
|
39
|
+
ActiveRecord::Base.connection.increment_open_transactions
|
40
|
+
ActiveRecord::Base.connection.transaction_joinable = false
|
41
|
+
ActiveRecord::Base.connection.begin_db_transaction
|
42
|
+
end
|
43
|
+
c.after(:each) do
|
44
|
+
ActiveRecord::Base.connection.rollback_db_transaction
|
45
|
+
ActiveRecord::Base.connection.decrement_open_transactions
|
46
|
+
end
|
56
47
|
end
|