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
@@ -1,9 +1,5 @@
|
|
1
1
|
ZipCode.class_eval do
|
2
2
|
data_miner do
|
3
|
-
process "Start from scratch" do
|
4
|
-
delete_all
|
5
|
-
end
|
6
|
-
|
7
3
|
import 'the Mapping Hacks zipcode database',
|
8
4
|
:url => 'http://mappinghacks.com/data/zipcode.zip', # http://archive.data.brighterplanet.com/zipcode.zip
|
9
5
|
:filename => 'zipcode.csv' do
|
data/lib/earth/model.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'earth'
|
2
|
+
require 'table_warnings'
|
3
|
+
|
4
|
+
module Earth
|
5
|
+
module Model
|
6
|
+
def Model.extended(target)
|
7
|
+
target.extend SafeFinders
|
8
|
+
target.extend Schema
|
9
|
+
target.mattr_accessor :source_file
|
10
|
+
self.registry << target
|
11
|
+
target.source_file = caller.first.split(':').first
|
12
|
+
|
13
|
+
extend_mining(target)
|
14
|
+
end
|
15
|
+
|
16
|
+
def Model.registry
|
17
|
+
@registry ||= []
|
18
|
+
end
|
19
|
+
|
20
|
+
def Model.extend_mining(target)
|
21
|
+
if Earth.mine_original_sources
|
22
|
+
path = File.join(File.dirname(target.source_file), File.basename(target.source_file, '.rb'), 'data_miner')
|
23
|
+
require path if File.exist?(path + '.rb')
|
24
|
+
target.data_miner_script.prepend_once :process, :create_table!
|
25
|
+
else
|
26
|
+
target.data_miner_script.prepend_once :sql, "Brighter Planet's reference data", "http://data.brighterplanet.com/#{to_s.underscore.pluralize}.sql"
|
27
|
+
end
|
28
|
+
target.data_miner_script.append_once :process, :run_data_miner_on_parent_associations!
|
29
|
+
end
|
30
|
+
|
31
|
+
module Schema
|
32
|
+
# http://ostermiller.org/findcomment.html
|
33
|
+
COMMENT = %r{/\*(?:.|[\r\n])*?\*/}
|
34
|
+
WHITESPACE = /\s+/
|
35
|
+
SEMICOLON = / ?; ?/
|
36
|
+
|
37
|
+
def create_table!(force = true)
|
38
|
+
c = ActiveRecord::Base.connection_pool.checkout
|
39
|
+
|
40
|
+
if c.table_exists?(table_name)
|
41
|
+
return unless force
|
42
|
+
c.drop_table table_name
|
43
|
+
end
|
44
|
+
|
45
|
+
statements = const_get(:TABLE_STRUCTURE).gsub(COMMENT, '').gsub(WHITESPACE, ' ').split(SEMICOLON).select(&:present?)
|
46
|
+
|
47
|
+
statements.each do |sql|
|
48
|
+
c.execute sql
|
49
|
+
end
|
50
|
+
|
51
|
+
# safely reset column information
|
52
|
+
if c.respond_to?(:schema_cache)
|
53
|
+
c.schema_cache.clear!
|
54
|
+
end
|
55
|
+
reset_column_information
|
56
|
+
descendants.each do |descendant|
|
57
|
+
descendant.reset_column_information
|
58
|
+
end
|
59
|
+
|
60
|
+
nil
|
61
|
+
ensure
|
62
|
+
ActiveRecord::Base.connection_pool.checkin c
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module SafeFinders
|
67
|
+
# http://www.seejohncode.com/tag/rails/
|
68
|
+
# Override due to implementation of regular find_in_batches conflicting using UUIDs
|
69
|
+
def safe_find_in_batches(&block)
|
70
|
+
return find_in_batches({}, &block) if relation.primary_key.is_a?(Arel::Attributes::Integer)
|
71
|
+
|
72
|
+
batch_size = 1000
|
73
|
+
offset = 0
|
74
|
+
# Get the relation and keep going over it until there's nothing left
|
75
|
+
relation = order("#{quoted_table_name}.#{quoted_primary_key} ASC").limit(batch_size)
|
76
|
+
while (results = relation.offset(offset).limit(batch_size).all).any?
|
77
|
+
unscoped { block.call(results) }
|
78
|
+
offset += batch_size
|
79
|
+
end
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def safe_find_each
|
84
|
+
safe_find_in_batches do |records|
|
85
|
+
records.each { |record| yield record }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/earth/pet.rb
CHANGED
data/lib/earth/pet/breed.rb
CHANGED
@@ -1,13 +1,28 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/pet/breed_gender'
|
4
|
+
require 'earth/pet/species'
|
5
|
+
|
1
6
|
class Breed < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE breeds
|
12
|
+
(
|
13
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
species_name CHARACTER VARYING(255),
|
15
|
+
weight FLOAT,
|
16
|
+
weight_units CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "name"
|
3
22
|
|
4
23
|
has_many :breed_genders, :foreign_key => 'breed_name'
|
5
24
|
belongs_to :species, :foreign_key => 'species_name'
|
6
25
|
|
7
|
-
col :name
|
8
|
-
col :species_name
|
9
|
-
col :weight, :type => :float
|
10
|
-
col :weight_units
|
11
26
|
|
12
27
|
warn_if_nulls_except(
|
13
28
|
:weight,
|
@@ -1,14 +1,29 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/pet/breed'
|
4
|
+
require 'earth/pet/gender'
|
5
|
+
|
1
6
|
class BreedGender < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE breed_genders
|
12
|
+
(
|
13
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
breed_name CHARACTER VARYING(255),
|
15
|
+
gender_name CHARACTER VARYING(255),
|
16
|
+
weight FLOAT,
|
17
|
+
weight_units CHARACTER VARYING(255)
|
18
|
+
);
|
19
|
+
|
20
|
+
EOS
|
21
|
+
|
2
22
|
self.primary_key = "name"
|
3
23
|
|
4
24
|
belongs_to :breed, :foreign_key => 'breed_name'
|
5
25
|
belongs_to :gender, :foreign_key => 'gender_name'
|
6
26
|
|
7
|
-
col :name
|
8
|
-
col :breed_name
|
9
|
-
col :gender_name
|
10
|
-
col :weight, :type => :float
|
11
|
-
col :weight_units
|
12
27
|
|
13
28
|
warn_unless_size 586
|
14
29
|
end
|
data/lib/earth/pet/gender.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/pet/breed_gender'
|
4
|
+
|
1
5
|
class Gender < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE genders
|
11
|
+
(
|
12
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY
|
13
|
+
);
|
14
|
+
|
15
|
+
EOS
|
16
|
+
|
2
17
|
self.primary_key = "name"
|
3
18
|
|
4
19
|
has_many :breed_genders, :foreign_key => 'gender_name'
|
5
20
|
|
6
|
-
col :name
|
7
21
|
|
8
22
|
warn_unless_size 2
|
9
23
|
end
|
data/lib/earth/pet/species.rb
CHANGED
@@ -1,20 +1,36 @@
|
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
5
|
+
require 'earth/pet/breed'
|
6
|
+
|
1
7
|
class Species < ActiveRecord::Base
|
8
|
+
extend Earth::Model
|
9
|
+
|
10
|
+
TABLE_STRUCTURE = <<-EOS
|
11
|
+
|
12
|
+
CREATE TABLE species
|
13
|
+
(
|
14
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
15
|
+
population INTEGER,
|
16
|
+
diet_emission_intensity FLOAT,
|
17
|
+
diet_emission_intensity_units CHARACTER VARYING(255),
|
18
|
+
weight FLOAT,
|
19
|
+
weight_units CHARACTER VARYING(255),
|
20
|
+
marginal_dietary_requirement FLOAT,
|
21
|
+
marginal_dietary_requirement_units CHARACTER VARYING(255),
|
22
|
+
fixed_dietary_requirement FLOAT,
|
23
|
+
fixed_dietary_requirement_units CHARACTER VARYING(255),
|
24
|
+
minimum_weight FLOAT,
|
25
|
+
minimum_weight_units CHARACTER VARYING(255),
|
26
|
+
maximum_weight FLOAT,
|
27
|
+
maximum_weight_units CHARACTER VARYING(255)
|
28
|
+
);
|
29
|
+
|
30
|
+
EOS
|
31
|
+
|
2
32
|
self.primary_key = "name"
|
3
33
|
|
4
|
-
col :name
|
5
|
-
col :population, :type => :integer
|
6
|
-
col :diet_emission_intensity, :type => :float
|
7
|
-
col :diet_emission_intensity_units
|
8
|
-
col :weight, :type => :float
|
9
|
-
col :weight_units
|
10
|
-
col :marginal_dietary_requirement, :type => :float
|
11
|
-
col :marginal_dietary_requirement_units
|
12
|
-
col :fixed_dietary_requirement, :type => :float
|
13
|
-
col :fixed_dietary_requirement_units
|
14
|
-
col :minimum_weight, :type => :float
|
15
|
-
col :minimum_weight_units
|
16
|
-
col :maximum_weight, :type => :float
|
17
|
-
col :maximum_weight_units
|
18
34
|
|
19
35
|
has_many :breeds, :foreign_key => 'species_name'
|
20
36
|
|
data/lib/earth/rail.rb
CHANGED
@@ -1,21 +1,32 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
2
3
|
class CountryRailClass < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE country_rail_classes
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
country_iso_3166_code CHARACTER VARYING(255),
|
12
|
+
rail_class_name CHARACTER VARYING(255),
|
13
|
+
passengers FLOAT,
|
14
|
+
speed FLOAT,
|
15
|
+
speed_units CHARACTER VARYING(255),
|
16
|
+
trip_distance FLOAT,
|
17
|
+
trip_distance_units CHARACTER VARYING(255),
|
18
|
+
electricity_intensity FLOAT,
|
19
|
+
electricity_intensity_units CHARACTER VARYING(255),
|
20
|
+
diesel_intensity FLOAT,
|
21
|
+
diesel_intensity_units CHARACTER VARYING(255),
|
22
|
+
co2_emission_factor FLOAT,
|
23
|
+
co2_emission_factor_units CHARACTER VARYING(255)
|
24
|
+
);
|
25
|
+
|
26
|
+
EOS
|
27
|
+
|
3
28
|
self.primary_key = "name"
|
4
29
|
|
5
|
-
col :name
|
6
|
-
col :country_iso_3166_code
|
7
|
-
col :rail_class_name
|
8
|
-
col :passengers, :type => :float
|
9
|
-
col :speed, :type => :float
|
10
|
-
col :speed_units
|
11
|
-
col :trip_distance, :type => :float
|
12
|
-
col :trip_distance_units
|
13
|
-
col :electricity_intensity, :type => :float
|
14
|
-
col :electricity_intensity_units
|
15
|
-
col :diesel_intensity, :type => :float
|
16
|
-
col :diesel_intensity_units
|
17
|
-
col :co2_emission_factor, :type => :float
|
18
|
-
col :co2_emission_factor_units
|
19
30
|
|
20
31
|
warn_unless_size 4
|
21
32
|
end
|
@@ -1,17 +1,27 @@
|
|
1
|
-
require 'earth/
|
2
|
-
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
3
|
class CountryRailTraction < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE country_rail_tractions
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
country_iso_3166_code CHARACTER VARYING(255),
|
12
|
+
rail_traction_name CHARACTER VARYING(255),
|
13
|
+
electricity_intensity FLOAT,
|
14
|
+
electricity_intensity_units CHARACTER VARYING(255),
|
15
|
+
diesel_intensity FLOAT,
|
16
|
+
diesel_intensity_units CHARACTER VARYING(255),
|
17
|
+
co2_emission_factor FLOAT,
|
18
|
+
co2_emission_factor_units CHARACTER VARYING(255)
|
19
|
+
);
|
20
|
+
|
21
|
+
EOS
|
22
|
+
|
4
23
|
self.primary_key = "name"
|
5
24
|
|
6
|
-
col :name
|
7
|
-
col :country_iso_3166_code
|
8
|
-
col :rail_traction_name
|
9
|
-
col :electricity_intensity, :type => :float
|
10
|
-
col :electricity_intensity_units
|
11
|
-
col :diesel_intensity, :type => :float
|
12
|
-
col :diesel_intensity_units
|
13
|
-
col :co2_emission_factor, :type => :float
|
14
|
-
col :co2_emission_factor_units
|
15
25
|
|
16
26
|
warn_unless_size 50
|
17
27
|
end
|
@@ -1,18 +1,28 @@
|
|
1
|
-
require 'earth/
|
2
|
-
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
3
|
class CountryRailTractionClass < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE country_rail_traction_classes
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
country_iso_3166_code CHARACTER VARYING(255),
|
12
|
+
rail_traction_name CHARACTER VARYING(255),
|
13
|
+
rail_class_name CHARACTER VARYING(255),
|
14
|
+
electricity_intensity FLOAT,
|
15
|
+
electricity_intensity_units CHARACTER VARYING(255),
|
16
|
+
diesel_intensity FLOAT,
|
17
|
+
diesel_intensity_units CHARACTER VARYING(255),
|
18
|
+
co2_emission_factor FLOAT,
|
19
|
+
co2_emission_factor_units CHARACTER VARYING(255)
|
20
|
+
);
|
21
|
+
|
22
|
+
EOS
|
23
|
+
|
4
24
|
self.primary_key = "name"
|
5
25
|
|
6
|
-
col :name
|
7
|
-
col :country_iso_3166_code
|
8
|
-
col :rail_traction_name
|
9
|
-
col :rail_class_name
|
10
|
-
col :electricity_intensity, :type => :float
|
11
|
-
col :electricity_intensity_units
|
12
|
-
col :diesel_intensity, :type => :float
|
13
|
-
col :diesel_intensity_units
|
14
|
-
col :co2_emission_factor, :type => :float
|
15
|
-
col :co2_emission_factor_units
|
16
26
|
|
17
27
|
warn_unless_size 125
|
18
28
|
end
|
@@ -1,5 +1,24 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/rail/national_transit_database_mode'
|
4
|
+
require 'earth/rail/national_transit_database_record'
|
5
|
+
|
2
6
|
class NationalTransitDatabaseCompany < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE ntd_companies
|
12
|
+
(
|
13
|
+
id CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
name CHARACTER VARYING(255),
|
15
|
+
acronym CHARACTER VARYING(255),
|
16
|
+
zip_code_name CHARACTER VARYING(255),
|
17
|
+
duns_number CHARACTER VARYING(255)
|
18
|
+
);
|
19
|
+
|
20
|
+
EOS
|
21
|
+
|
3
22
|
self.primary_key = "id"
|
4
23
|
self.table_name = :ntd_companies
|
5
24
|
|
@@ -31,11 +50,6 @@ class NationalTransitDatabaseCompany < ActiveRecord::Base
|
|
31
50
|
end
|
32
51
|
end
|
33
52
|
|
34
|
-
col :id
|
35
|
-
col :name
|
36
|
-
col :acronym
|
37
|
-
col :zip_code_name
|
38
|
-
col :duns_number
|
39
53
|
|
40
54
|
warn_if_nulls_except(
|
41
55
|
:acronym,
|