earth 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -5
- data/README.markdown +0 -8
- data/Rakefile +14 -10
- data/bin/earth_tester.rb +12 -12
- data/earth.gemspec +2 -1
- data/features/automobile_make_fleet_year.feature +9 -19
- data/features/automobile_make_model_year.feature +4 -4
- data/features/support/env.rb +11 -7
- data/features/support/imports/automobile_make_fleet_year_bad.csv +1 -1
- data/features/support/imports/automobile_make_fleet_year_good.csv +1 -1
- data/features/support/imports/automobile_make_model_year_bad.csv +1 -1
- data/features/support/imports/automobile_make_model_year_good.csv +1 -1
- data/lib/earth/air/aircraft/data_miner.rb +63 -15
- data/lib/earth/air/aircraft.rb +0 -11
- data/lib/earth/air/aircraft_class/data_miner.rb +0 -13
- data/lib/earth/air/aircraft_class.rb +12 -3
- data/lib/earth/air/aircraft_fuel_use_equation/data_miner.rb +0 -13
- data/lib/earth/air/aircraft_fuel_use_equation.rb +12 -3
- data/lib/earth/air/airline/data_miner.rb +0 -7
- data/lib/earth/air/airline.rb +6 -3
- data/lib/earth/air/airport/data_miner.rb +5 -14
- data/lib/earth/air/airport.rb +9 -7
- data/lib/earth/air/bts_aircraft/data_miner.rb +0 -5
- data/lib/earth/air/bts_aircraft.rb +3 -3
- data/lib/earth/air/data_miner.rb +2 -3
- data/lib/earth/air/flight_distance_class/data_miner.rb +0 -6
- data/lib/earth/air/flight_distance_class.rb +4 -3
- data/lib/earth/air/flight_seat_class/data_miner.rb +0 -7
- data/lib/earth/air/flight_seat_class.rb +6 -3
- data/lib/earth/air/flight_segment/data_miner.rb +30 -112
- data/lib/earth/air/flight_segment.rb +47 -13
- data/lib/earth/air.rb +2 -1
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -25
- data/lib/earth/automobile/automobile_fuel.rb +24 -8
- data/lib/earth/automobile/automobile_make/data_miner.rb +3 -16
- data/lib/earth/automobile/automobile_make.rb +5 -3
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +16 -30
- data/lib/earth/automobile/automobile_make_fleet_year.rb +10 -7
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -11
- data/lib/earth/automobile/automobile_make_model.rb +9 -7
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +4 -17
- data/lib/earth/automobile/automobile_make_model_year.rb +11 -6
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +37 -65
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +36 -6
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +3 -15
- data/lib/earth/automobile/automobile_make_year.rb +8 -7
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -15
- data/lib/earth/automobile/automobile_size_class.rb +13 -2
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_size_class_year.rb +10 -3
- data/lib/earth/automobile/automobile_type_fuel_age/data_miner.rb +0 -12
- data/lib/earth/automobile/automobile_type_fuel_age.rb +10 -2
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_type_fuel_control.rb +9 -3
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -17
- data/lib/earth/automobile/automobile_type_fuel_year.rb +14 -6
- data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -13
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +12 -7
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -11
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +9 -6
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -10
- data/lib/earth/automobile/automobile_type_year.rb +9 -3
- data/lib/earth/bus/bus_class/data_miner.rb +0 -29
- data/lib/earth/bus/bus_class.rb +27 -2
- data/lib/earth/bus/bus_fuel/data_miner.rb +1 -16
- data/lib/earth/bus/bus_fuel.rb +15 -8
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -10
- data/lib/earth/bus/bus_fuel_control.rb +8 -3
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -10
- data/lib/earth/bus/bus_fuel_year_control.rb +8 -7
- data/lib/earth/bus/data_miner.rb +2 -0
- data/lib/earth/bus.rb +2 -0
- data/lib/earth/computation/computation_carrier/data_miner.rb +0 -5
- data/lib/earth/computation/computation_carrier.rb +3 -2
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -8
- data/lib/earth/computation/computation_carrier_instance_class.rb +6 -6
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -7
- data/lib/earth/computation/computation_carrier_region.rb +6 -7
- data/lib/earth/computation/data_miner.rb +2 -0
- data/lib/earth/computation.rb +2 -0
- data/lib/earth/diet/diet_class/data_miner.rb +0 -16
- data/lib/earth/diet/diet_class.rb +16 -4
- data/lib/earth/diet/food_group/data_miner.rb +0 -9
- data/lib/earth/diet/food_group.rb +7 -2
- data/lib/earth/fuel/fuel/data_miner.rb +0 -16
- data/lib/earth/fuel/fuel.rb +14 -2
- data/lib/earth/fuel/fuel_price/data_miner.rb +0 -6
- data/lib/earth/fuel/fuel_price.rb +4 -6
- data/lib/earth/fuel/fuel_type/data_miner.rb +0 -14
- data/lib/earth/fuel/fuel_type.rb +14 -4
- data/lib/earth/fuel/fuel_year/data_miner.rb +0 -16
- data/lib/earth/fuel/fuel_year.rb +14 -2
- data/lib/earth/fuel/greenhouse_gas/data_miner.rb +0 -9
- data/lib/earth/fuel/greenhouse_gas.rb +10 -5
- data/lib/earth/hospitality/lodging_class/data_miner.rb +0 -12
- data/lib/earth/hospitality/lodging_class.rb +10 -2
- data/lib/earth/industry/data_miner.rb +0 -0
- data/lib/earth/industry/industry.rb +3 -10
- data/lib/earth/industry/industry_product.rb +6 -13
- data/lib/earth/industry/industry_product_line.rb +5 -12
- data/lib/earth/industry/industry_sector.rb +5 -12
- data/lib/earth/industry/merchant.rb +4 -11
- data/lib/earth/industry/merchant_category.rb +3 -10
- data/lib/earth/industry/merchant_category_industry.rb +5 -12
- data/lib/earth/industry/product_line.rb +5 -12
- data/lib/earth/industry/product_line_industry_product.rb +5 -12
- data/lib/earth/industry/sector.rb +5 -12
- data/lib/earth/locality/census_division/data_miner.rb +0 -23
- data/lib/earth/locality/census_division.rb +21 -6
- data/lib/earth/locality/census_region/data_miner.rb +0 -5
- data/lib/earth/locality/census_region.rb +3 -2
- data/lib/earth/locality/climate_division/data_miner.rb +0 -7
- data/lib/earth/locality/climate_division.rb +5 -7
- data/lib/earth/locality/country/data_miner.rb +16 -29
- data/lib/earth/locality/country.rb +15 -4
- data/lib/earth/locality/data_miner.rb +3 -0
- data/lib/earth/locality/egrid_region/data_miner.rb +0 -5
- data/lib/earth/locality/egrid_region.rb +5 -8
- data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -20
- data/lib/earth/locality/egrid_subregion.rb +17 -6
- data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +4 -13
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +8 -4
- data/lib/earth/locality/state/data_miner.rb +0 -8
- data/lib/earth/locality/state.rb +6 -7
- data/lib/earth/locality/urbanity/data_miner.rb +0 -4
- data/lib/earth/locality/urbanity.rb +2 -2
- data/lib/earth/locality/zip_code/data_miner.rb +0 -10
- data/lib/earth/locality/zip_code.rb +8 -6
- data/lib/earth/locality.rb +3 -0
- data/lib/earth/pet/breed/data_miner.rb +0 -7
- data/lib/earth/pet/breed.rb +5 -6
- data/lib/earth/pet/breed_gender/data_miner.rb +0 -8
- data/lib/earth/pet/breed_gender.rb +6 -6
- data/lib/earth/pet/gender/data_miner.rb +0 -3
- data/lib/earth/pet/gender.rb +2 -2
- data/lib/earth/pet/species/data_miner.rb +0 -17
- data/lib/earth/pet/species.rb +17 -4
- data/lib/earth/rail/rail_class/data_miner.rb +0 -14
- data/lib/earth/rail/rail_class.rb +12 -3
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +0 -6
- data/lib/earth/residence/air_conditioner_use.rb +5 -3
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +0 -6
- data/lib/earth/residence/clothes_machine_use.rb +4 -2
- data/lib/earth/residence/data_miner.rb +2 -0
- data/lib/earth/residence/dishwasher_use/data_miner.rb +0 -6
- data/lib/earth/residence/dishwasher_use.rb +5 -3
- data/lib/earth/residence/residence_appliance/data_miner.rb +0 -6
- data/lib/earth/residence/residence_appliance.rb +4 -2
- data/lib/earth/residence/residence_class/data_miner.rb +0 -4
- data/lib/earth/residence/residence_class.rb +2 -2
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -14
- data/lib/earth/residence/residence_fuel_price.rb +12 -7
- data/lib/earth/residence/residence_fuel_type/data_miner.rb +0 -8
- data/lib/earth/residence/residence_fuel_type.rb +6 -2
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -94
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +92 -6
- data/lib/earth/residence.rb +2 -0
- data/lib/earth/shipping/carrier/data_miner.rb +0 -10
- data/lib/earth/shipping/carrier.rb +8 -2
- data/lib/earth/shipping/carrier_mode/data_miner.rb +0 -10
- data/lib/earth/shipping/carrier_mode.rb +9 -3
- data/lib/earth/shipping/shipment_mode/data_miner.rb +0 -7
- data/lib/earth/shipping/shipment_mode.rb +5 -2
- data/lib/earth/version.rb +1 -1
- data/lib/earth.rb +92 -84
- data/spec/earth/air/aircraft_spec.rb +1 -1
- data/spec/earth_spec.rb +15 -15
- data/spec/spec_helper.rb +12 -9
- metadata +175 -171
- data/lib/earth/active_record_ext.rb +0 -9
- data/lib/earth/air/aircraft_manufacturer/data_miner.rb +0 -21
- data/lib/earth/air/aircraft_manufacturer.rb +0 -7
- data/lib/earth/base.rb +0 -7
@@ -30,11 +30,97 @@ class ResidentialEnergyConsumptionSurveyResponse < ActiveRecord::Base
|
|
30
30
|
:ownership,
|
31
31
|
]
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
# sabshere 9/20/10 sorted with sort -d -t "'" -k 2 ~/Desktop/parts.txt
|
34
|
+
create_table do
|
35
|
+
integer 'id'
|
36
|
+
string 'air_conditioner_use_id'
|
37
|
+
float 'annual_energy_from_electricity_for_air_conditioners'
|
38
|
+
string 'annual_energy_from_electricity_for_air_conditioners_units'
|
39
|
+
float 'annual_energy_from_electricity_for_clothes_driers'
|
40
|
+
string 'annual_energy_from_electricity_for_clothes_driers_units'
|
41
|
+
float 'annual_energy_from_electricity_for_dishwashers'
|
42
|
+
string 'annual_energy_from_electricity_for_dishwashers_units'
|
43
|
+
float 'annual_energy_from_electricity_for_freezers'
|
44
|
+
string 'annual_energy_from_electricity_for_freezers_units'
|
45
|
+
float 'annual_energy_from_electricity_for_heating_space'
|
46
|
+
string 'annual_energy_from_electricity_for_heating_space_units'
|
47
|
+
float 'annual_energy_from_electricity_for_heating_water'
|
48
|
+
string 'annual_energy_from_electricity_for_heating_water_units'
|
49
|
+
float 'annual_energy_from_electricity_for_other_appliances'
|
50
|
+
string 'annual_energy_from_electricity_for_other_appliances_units'
|
51
|
+
float 'annual_energy_from_electricity_for_refrigerators'
|
52
|
+
string 'annual_energy_from_electricity_for_refrigerators_units'
|
53
|
+
float 'annual_energy_from_fuel_oil_for_appliances'
|
54
|
+
string 'annual_energy_from_fuel_oil_for_appliances_units'
|
55
|
+
float 'annual_energy_from_fuel_oil_for_heating_space'
|
56
|
+
string 'annual_energy_from_fuel_oil_for_heating_space_units'
|
57
|
+
float 'annual_energy_from_fuel_oil_for_heating_water'
|
58
|
+
string 'annual_energy_from_fuel_oil_for_heating_water_units'
|
59
|
+
float 'annual_energy_from_kerosene'
|
60
|
+
string 'annual_energy_from_kerosene_units'
|
61
|
+
float 'annual_energy_from_natural_gas_for_appliances'
|
62
|
+
string 'annual_energy_from_natural_gas_for_appliances_units'
|
63
|
+
float 'annual_energy_from_natural_gas_for_heating_space'
|
64
|
+
string 'annual_energy_from_natural_gas_for_heating_space_units'
|
65
|
+
float 'annual_energy_from_natural_gas_for_heating_water'
|
66
|
+
string 'annual_energy_from_natural_gas_for_heating_water_units'
|
67
|
+
float 'annual_energy_from_propane_for_appliances'
|
68
|
+
string 'annual_energy_from_propane_for_appliances_units'
|
69
|
+
float 'annual_energy_from_propane_for_heating_space'
|
70
|
+
string 'annual_energy_from_propane_for_heating_space_units'
|
71
|
+
float 'annual_energy_from_propane_for_heating_water'
|
72
|
+
string 'annual_energy_from_propane_for_heating_water_units'
|
73
|
+
float 'annual_energy_from_wood'
|
74
|
+
string 'annual_energy_from_wood_units'
|
75
|
+
boolean 'attached_1car_garage'
|
76
|
+
boolean 'attached_2car_garage'
|
77
|
+
boolean 'attached_3car_garage'
|
78
|
+
float 'bathrooms'
|
79
|
+
integer 'bedrooms'
|
80
|
+
string 'census_division_name'
|
81
|
+
integer 'census_division_number'
|
82
|
+
string 'census_region_name'
|
83
|
+
integer 'census_region_number'
|
84
|
+
string 'central_ac_use'
|
85
|
+
string 'clothes_dryer_use'
|
86
|
+
string 'clothes_machine_use_id'
|
87
|
+
string 'clothes_washer_use'
|
88
|
+
string 'construction_period'
|
89
|
+
date 'construction_year'
|
90
|
+
integer 'cooling_degree_days'
|
91
|
+
string 'cooling_degree_days_units'
|
92
|
+
boolean 'detached_1car_garage'
|
93
|
+
boolean 'detached_2car_garage'
|
94
|
+
boolean 'detached_3car_garage'
|
95
|
+
string 'dishwasher_use_id'
|
96
|
+
integer 'efficient_lights_on_1_to_4_hours'
|
97
|
+
integer 'efficient_lights_on_4_to_12_hours'
|
98
|
+
integer 'efficient_lights_on_over_12_hours'
|
99
|
+
float 'floorspace'
|
100
|
+
string 'floorspace_units'
|
101
|
+
integer 'freezer_count'
|
102
|
+
integer 'full_bathrooms'
|
103
|
+
integer 'half_bathrooms'
|
104
|
+
boolean 'heated_garage'
|
105
|
+
integer 'heating_degree_days'
|
106
|
+
string 'heating_degree_days_units'
|
107
|
+
float 'lighting_efficiency'
|
108
|
+
float 'lighting_use'
|
109
|
+
string 'lighting_use_units'
|
110
|
+
integer 'lights_on_1_to_4_hours'
|
111
|
+
integer 'lights_on_4_to_12_hours'
|
112
|
+
integer 'lights_on_over_12_hours'
|
113
|
+
integer 'outdoor_all_night_gas_lights'
|
114
|
+
integer 'outdoor_all_night_lights'
|
115
|
+
boolean 'ownership'
|
116
|
+
integer 'refrigerator_count'
|
117
|
+
string 'residence_class_id'
|
118
|
+
integer 'residents'
|
119
|
+
float 'rooms'
|
120
|
+
boolean 'thermostat_programmability'
|
121
|
+
integer 'total_rooms'
|
122
|
+
string 'urbanity_id'
|
123
|
+
float 'weighting'
|
124
|
+
string 'window_ac_use'
|
39
125
|
end
|
40
126
|
end
|
data/lib/earth/residence.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
Carrier.class_eval do
|
2
2
|
data_miner do
|
3
|
-
schema Earth.database_options do
|
4
|
-
string 'name'
|
5
|
-
float 'package_volume'
|
6
|
-
float 'route_inefficiency_factor'
|
7
|
-
float 'transport_emission_factor'
|
8
|
-
string 'transport_emission_factor_units'
|
9
|
-
float 'corporate_emission_factor'
|
10
|
-
string 'corporate_emission_factor_units'
|
11
|
-
end
|
12
|
-
|
13
3
|
import "a list of shipping companies and their characteristics",
|
14
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdG1ONU1HZDdZTFJNclFYVkRzR0k5Z2c&hl=en&gid=0&output=csv' do
|
15
5
|
key 'name'
|
@@ -8,7 +8,13 @@ class Carrier < ActiveRecord::Base
|
|
8
8
|
:transport_emission_factor => 0.0005266,
|
9
9
|
:corporate_emission_factor => 0.221
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
create_table do
|
12
|
+
string 'name'
|
13
|
+
float 'package_volume'
|
14
|
+
float 'route_inefficiency_factor'
|
15
|
+
float 'transport_emission_factor'
|
16
|
+
string 'transport_emission_factor_units'
|
17
|
+
float 'corporate_emission_factor'
|
18
|
+
string 'corporate_emission_factor_units'
|
13
19
|
end
|
14
20
|
end
|
@@ -1,15 +1,5 @@
|
|
1
1
|
CarrierMode.class_eval do
|
2
2
|
data_miner do
|
3
|
-
schema Earth.database_options do
|
4
|
-
string 'name'
|
5
|
-
string 'carrier_name'
|
6
|
-
string 'mode_name'
|
7
|
-
float 'package_volume'
|
8
|
-
float 'route_inefficiency_factor'
|
9
|
-
float 'transport_emission_factor'
|
10
|
-
string 'transport_emission_factor_units'
|
11
|
-
end
|
12
|
-
|
13
3
|
import "a list of carrier modes and their characteristics",
|
14
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRsRkJOd0NPd0FETTI0NmpYUlBsN2c&hl=en&gid=0&output=csv' do
|
15
5
|
key 'name'
|
@@ -3,8 +3,14 @@ class CarrierMode < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
|
5
5
|
belongs_to :mode, :foreign_key => 'mode_name', :primary_key => 'name', :class_name => 'ShipmentMode'
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
|
7
|
+
create_table do
|
8
|
+
string 'name'
|
9
|
+
string 'carrier_name'
|
10
|
+
string 'mode_name'
|
11
|
+
float 'package_volume'
|
12
|
+
float 'route_inefficiency_factor'
|
13
|
+
float 'transport_emission_factor'
|
14
|
+
string 'transport_emission_factor_units'
|
9
15
|
end
|
10
16
|
end
|
@@ -1,12 +1,5 @@
|
|
1
1
|
ShipmentMode.class_eval do
|
2
2
|
data_miner do
|
3
|
-
schema Earth.database_options do
|
4
|
-
string 'name'
|
5
|
-
float 'route_inefficiency_factor'
|
6
|
-
float 'transport_emission_factor'
|
7
|
-
string 'transport_emission_factor_units'
|
8
|
-
end
|
9
|
-
|
10
3
|
import "a list of shipment modes and their characteristics",
|
11
4
|
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGR2a2RYcEg2RnRKbkRQcXc0ZkQ5U0E&hl=en&gid=0&output=csv' do
|
12
5
|
key 'name'
|
@@ -3,7 +3,10 @@ class ShipmentMode < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
has_many :carrier_modes, :foreign_key => 'mode_name', :primary_key => 'name'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
create_table do
|
7
|
+
string 'name'
|
8
|
+
float 'route_inefficiency_factor'
|
9
|
+
float 'transport_emission_factor'
|
10
|
+
string 'transport_emission_factor_units'
|
8
11
|
end
|
9
12
|
end
|
data/lib/earth/version.rb
CHANGED
data/lib/earth.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'cohort_scope'
|
3
|
-
require 'earth/base'
|
4
3
|
require 'earth/conversions_ext'
|
5
4
|
require 'earth/inflectors'
|
6
5
|
require 'data_miner'
|
@@ -8,31 +7,36 @@ require 'falls_back_on'
|
|
8
7
|
require 'weighted_average'
|
9
8
|
require 'fixed_width'
|
10
9
|
require 'errata'
|
10
|
+
require 'create_table'
|
11
|
+
require 'loose_tight_dictionary'
|
12
|
+
require 'loose_tight_dictionary/cached_result'
|
11
13
|
|
12
|
-
#
|
13
|
-
|
14
|
+
# hackety hack
|
15
|
+
def INSERT_IGNORE(cmd)
|
16
|
+
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
|
17
|
+
prefix = 'INSERT'
|
18
|
+
else
|
19
|
+
prefix = 'INSERT IGNORE'
|
20
|
+
end
|
21
|
+
ActiveRecord::Base.connection.execute "#{prefix} #{cmd}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# The earth module is an interface for loading data models from various domains.
|
14
25
|
module Earth
|
15
26
|
extend self
|
16
27
|
|
17
|
-
|
18
|
-
@taps_server || 'http://carbon:neutral@data.brighterplanet.com:5000'
|
19
|
-
end
|
20
|
-
|
21
|
-
# taps_server is a URL. See the data_miner gem docs
|
22
|
-
def taps_server=(val)
|
23
|
-
@taps_server = val
|
24
|
-
end
|
25
|
-
|
26
|
-
# Takes argument like Earth.resource_names(['air'])
|
28
|
+
# Takes argument like Earth.search(['air'])
|
27
29
|
# Default is search all domains
|
28
30
|
# For example, <tt>[ 'Aircraft', 'Airline' ]</tt>
|
29
|
-
def
|
30
|
-
|
31
|
-
|
31
|
+
def search(*search_domains)
|
32
|
+
search_domains = search_domains.empty? ? [:all] : search_domains.flatten.map(&:to_sym)
|
33
|
+
if search_domains.include? :all
|
34
|
+
resources
|
32
35
|
else
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
resource_map.select do |resource, domain|
|
37
|
+
search_domains.include? domain.to_sym
|
38
|
+
end.map do |resource, domain|
|
39
|
+
resource
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -42,21 +46,24 @@ module Earth
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def domains
|
45
|
-
|
49
|
+
resource_map.values.uniq.sort
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
def resources
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
resource_map.keys.sort
|
54
|
+
end
|
55
|
+
|
56
|
+
def resource_map
|
57
|
+
@resource_map ||= Dir[File.join(gem_root, 'lib', 'earth', '*')].select do |path|
|
58
|
+
File.directory? path
|
59
|
+
end.inject({}) do |memo, domain_path|
|
60
|
+
Dir[File.join(domain_path, '*.rb')].each do |resource_path|
|
61
|
+
resource = File.basename(resource_path, '.rb').camelcase
|
62
|
+
unless resource == 'DataMiner'
|
63
|
+
memo[resource] = File.basename domain_path
|
57
64
|
end
|
58
65
|
end
|
59
|
-
|
66
|
+
memo
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
@@ -68,85 +75,86 @@ module Earth
|
|
68
75
|
# Earth.init should be performed after a connection is made to the database and
|
69
76
|
# before any domain models are referenced.
|
70
77
|
def init(*args)
|
71
|
-
|
72
|
-
|
73
|
-
domains = []
|
74
|
-
options = {}
|
75
|
-
args.each do |arg|
|
76
|
-
if arg.is_a?(Hash)
|
77
|
-
options = arg
|
78
|
-
else
|
79
|
-
domains << arg
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
load_domains(domains, options)
|
84
|
-
load_schemas(options) if options[:apply_schemas]
|
85
|
-
end
|
78
|
+
options = args.last.is_a?(Hash) ? args.pop.symbolize_keys : {}
|
79
|
+
domains = args.empty? ? [ :all ] : args.map(&:to_sym)
|
86
80
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
{ :options => 'ENGINE=InnoDB default charset=utf8 collate=utf8_general_ci' }
|
92
|
-
end
|
81
|
+
_load_plugins
|
82
|
+
_load_domains domains, options
|
83
|
+
_decorate_resources options
|
84
|
+
_load_schemas search(domains), options
|
93
85
|
end
|
94
86
|
|
95
|
-
private
|
96
|
-
|
87
|
+
private
|
88
|
+
|
89
|
+
# TODO sabshere don't use directories to specify domains
|
90
|
+
# * you have 20 million data_miner.rb files which are easy to confuse
|
91
|
+
# * you have to go all over the filesystem to figure things out
|
92
|
+
def _load_domains(domains, options)
|
93
|
+
return if domains.include? :none
|
97
94
|
if domains.empty? or domains.include?(:all)
|
98
95
|
# sabshere 9/16/10 why maintain this separately?
|
99
96
|
require 'earth/all'
|
100
97
|
require 'earth/data_miner' if options[:apply_schemas] or options[:load_data_miner]
|
101
|
-
|
98
|
+
else
|
102
99
|
domains.each do |domain|
|
103
100
|
require "earth/#{domain}"
|
104
|
-
if options[:apply_schemas] or options[:load_data_miner]
|
105
|
-
begin
|
106
|
-
require "earth/#{domain}/data_miner"
|
107
|
-
rescue LoadError
|
108
|
-
end
|
109
|
-
end
|
101
|
+
require "earth/#{domain}/data_miner" if options[:apply_schemas] or options[:load_data_miner]
|
110
102
|
end
|
111
103
|
end
|
112
104
|
end
|
113
105
|
|
114
|
-
def
|
115
|
-
require 'earth/active_record_ext'
|
106
|
+
def _load_plugins
|
116
107
|
Dir[File.join(Earth.gem_root, 'vendor', '**', 'init.rb')].each do |pluginit|
|
117
108
|
$:.unshift File.join(File.dirname(pluginit), 'lib')
|
118
109
|
load pluginit
|
119
110
|
end
|
120
111
|
end
|
112
|
+
|
113
|
+
def _append_pull_dependencies_step_to_data_miner(resource)
|
114
|
+
resource_model = resource.constantize
|
115
|
+
return if resource_model.data_miner_config.steps.any? { |step| step.description == :run_data_miner_on_parent_associations! }
|
121
116
|
|
122
|
-
|
123
|
-
|
117
|
+
pull_dependencies_step = DataMiner::Process.new resource_model.data_miner_config, :run_data_miner_on_parent_associations!
|
118
|
+
|
119
|
+
resource_model.data_miner_config.steps.push pull_dependencies_step
|
124
120
|
end
|
121
|
+
|
122
|
+
def _prepend_create_table_step_to_data_miner(resource)
|
123
|
+
resource_model = resource.constantize
|
124
|
+
return if resource_model.data_miner_config.steps.any? { |step| step.description == :create_table! }
|
125
|
+
|
126
|
+
create_table_step = DataMiner::Process.new resource_model.data_miner_config, :create_table!
|
125
127
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
128
|
+
resource_model.data_miner_config.steps.unshift create_table_step
|
129
|
+
end
|
130
|
+
|
131
|
+
TAPS_STEP = 'Tap the Brighter Planet data server'
|
132
|
+
TAPS_SOURCE = 'http://carbon:neutral@data.brighterplanet.com'
|
133
|
+
def _prepend_taps_step_to_data_miner(resource)
|
134
|
+
resource_model = resource.constantize
|
135
|
+
return if resource_model.data_miner_config.steps.any? { |step| step.description == TAPS_STEP }
|
136
|
+
|
137
|
+
taps_step = DataMiner::Tap.new resource_model.data_miner_config, TAPS_STEP, TAPS_SOURCE
|
138
|
+
|
139
|
+
resource_model.data_miner_config.steps.unshift taps_step
|
140
|
+
end
|
141
|
+
|
142
|
+
def _decorate_resources(options)
|
143
|
+
resources.each do |resource|
|
144
|
+
next unless ::Object.const_defined?(resource)
|
145
|
+
_append_pull_dependencies_step_to_data_miner resource
|
146
|
+
if options[:apply_schemas] or options[:load_data_miner]
|
147
|
+
_prepend_create_table_step_to_data_miner resource
|
132
148
|
else
|
133
|
-
|
134
|
-
end
|
135
|
-
end
|
136
|
-
models.sort.each do |model|
|
137
|
-
klass = Object.const_get(model)
|
138
|
-
if klass.respond_to?(:execute_schema) and (!klass.table_exists? || options[:force_schema])
|
139
|
-
klass.execute_schema
|
149
|
+
_prepend_taps_step_to_data_miner resource
|
140
150
|
end
|
141
151
|
end
|
142
152
|
end
|
143
|
-
end
|
144
153
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
154
|
+
def _load_schemas(selected_resources, options)
|
155
|
+
return unless options[:apply_schemas]
|
156
|
+
selected_resources.each do |resource|
|
157
|
+
resource.constantize.create_table!
|
158
|
+
end
|
150
159
|
end
|
151
|
-
ActiveRecord::Base.connection.execute "#{prefix} #{cmd}"
|
152
160
|
end
|
@@ -5,7 +5,7 @@ require 'earth/air/aircraft/data_miner'
|
|
5
5
|
describe Aircraft do
|
6
6
|
describe 'import', :slow => true do
|
7
7
|
it 'should treat empty cells as null' do
|
8
|
-
Aircraft.
|
8
|
+
Aircraft.create_table!
|
9
9
|
Aircraft.run_data_miner!
|
10
10
|
Aircraft.count.should > 1
|
11
11
|
Aircraft.where(:brighter_planet_aircraft_class_code => nil).should_not be_empty
|
data/spec/earth_spec.rb
CHANGED
@@ -8,38 +8,38 @@ describe Earth do
|
|
8
8
|
|
9
9
|
it 'should require all Earth models' do
|
10
10
|
lambda do
|
11
|
-
Earth.
|
11
|
+
Earth.resources.each { |k| k.constantize }
|
12
12
|
end.should_not raise_error(NameError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should include data_miner definitions' do
|
16
16
|
lambda do
|
17
|
-
Earth.
|
17
|
+
Earth.resources.each { |k| k.constantize.should_receive(:data_miner) }
|
18
18
|
end
|
19
19
|
require 'earth/data_miner'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe '.
|
24
|
-
it 'should get a list of
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
describe '.resource_map' do
|
24
|
+
it 'should get a list of resource_map' do
|
25
|
+
resource_map = Earth.resource_map
|
26
|
+
resource_map.keys.count.should == 75
|
27
|
+
resource_map['FuelType'].should == 'fuel'
|
28
28
|
end
|
29
29
|
it 'should exclude data_miner files' do
|
30
|
-
Earth.
|
30
|
+
Earth.resource_map.keys.should_not include('DataMiner')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '.
|
34
|
+
describe '.search' do
|
35
35
|
it 'should get a list of all resource names' do
|
36
|
-
Earth.
|
37
|
-
Earth.
|
38
|
-
Earth.
|
36
|
+
Earth.search.length.should == 75
|
37
|
+
Earth.search.should include('Aircraft')
|
38
|
+
Earth.search.should include('Industry')
|
39
39
|
end
|
40
|
-
it 'should filter
|
41
|
-
Earth.
|
42
|
-
Earth.
|
40
|
+
it 'should filter resource_map by domain' do
|
41
|
+
Earth.search('fuel').length.should == 5
|
42
|
+
Earth.search('fuel').should include('FuelType')
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
3
|
Bundler.setup
|
4
|
-
|
4
|
+
require 'logger'
|
5
5
|
require 'active_record'
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
6
|
+
require 'data_miner'
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
require 'earth'
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
logger = Logger.new 'log/test.log'
|
12
|
+
logger.level = Logger::DEBUG
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
15
|
+
|
16
|
+
ActiveRecord::Base.logger = logger
|
17
|
+
|
18
|
+
DataMiner.logger = logger
|
16
19
|
|
17
20
|
RSpec.configure do |c|
|
18
21
|
c.filter_run_excluding :slow => true
|