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
data/lib/earth/air.rb
CHANGED
data/lib/earth/air/aircraft.rb
CHANGED
@@ -1,6 +1,43 @@
|
|
1
1
|
require 'fuzzy_match/cached_result'
|
2
|
+
require 'falls_back_on'
|
3
|
+
|
4
|
+
require 'earth/model'
|
5
|
+
|
6
|
+
require 'earth/air/flight_segment'
|
2
7
|
|
3
8
|
class Aircraft < ActiveRecord::Base
|
9
|
+
extend Earth::Model
|
10
|
+
|
11
|
+
TABLE_STRUCTURE = <<-EOS
|
12
|
+
|
13
|
+
CREATE TABLE aircraft
|
14
|
+
(
|
15
|
+
icao_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
16
|
+
manufacturer_name CHARACTER VARYING(255),
|
17
|
+
model_name CHARACTER VARYING(255),
|
18
|
+
description CHARACTER VARYING(255),
|
19
|
+
aircraft_type CHARACTER VARYING(255),
|
20
|
+
engine_type CHARACTER VARYING(255),
|
21
|
+
engines INTEGER,
|
22
|
+
weight_class CHARACTER VARYING(255),
|
23
|
+
class_code CHARACTER VARYING(255),
|
24
|
+
passengers FLOAT,
|
25
|
+
seats FLOAT,
|
26
|
+
seats_specificity CHARACTER VARYING(255),
|
27
|
+
m3 FLOAT,
|
28
|
+
m3_units CHARACTER VARYING(255),
|
29
|
+
m2 FLOAT,
|
30
|
+
m2_units CHARACTER VARYING(255),
|
31
|
+
m1 FLOAT,
|
32
|
+
m1_units CHARACTER VARYING(255),
|
33
|
+
b FLOAT,
|
34
|
+
b_units CHARACTER VARYING(255),
|
35
|
+
fuel_use_specificity CHARACTER VARYING(255)
|
36
|
+
);
|
37
|
+
CREATE INDEX index_aircraft_on_description ON aircraft (description);
|
38
|
+
|
39
|
+
EOS
|
40
|
+
|
4
41
|
self.primary_key = "icao_code"
|
5
42
|
|
6
43
|
# Fuzzy association with FlightSegment
|
@@ -122,27 +159,6 @@ class Aircraft < ActiveRecord::Base
|
|
122
159
|
:m1_units => 'kilograms_per_nautical_mile',
|
123
160
|
:b_units => 'kilograms'
|
124
161
|
|
125
|
-
col :icao_code
|
126
|
-
col :manufacturer_name
|
127
|
-
col :model_name
|
128
|
-
col :description
|
129
|
-
col :aircraft_type
|
130
|
-
col :engine_type
|
131
|
-
col :engines, :type => :integer
|
132
|
-
col :weight_class
|
133
|
-
col :class_code
|
134
|
-
col :passengers, :type => :float
|
135
|
-
col :seats, :type => :float
|
136
|
-
col :seats_specificity
|
137
|
-
col :m3, :type => :float
|
138
|
-
col :m3_units
|
139
|
-
col :m2, :type => :float
|
140
|
-
col :m2_units
|
141
|
-
col :m1, :type => :float
|
142
|
-
col :m1_units
|
143
|
-
col :b, :type => :float
|
144
|
-
col :b_units
|
145
|
-
col :fuel_use_specificity
|
146
162
|
|
147
163
|
warn_if_nulls_except(
|
148
164
|
:passengers,
|
@@ -22,10 +22,6 @@ Aircraft.class_eval do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
data_miner do
|
25
|
-
process "Start from scratch" do
|
26
|
-
delete_all
|
27
|
-
end
|
28
|
-
|
29
25
|
('A'..'Z').each do |letter|
|
30
26
|
import("aircraft made by whitelisted manufacturers whose ICAO code starts with '#{letter}' from the FAA",
|
31
27
|
:url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
|
data/lib/earth/air/airline.rb
CHANGED
@@ -1,15 +1,29 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/air/flight_segment'
|
4
|
+
|
1
5
|
class Airline < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE airlines
|
11
|
+
(
|
12
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
13
|
+
secondary_name CHARACTER VARYING(255),
|
14
|
+
bts_code CHARACTER VARYING(255),
|
15
|
+
iata_code CHARACTER VARYING(255),
|
16
|
+
icao_code CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "name"
|
3
22
|
|
4
23
|
has_many :flight_segments,
|
5
24
|
:primary_key => :bts_code,
|
6
25
|
:foreign_key => :airline_bts_code
|
7
26
|
|
8
|
-
col :name
|
9
|
-
col :secondary_name
|
10
|
-
col :bts_code
|
11
|
-
col :iata_code
|
12
|
-
col :icao_code
|
13
27
|
|
14
28
|
warn_unless_size 1523 # note: this is overridden in data1, which imports extra airlines from proprietary data
|
15
29
|
end
|
@@ -7,10 +7,6 @@ Airline.class_eval do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
data_miner do
|
10
|
-
process "Start from scratch" do
|
11
|
-
delete_all
|
12
|
-
end
|
13
|
-
|
14
10
|
import "the BTS unique carrier code lookup table",
|
15
11
|
:url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_UNIQUE_CARRIERS',
|
16
12
|
:errata => { :url => "file://#{Earth::ERRATA_DIR}/airline/bts_carrier_codes_errata.csv", :responder => 'Airline::Guru' } do
|
data/lib/earth/air/airport.rb
CHANGED
@@ -1,7 +1,28 @@
|
|
1
|
-
require
|
2
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
require 'earth/loader'
|
3
|
+
Earth::Loader.load_plugins
|
4
|
+
|
5
|
+
require 'earth/locality/country'
|
6
|
+
require 'earth/air/flight_segment'
|
3
7
|
|
4
8
|
class Airport < ActiveRecord::Base
|
9
|
+
extend Earth::Model
|
10
|
+
|
11
|
+
TABLE_STRUCTURE = <<-EOS
|
12
|
+
|
13
|
+
CREATE TABLE airports
|
14
|
+
(
|
15
|
+
iata_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
16
|
+
name CHARACTER VARYING(255),
|
17
|
+
city CHARACTER VARYING(255),
|
18
|
+
country_name CHARACTER VARYING(255),
|
19
|
+
country_iso_3166_code CHARACTER VARYING(255),
|
20
|
+
latitude FLOAT,
|
21
|
+
longitude FLOAT
|
22
|
+
);
|
23
|
+
|
24
|
+
EOS
|
25
|
+
|
5
26
|
self.primary_key = "iata_code"
|
6
27
|
|
7
28
|
belongs_to :country,
|
@@ -18,13 +39,6 @@ class Airport < ActiveRecord::Base
|
|
18
39
|
:lat_column_name => :latitude,
|
19
40
|
:lng_column_name => :longitude
|
20
41
|
|
21
|
-
col :iata_code
|
22
|
-
col :name
|
23
|
-
col :city
|
24
|
-
col :country_name
|
25
|
-
col :country_iso_3166_code
|
26
|
-
col :latitude, :type => :float
|
27
|
-
col :longitude, :type => :float
|
28
42
|
|
29
43
|
warn_unless_size 5324
|
30
44
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'earth/locality/
|
1
|
+
require 'earth/locality/country'
|
2
2
|
|
3
3
|
Airport.class_eval do
|
4
4
|
class Airport::Guru
|
@@ -21,10 +21,6 @@ Airport.class_eval do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
data_miner do
|
24
|
-
process "Start from scratch" do
|
25
|
-
delete_all
|
26
|
-
end
|
27
|
-
|
28
24
|
process "Ensure Country is populated" do
|
29
25
|
Country.run_data_miner!
|
30
26
|
end
|
@@ -1,7 +1,19 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class BtsAircraft < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE bts_aircraft
|
9
|
+
(
|
10
|
+
bts_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
description CHARACTER VARYING(255)
|
12
|
+
);
|
13
|
+
|
14
|
+
EOS
|
15
|
+
|
2
16
|
self.primary_key = "bts_code"
|
3
|
-
col :bts_code
|
4
|
-
col :description
|
5
17
|
|
6
18
|
warn_unless_size 379
|
7
19
|
end
|
@@ -1,17 +1,29 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class FlightDistanceClass < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE flight_distance_classes
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
distance FLOAT,
|
12
|
+
distance_units CHARACTER VARYING(255),
|
13
|
+
min_distance FLOAT,
|
14
|
+
min_distance_units CHARACTER VARYING(255),
|
15
|
+
max_distance FLOAT,
|
16
|
+
max_distance_units CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "name"
|
3
22
|
|
4
23
|
def self.find_by_distance(distance)
|
5
24
|
first :conditions => arel_table[:min_distance].lt(distance.to_f).and(arel_table[:max_distance].gteq(distance.to_f))
|
6
25
|
end
|
7
26
|
|
8
|
-
col :name
|
9
|
-
col :distance, :type => :float
|
10
|
-
col :distance_units
|
11
|
-
col :min_distance, :type => :float
|
12
|
-
col :min_distance_units
|
13
|
-
col :max_distance, :type => :float
|
14
|
-
col :max_distance_units
|
15
27
|
|
16
28
|
warn_unless_size 2
|
17
29
|
end
|
@@ -1,4 +1,25 @@
|
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
5
|
+
require 'earth/air/flight_distance_class'
|
6
|
+
require 'earth/air/flight_seat_class'
|
7
|
+
|
1
8
|
class FlightDistanceClassSeatClass < ActiveRecord::Base
|
9
|
+
extend Earth::Model
|
10
|
+
|
11
|
+
TABLE_STRUCTURE = <<-EOS
|
12
|
+
|
13
|
+
CREATE TABLE flight_distance_class_seat_classes
|
14
|
+
(
|
15
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
16
|
+
distance_class_name CHARACTER VARYING(255),
|
17
|
+
seat_class_name CHARACTER VARYING(255),
|
18
|
+
multiplier FLOAT
|
19
|
+
);
|
20
|
+
|
21
|
+
EOS
|
22
|
+
|
2
23
|
self.primary_key = "name"
|
3
24
|
|
4
25
|
belongs_to :seat_class, :class_name => 'FlightSeatClass', :foreign_key => 'seat_class_name'
|
@@ -7,10 +28,6 @@ class FlightDistanceClassSeatClass < ActiveRecord::Base
|
|
7
28
|
falls_back_on :name => 'fallback',
|
8
29
|
:multiplier => 1.0
|
9
30
|
|
10
|
-
col :name
|
11
|
-
col :distance_class_name
|
12
|
-
col :seat_class_name
|
13
|
-
col :multiplier, :type => :float
|
14
31
|
|
15
32
|
warn_unless_size 7
|
16
33
|
end
|
@@ -1,7 +1,19 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class FlightSeatClass < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE flight_seat_classes
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY
|
11
|
+
);
|
12
|
+
|
13
|
+
EOS
|
14
|
+
|
2
15
|
self.primary_key = "name"
|
3
16
|
|
4
|
-
col :name
|
5
17
|
|
6
18
|
warn_unless_size 4
|
7
19
|
end
|
@@ -1,28 +1,62 @@
|
|
1
|
-
require '
|
1
|
+
require 'falls_back_on'
|
2
2
|
require 'fuzzy_match/cached_result'
|
3
3
|
|
4
|
+
require 'earth/model'
|
5
|
+
|
6
|
+
require 'earth/air/aircraft'
|
7
|
+
require 'earth/air/airline'
|
8
|
+
|
4
9
|
class FlightSegment < ActiveRecord::Base
|
5
|
-
|
10
|
+
extend Earth::Model
|
6
11
|
|
7
|
-
|
8
|
-
:primary_key => :bts_code,
|
9
|
-
:foreign_key => :airline_bts_code
|
12
|
+
TABLE_STRUCTURE = <<-EOS
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
CREATE TABLE flight_segments
|
15
|
+
(
|
16
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
17
|
+
origin_airport_iata_code CHARACTER VARYING(255),
|
18
|
+
origin_airport_city CHARACTER VARYING(255),
|
19
|
+
origin_country_iso_3166_code CHARACTER VARYING(255),
|
20
|
+
destination_airport_iata_code CHARACTER VARYING(255),
|
21
|
+
destination_airport_city CHARACTER VARYING(255),
|
22
|
+
destination_country_iso_3166_code CHARACTER VARYING(255),
|
23
|
+
airline_bts_code CHARACTER VARYING(255),
|
24
|
+
airline_icao_code CHARACTER VARYING(255),
|
25
|
+
airline_name CHARACTER VARYING(255), /* text description derived from bts or icao code */
|
26
|
+
aircraft_bts_code CHARACTER VARYING(255),
|
27
|
+
aircraft_description CHARACTER VARYING(255), /* text description derived from BTS T100 or ICAO TFS */
|
28
|
+
flights INTEGER, /* number of flights over month or year */
|
29
|
+
passengers INTEGER, /* total passengers on all flights */
|
30
|
+
seats INTEGER, /* total seats on all flights */
|
31
|
+
seats_per_flight FLOAT, /* average seats per flight */
|
32
|
+
load_factor FLOAT, /* passengers / seats */
|
33
|
+
freight_share FLOAT, /* (freight + mail) / (freight + mail + (passengers * average passenger weight)) */
|
34
|
+
distance FLOAT,
|
35
|
+
distance_units CHARACTER VARYING(255),
|
36
|
+
payload_capacity FLOAT, /* aircraft maximum payload capacity rating */
|
37
|
+
payload_capacity_units CHARACTER VARYING(255),
|
38
|
+
freight FLOAT, /* total freight on all flights performed */
|
39
|
+
freight_units CHARACTER VARYING(255),
|
40
|
+
mail FLOAT, /* total mail on all flights performed */
|
41
|
+
mail_units CHARACTER VARYING(255),
|
42
|
+
month INTEGER,
|
43
|
+
year INTEGER,
|
44
|
+
source CHARACTER VARYING(255) /* 'BTS T100' or 'ICAO TFS' */
|
45
|
+
);
|
46
|
+
CREATE INDEX index_flight_segments_on_origin_airport_iata_code ON flight_segments (origin_airport_iata_code);
|
47
|
+
CREATE INDEX index_flight_segments_on_origin_airport_city ON flight_segments (origin_airport_city);
|
48
|
+
CREATE INDEX index_flight_segments_on_destination_airport_iata_code ON flight_segments (destination_airport_iata_code);
|
49
|
+
CREATE INDEX index_flight_segments_on_destination_airport_city ON flight_segments (destination_airport_city);
|
50
|
+
CREATE INDEX index_flight_segments_on_airline_bts_code ON flight_segments (airline_bts_code);
|
51
|
+
CREATE INDEX index_flight_segments_on_airline_icao_code ON flight_segments (airline_icao_code);
|
52
|
+
CREATE INDEX index_flight_segments_on_airline_name ON flight_segments (airline_name);
|
53
|
+
CREATE INDEX index_flight_segments_on_aircraft_bts_code ON flight_segments (aircraft_bts_code);
|
54
|
+
CREATE INDEX index_flight_segments_on_aircraft_description ON flight_segments (aircraft_description);
|
55
|
+
CREATE INDEX index_flight_segments_on_year ON flight_segments (year)
|
56
|
+
|
57
|
+
EOS
|
58
|
+
|
59
|
+
self.primary_key = "row_hash"
|
26
60
|
|
27
61
|
# Enable flight_segment.aircraft
|
28
62
|
cache_fuzzy_match_with :aircraft, :primary_key => :aircraft_description, :foreign_key => :description
|
@@ -49,45 +83,8 @@ class FlightSegment < ActiveRecord::Base
|
|
49
83
|
:load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78073233770097 data1 10-12-2010
|
50
84
|
:freight_share => lambda { weighted_average(:freight_share, :weighted_by => :passengers) } # 0.022567224170157 data1 10-12-2010
|
51
85
|
|
52
|
-
|
53
|
-
|
54
|
-
col :origin_airport_city # city
|
55
|
-
col :origin_country_iso_3166_code # iso code
|
56
|
-
col :destination_airport_iata_code # iata code
|
57
|
-
col :destination_airport_city # city
|
58
|
-
col :destination_country_iso_3166_code # iso code
|
59
|
-
col :airline_bts_code # bts code
|
60
|
-
col :airline_icao_code # icao code
|
61
|
-
col :airline_name # text description derived from bts or icao code
|
62
|
-
col :aircraft_bts_code # bts code
|
63
|
-
col :aircraft_description # text description derived from BTS T100 or ICAO TFS
|
64
|
-
col :flights, :type => :integer # number of flights over month or year
|
65
|
-
col :passengers, :type => :integer # total passengers on all flights
|
66
|
-
col :seats, :type => :integer # total seats on all flights
|
67
|
-
col :seats_per_flight, :type => :float # average seats per flight; make this a float
|
68
|
-
col :load_factor, :type => :float # passengers / seats
|
69
|
-
col :freight_share, :type => :float # (freight + mail) / (freight + mail + (passengers * average passenger weight))
|
70
|
-
col :distance, :type => :float # flight distance
|
71
|
-
col :distance_units # 'kilometres'
|
72
|
-
col :payload_capacity, :type => :float # aircraft maximum payload capacity rating; float b/c unit conversion
|
73
|
-
col :payload_capacity_units # 'kilograms'
|
74
|
-
col :freight, :type => :float # total freight on all flights performed; float b/c unit conversion
|
75
|
-
col :freight_units # 'kilograms'
|
76
|
-
col :mail, :type => :float # total mail on all flights performed; float b/c unit conversion
|
77
|
-
col :mail_units # 'kilograms'
|
78
|
-
col :month, :type => :integer # month of flight
|
79
|
-
col :year, :type => :integer # year of flight
|
80
|
-
col :source # 'BTS T100' or 'ICAO TFS'
|
81
|
-
add_index :origin_airport_iata_code
|
82
|
-
add_index :origin_airport_city
|
83
|
-
add_index :destination_airport_iata_code
|
84
|
-
add_index :destination_airport_city
|
85
|
-
add_index :airline_bts_code
|
86
|
-
add_index :airline_icao_code
|
87
|
-
add_index :airline_name
|
88
|
-
add_index :aircraft_bts_code
|
89
|
-
add_index :aircraft_description
|
90
|
-
add_index :year
|
86
|
+
# FIXME remove this - wherever you're trying to create a flight segment, just don't use mass-assignment for the primary key
|
87
|
+
attr_accessible :row_hash
|
91
88
|
|
92
89
|
warn_if_nulls_except(
|
93
90
|
:origin_airport_city,
|
@@ -98,4 +95,12 @@ class FlightSegment < ActiveRecord::Base
|
|
98
95
|
)
|
99
96
|
|
100
97
|
warn_unless_size 1_254_412
|
98
|
+
|
99
|
+
def airline
|
100
|
+
if airline_bts_code
|
101
|
+
Airline.where(:bts_code => airline_bts_code).first
|
102
|
+
else
|
103
|
+
Airline.where(:icao_code => airline_icao_code).first
|
104
|
+
end
|
105
|
+
end
|
101
106
|
end
|