earth-ruby19 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/Gemfile.lock +138 -0
- data/LICENSE +20 -0
- data/README.markdown +38 -0
- data/lib/earth.rb +146 -0
- data/lib/earth/active_record_ext.rb +9 -0
- data/lib/earth/air.rb +13 -0
- data/lib/earth/air/aircraft.rb +21 -0
- data/lib/earth/air/aircraft/data_miner.rb +184 -0
- data/lib/earth/air/aircraft_class.rb +10 -0
- data/lib/earth/air/aircraft_class/data_miner.rb +42 -0
- data/lib/earth/air/aircraft_manufacturer.rb +9 -0
- data/lib/earth/air/aircraft_manufacturer/data_miner.rb +20 -0
- data/lib/earth/air/airline.rb +16 -0
- data/lib/earth/air/airline/data_miner.rb +57 -0
- data/lib/earth/air/airport.rb +44 -0
- data/lib/earth/air/airport/data_miner.rb +80 -0
- data/lib/earth/air/data_miner.rb +15 -0
- data/lib/earth/air/flight_configuration.rb +7 -0
- data/lib/earth/air/flight_configuration/data_miner.rb +16 -0
- data/lib/earth/air/flight_distance_class.rb +7 -0
- data/lib/earth/air/flight_distance_class/data_miner.rb +16 -0
- data/lib/earth/air/flight_domesticity.rb +6 -0
- data/lib/earth/air/flight_domesticity/data_miner.rb +57 -0
- data/lib/earth/air/flight_fuel_type.rb +12 -0
- data/lib/earth/air/flight_fuel_type/data_miner.rb +12 -0
- data/lib/earth/air/flight_propulsion.rb +7 -0
- data/lib/earth/air/flight_propulsion/data_miner.rb +16 -0
- data/lib/earth/air/flight_seat_class.rb +12 -0
- data/lib/earth/air/flight_seat_class/data_miner.rb +36 -0
- data/lib/earth/air/flight_segment.rb +29 -0
- data/lib/earth/air/flight_segment/data_miner.rb +330 -0
- data/lib/earth/air/flight_service.rb +7 -0
- data/lib/earth/air/flight_service/data_miner.rb +16 -0
- data/lib/earth/all.rb +11 -0
- data/lib/earth/automobile.rb +8 -0
- data/lib/earth/automobile/automobile_fuel_type.rb +18 -0
- data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +45 -0
- data/lib/earth/automobile/automobile_make.rb +14 -0
- data/lib/earth/automobile/automobile_make/data_miner.rb +68 -0
- data/lib/earth/automobile/automobile_make_fleet_year.rb +15 -0
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +29 -0
- data/lib/earth/automobile/automobile_make_year.rb +14 -0
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +45 -0
- data/lib/earth/automobile/automobile_model.rb +14 -0
- data/lib/earth/automobile/automobile_model/data_miner.rb +38 -0
- data/lib/earth/automobile/automobile_model_year.rb +15 -0
- data/lib/earth/automobile/automobile_model_year/data_miner.rb +51 -0
- data/lib/earth/automobile/automobile_size_class.rb +14 -0
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +43 -0
- data/lib/earth/automobile/automobile_variant.rb +17 -0
- data/lib/earth/automobile/automobile_variant/data_miner.rb +460 -0
- data/lib/earth/automobile/data_miner.rb +8 -0
- data/lib/earth/base.rb +7 -0
- data/lib/earth/bus.rb +1 -0
- data/lib/earth/bus/bus_class.rb +19 -0
- data/lib/earth/bus/bus_class/data_miner.rb +41 -0
- data/lib/earth/bus/data_miner.rb +1 -0
- data/lib/earth/conversions_ext.rb +45 -0
- data/lib/earth/data_miner.rb +10 -0
- data/lib/earth/diet.rb +2 -0
- data/lib/earth/diet/data_miner.rb +2 -0
- data/lib/earth/diet/diet_class.rb +15 -0
- data/lib/earth/diet/diet_class/data_miner.rb +36 -0
- data/lib/earth/diet/food_group.rb +17 -0
- data/lib/earth/diet/food_group/data_miner.rb +26 -0
- data/lib/earth/fuel.rb +2 -0
- data/lib/earth/fuel/data_miner.rb +2 -0
- data/lib/earth/fuel/fuel_price.rb +13 -0
- data/lib/earth/fuel/fuel_price/data_miner.rb +20 -0
- data/lib/earth/fuel/fuel_type.rb +18 -0
- data/lib/earth/fuel/fuel_type/data_miner.rb +37 -0
- data/lib/earth/hospitality.rb +1 -0
- data/lib/earth/hospitality/data_miner.rb +1 -0
- data/lib/earth/hospitality/lodging_class.rb +9 -0
- data/lib/earth/hospitality/lodging_class/data_miner.rb +30 -0
- data/lib/earth/industry.rb +10 -0
- data/lib/earth/industry/industry.rb +23 -0
- data/lib/earth/industry/industry_product.rb +22 -0
- data/lib/earth/industry/industry_product_line.rb +20 -0
- data/lib/earth/industry/industry_sector.rb +20 -0
- data/lib/earth/industry/merchant.rb +18 -0
- data/lib/earth/industry/merchant_category.rb +22 -0
- data/lib/earth/industry/merchant_category_industry.rb +20 -0
- data/lib/earth/industry/product_line.rb +22 -0
- data/lib/earth/industry/product_line_industry_product.rb +20 -0
- data/lib/earth/industry/sector.rb +19 -0
- data/lib/earth/inflectors.rb +9 -0
- data/lib/earth/locality.rb +10 -0
- data/lib/earth/locality/census_division.rb +22 -0
- data/lib/earth/locality/census_division/data_miner.rb +64 -0
- data/lib/earth/locality/census_region.rb +13 -0
- data/lib/earth/locality/census_region/data_miner.rb +17 -0
- data/lib/earth/locality/climate_division.rb +17 -0
- data/lib/earth/locality/climate_division/data_miner.rb +20 -0
- data/lib/earth/locality/country.rb +13 -0
- data/lib/earth/locality/country/data_miner.rb +19 -0
- data/lib/earth/locality/data_miner.rb +10 -0
- data/lib/earth/locality/egrid_region.rb +15 -0
- data/lib/earth/locality/egrid_region/data_miner.rb +35 -0
- data/lib/earth/locality/egrid_subregion.rb +16 -0
- data/lib/earth/locality/egrid_subregion/data_miner.rb +65 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +13 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +21 -0
- data/lib/earth/locality/state.rb +22 -0
- data/lib/earth/locality/state/data_miner.rb +37 -0
- data/lib/earth/locality/urbanity.rb +10 -0
- data/lib/earth/locality/urbanity/data_miner.rb +15 -0
- data/lib/earth/locality/zip_code.rb +23 -0
- data/lib/earth/locality/zip_code/data_miner.rb +43 -0
- data/lib/earth/pet.rb +4 -0
- data/lib/earth/pet/breed.rb +15 -0
- data/lib/earth/pet/breed/data_miner.rb +25 -0
- data/lib/earth/pet/breed_gender.rb +14 -0
- data/lib/earth/pet/breed_gender/data_miner.rb +21 -0
- data/lib/earth/pet/data_miner.rb +4 -0
- data/lib/earth/pet/gender.rb +10 -0
- data/lib/earth/pet/gender/data_miner.rb +13 -0
- data/lib/earth/pet/species.rb +40 -0
- data/lib/earth/pet/species/data_miner.rb +42 -0
- data/lib/earth/rail.rb +1 -0
- data/lib/earth/rail/data_miner.rb +1 -0
- data/lib/earth/rail/rail_class.rb +16 -0
- data/lib/earth/rail/rail_class/data_miner.rb +36 -0
- data/lib/earth/residence.rb +8 -0
- data/lib/earth/residence/air_conditioner_use.rb +13 -0
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +22 -0
- data/lib/earth/residence/clothes_machine_use.rb +10 -0
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +28 -0
- data/lib/earth/residence/data_miner.rb +8 -0
- data/lib/earth/residence/dishwasher_use.rb +10 -0
- data/lib/earth/residence/dishwasher_use/data_miner.rb +28 -0
- data/lib/earth/residence/residence_appliance.rb +16 -0
- data/lib/earth/residence/residence_appliance/data_miner.rb +20 -0
- data/lib/earth/residence/residence_class.rb +16 -0
- data/lib/earth/residence/residence_class/data_miner.rb +15 -0
- data/lib/earth/residence/residence_fuel_price.rb +18 -0
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +200 -0
- data/lib/earth/residence/residence_fuel_type.rb +32 -0
- data/lib/earth/residence/residence_fuel_type/data_miner.rb +18 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +39 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +283 -0
- data/spec/lib/earth_spec.rb +25 -0
- data/spec/spec_helper.rb +11 -0
- data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
- data/vendor/geokit-rails/MIT-LICENSE +20 -0
- data/vendor/geokit-rails/README.markdown +561 -0
- data/vendor/geokit-rails/Rakefile +18 -0
- data/vendor/geokit-rails/about.yml +9 -0
- data/vendor/geokit-rails/assets/api_keys_template +61 -0
- data/vendor/geokit-rails/init.rb +1 -0
- data/vendor/geokit-rails/install.rb +14 -0
- data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
- data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
- data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
- data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
- data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
- data/vendor/geokit-rails/test/boot.rb +25 -0
- data/vendor/geokit-rails/test/database.yml +20 -0
- data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
- data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
- data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
- data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
- data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
- data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
- data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
- data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
- data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
- data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
- data/vendor/geokit-rails/test/models/company.rb +3 -0
- data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
- data/vendor/geokit-rails/test/models/location.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
- data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
- data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
- data/vendor/geokit-rails/test/models/store.rb +3 -0
- data/vendor/geokit-rails/test/schema.rb +60 -0
- data/vendor/geokit-rails/test/tasks.rake +31 -0
- data/vendor/geokit-rails/test/test_helper.rb +23 -0
- metadata +476 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
FlightPropulsion.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema do
|
4
|
+
string 'name'
|
5
|
+
string 'bts_aircraft_group_code'
|
6
|
+
end
|
7
|
+
|
8
|
+
process "derive from flight segments" do
|
9
|
+
FlightSegment.run_data_miner!
|
10
|
+
connection.execute %{
|
11
|
+
INSERT IGNORE INTO flight_propulsions(name, bts_aircraft_group_code)
|
12
|
+
SELECT flight_segments.propulsion_id, flight_segments.bts_aircraft_group_code FROM flight_segments WHERE LENGTH(flight_segments.propulsion_id) > 0
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class FlightSeatClass < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
# has_many :airline_seat_classes, :class_name => 'AirlineSeatClass'
|
4
|
+
# has_many :aircraft_seat_classes, :class_name => 'AircraftSeatClass'
|
5
|
+
# has_many :airline_aircraft_seat_classes, :class_name => 'AirlineAircraftSeatClass'
|
6
|
+
|
7
|
+
falls_back_on :multiplier => 1
|
8
|
+
|
9
|
+
data_miner do
|
10
|
+
tap "Brighter Planet's sanitized flight seat class data", Earth.taps_server
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
FlightSeatClass.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
float 'multiplier'
|
6
|
+
integer 'seats'
|
7
|
+
end
|
8
|
+
|
9
|
+
import "a list of Brighter Planet-defined seat classes and pre-calculated multipliers",
|
10
|
+
:url => 'http://static.brighterplanet.com/science/data/transport/air/seat_classes/seat_classes.csv' do
|
11
|
+
key 'name'
|
12
|
+
store 'multiplier'
|
13
|
+
end
|
14
|
+
|
15
|
+
# sabshere 5/21/10 in case we ever need this
|
16
|
+
# class << self
|
17
|
+
# def refresh
|
18
|
+
# update_all_weighted_averages(:seats, :weighted_by => :airline_aircraft_seat_classes)
|
19
|
+
# update_all_weighted_averages(:multiplier, :weighted_by => :airline_aircraft_seat_classes)
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def safe_find_by_name(name)
|
23
|
+
# guess = case name.to_s.downcase.gsub(/[^a-z]/, '')
|
24
|
+
# when /first/
|
25
|
+
# 'first'
|
26
|
+
# when /busi/, /exec/
|
27
|
+
# 'business'
|
28
|
+
# when /econ/, /coach/
|
29
|
+
# 'economy'
|
30
|
+
# end
|
31
|
+
# find_or_create_by_name(guess) unless guess.nil?
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class FlightSegment < ActiveRecord::Base
|
2
|
+
set_primary_key :row_hash
|
3
|
+
|
4
|
+
extend CohortScope
|
5
|
+
self.minimum_cohort_size = 1
|
6
|
+
|
7
|
+
belongs_to :airline, :foreign_key => 'airline_iata_code'
|
8
|
+
belongs_to :origin_airport, :foreign_key => "origin_airport_iata_code", :class_name => 'Airport'
|
9
|
+
belongs_to :destination_airport, :foreign_key => "dest_airport_iata_code", :class_name => 'Airport'
|
10
|
+
belongs_to :origin_country, :foreign_key => 'origin_country_iso_3166_code', :class_name => 'Country'
|
11
|
+
belongs_to :destination_country, :foreign_key => 'dest_country_iso_3166_code', :class_name => 'Country'
|
12
|
+
belongs_to :aircraft, :foreign_key => 'bts_aircraft_type_code', :primary_key => 'bts_aircraft_type_code'
|
13
|
+
belongs_to :propulsion, :class_name => 'FlightPropulsion'
|
14
|
+
belongs_to :configuration, :class_name => 'FlightConfiguration'
|
15
|
+
belongs_to :service_class, :class_name => 'FlightService'
|
16
|
+
belongs_to :domesticity, :class_name => 'FlightDomesticity'
|
17
|
+
|
18
|
+
falls_back_on :load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78222911236768
|
19
|
+
:freight_share => lambda { weighted_average(:freight_share, :weighted_by => :passengers) }, # 0.024017329363736
|
20
|
+
:seats => lambda { weighted_average :seats, :weighted_by => :passengers }
|
21
|
+
|
22
|
+
data_miner do
|
23
|
+
tap "Brighter Planet's sanitized T100 data", Earth.taps_server
|
24
|
+
|
25
|
+
process "pull dependencies" do
|
26
|
+
run_data_miner_on_belongs_to_associations
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,330 @@
|
|
1
|
+
FlightSegment.class_eval do
|
2
|
+
URL = 'http://www.transtats.bts.gov/DownLoad_Table.asp?Table_ID=293&Has_Group=3&Is_Zipped=0'
|
3
|
+
FORM_DATA = %{
|
4
|
+
UserTableName=T_100_Segment__All_Carriers&
|
5
|
+
DBShortName=Air_Carriers&
|
6
|
+
RawDataTable=T_T100_SEGMENT_ALL_CARRIER&
|
7
|
+
sqlstr=+SELECT+DEPARTURES_SCHEDULED%2CDEPARTURES_PERFORMED%2CPAYLOAD%2CSEATS%2CPASSENGERS%2CFREIGHT%2CMAIL%2CDISTANCE%2CRAMP_TO_RAMP%2CAIR_TIME%2CUNIQUE_CARRIER%2CAIRLINE_ID%2CUNIQUE_CARRIER_NAME%2CUNIQUE_CARRIER_ENTITY%2CREGION%2CCARRIER%2CCARRIER_NAME%2CCARRIER_GROUP%2CCARRIER_GROUP_NEW%2CORIGIN%2CORIGIN_CITY_NAME%2CORIGIN_CITY_NUM%2CORIGIN_STATE_ABR%2CORIGIN_STATE_FIPS%2CORIGIN_STATE_NM%2CORIGIN_COUNTRY%2CORIGIN_COUNTRY_NAME%2CORIGIN_WAC%2CDEST%2CDEST_CITY_NAME%2CDEST_CITY_NUM%2CDEST_STATE_ABR%2CDEST_STATE_FIPS%2CDEST_STATE_NM%2CDEST_COUNTRY%2CDEST_COUNTRY_NAME%2CDEST_WAC%2CAIRCRAFT_GROUP%2CAIRCRAFT_TYPE%2CAIRCRAFT_CONFIG%2CYEAR%2CQUARTER%2CMONTH%2CDISTANCE_GROUP%2CCLASS%2CDATA_SOURCE+FROM++T_T100_SEGMENT_ALL_CARRIER+WHERE+Month+%3D__MONTH_NUMBER__+AND+YEAR%3D__YEAR__&
|
8
|
+
varlist=DEPARTURES_SCHEDULED%2CDEPARTURES_PERFORMED%2CPAYLOAD%2CSEATS%2CPASSENGERS%2CFREIGHT%2CMAIL%2CDISTANCE%2CRAMP_TO_RAMP%2CAIR_TIME%2CUNIQUE_CARRIER%2CAIRLINE_ID%2CUNIQUE_CARRIER_NAME%2CUNIQUE_CARRIER_ENTITY%2CREGION%2CCARRIER%2CCARRIER_NAME%2CCARRIER_GROUP%2CCARRIER_GROUP_NEW%2CORIGIN%2CORIGIN_CITY_NAME%2CORIGIN_CITY_NUM%2CORIGIN_STATE_ABR%2CORIGIN_STATE_FIPS%2CORIGIN_STATE_NM%2CORIGIN_COUNTRY%2CORIGIN_COUNTRY_NAME%2CORIGIN_WAC%2CDEST%2CDEST_CITY_NAME%2CDEST_CITY_NUM%2CDEST_STATE_ABR%2CDEST_STATE_FIPS%2CDEST_STATE_NM%2CDEST_COUNTRY%2CDEST_COUNTRY_NAME%2CDEST_WAC%2CAIRCRAFT_GROUP%2CAIRCRAFT_TYPE%2CAIRCRAFT_CONFIG%2CYEAR%2CQUARTER%2CMONTH%2CDISTANCE_GROUP%2CCLASS%2CDATA_SOURCE&
|
9
|
+
grouplist=&
|
10
|
+
suml=&
|
11
|
+
sumRegion=&
|
12
|
+
filter1=title%3D&
|
13
|
+
filter2=title%3D&
|
14
|
+
geo=All%A0&
|
15
|
+
time=__MONTH_NAME__&
|
16
|
+
timename=Month&
|
17
|
+
GEOGRAPHY=All&
|
18
|
+
XYEAR=__YEAR__&
|
19
|
+
FREQUENCY=__MONTH_NUMBER__&
|
20
|
+
AllVars=All&
|
21
|
+
VarName=DEPARTURES_SCHEDULED&
|
22
|
+
VarDesc=DepScheduled&
|
23
|
+
VarType=Num&
|
24
|
+
VarName=DEPARTURES_PERFORMED&
|
25
|
+
VarDesc=DepPerformed&
|
26
|
+
VarType=Num&
|
27
|
+
VarName=PAYLOAD&
|
28
|
+
VarDesc=Payload&
|
29
|
+
VarType=Num&
|
30
|
+
VarName=SEATS&
|
31
|
+
VarDesc=Seats&
|
32
|
+
VarType=Num&
|
33
|
+
VarName=PASSENGERS&
|
34
|
+
VarDesc=Passengers&
|
35
|
+
VarType=Num&
|
36
|
+
VarName=FREIGHT&
|
37
|
+
VarDesc=Freight&
|
38
|
+
VarType=Num&
|
39
|
+
VarName=MAIL&
|
40
|
+
VarDesc=Mail&
|
41
|
+
VarType=Num&
|
42
|
+
VarName=DISTANCE&
|
43
|
+
VarDesc=Distance&
|
44
|
+
VarType=Num&
|
45
|
+
VarName=RAMP_TO_RAMP&
|
46
|
+
VarDesc=RampToRamp&
|
47
|
+
VarType=Num&
|
48
|
+
VarName=AIR_TIME&
|
49
|
+
VarDesc=AirTime&
|
50
|
+
VarType=Num&
|
51
|
+
VarName=UNIQUE_CARRIER&
|
52
|
+
VarDesc=UniqueCarrier&
|
53
|
+
VarType=Char&
|
54
|
+
VarName=AIRLINE_ID&
|
55
|
+
VarDesc=AirlineID&
|
56
|
+
VarType=Num&
|
57
|
+
VarName=UNIQUE_CARRIER_NAME&
|
58
|
+
VarDesc=UniqueCarrierName&
|
59
|
+
VarType=Char&
|
60
|
+
VarName=UNIQUE_CARRIER_ENTITY&
|
61
|
+
VarDesc=UniqCarrierEntity&
|
62
|
+
VarType=Char&
|
63
|
+
VarName=REGION&
|
64
|
+
VarDesc=CarrierRegion&
|
65
|
+
VarType=Char&
|
66
|
+
VarName=CARRIER&
|
67
|
+
VarDesc=Carrier&
|
68
|
+
VarType=Char&
|
69
|
+
VarName=CARRIER_NAME&
|
70
|
+
VarDesc=CarrierName&
|
71
|
+
VarType=Char&
|
72
|
+
VarName=CARRIER_GROUP&
|
73
|
+
VarDesc=CarrierGroup&
|
74
|
+
VarType=Num&
|
75
|
+
VarName=CARRIER_GROUP_NEW&
|
76
|
+
VarDesc=CarrierGroupNew&
|
77
|
+
VarType=Num&
|
78
|
+
VarName=ORIGIN&
|
79
|
+
VarDesc=Origin&
|
80
|
+
VarType=Char&
|
81
|
+
VarName=ORIGIN_CITY_NAME&
|
82
|
+
VarDesc=OriginCityName&
|
83
|
+
VarType=Char&
|
84
|
+
VarName=ORIGIN_CITY_NUM&
|
85
|
+
VarDesc=OriginCityNum&
|
86
|
+
VarType=Num&
|
87
|
+
VarName=ORIGIN_STATE_ABR&
|
88
|
+
VarDesc=OriginState&
|
89
|
+
VarType=Char&
|
90
|
+
VarName=ORIGIN_STATE_FIPS&
|
91
|
+
VarDesc=OriginStateFips&
|
92
|
+
VarType=Char&
|
93
|
+
VarName=ORIGIN_STATE_NM&
|
94
|
+
VarDesc=OriginStateName&
|
95
|
+
VarType=Char&
|
96
|
+
VarName=ORIGIN_COUNTRY&
|
97
|
+
VarDesc=OriginCountry&
|
98
|
+
VarType=Char&
|
99
|
+
VarName=ORIGIN_COUNTRY_NAME&
|
100
|
+
VarDesc=OriginCountryName&
|
101
|
+
VarType=Char&
|
102
|
+
VarName=ORIGIN_WAC&
|
103
|
+
VarDesc=OriginWac&
|
104
|
+
VarType=Num&
|
105
|
+
VarName=DEST&
|
106
|
+
VarDesc=Dest&
|
107
|
+
VarType=Char&
|
108
|
+
VarName=DEST_CITY_NAME&
|
109
|
+
VarDesc=DestCityName&
|
110
|
+
VarType=Char&
|
111
|
+
VarName=DEST_CITY_NUM&
|
112
|
+
VarDesc=DestCityNum&
|
113
|
+
VarType=Num&
|
114
|
+
VarName=DEST_STATE_ABR&
|
115
|
+
VarDesc=DestState&
|
116
|
+
VarType=Char&
|
117
|
+
VarName=DEST_STATE_FIPS&
|
118
|
+
VarDesc=DestStateFips&
|
119
|
+
VarType=Char&
|
120
|
+
VarName=DEST_STATE_NM&
|
121
|
+
VarDesc=DestStateName&
|
122
|
+
VarType=Char&
|
123
|
+
VarName=DEST_COUNTRY&
|
124
|
+
VarDesc=DestCountry&
|
125
|
+
VarType=Char&
|
126
|
+
VarName=DEST_COUNTRY_NAME&
|
127
|
+
VarDesc=DestCountryName&
|
128
|
+
VarType=Char&
|
129
|
+
VarName=DEST_WAC&
|
130
|
+
VarDesc=DestWac&
|
131
|
+
VarType=Num&
|
132
|
+
VarName=AIRCRAFT_GROUP&
|
133
|
+
VarDesc=AircraftGroup&
|
134
|
+
VarType=Num&
|
135
|
+
VarName=AIRCRAFT_TYPE&
|
136
|
+
VarDesc=AircraftType&
|
137
|
+
VarType=Char&
|
138
|
+
VarName=AIRCRAFT_CONFIG&
|
139
|
+
VarDesc=AircraftConfig&
|
140
|
+
VarType=Num&
|
141
|
+
VarName=YEAR&
|
142
|
+
VarDesc=Year&
|
143
|
+
VarType=Num&
|
144
|
+
VarName=QUARTER&
|
145
|
+
VarDesc=Quarter&
|
146
|
+
VarType=Num&
|
147
|
+
VarName=MONTH&
|
148
|
+
VarDesc=Month&
|
149
|
+
VarType=Num&
|
150
|
+
VarName=DISTANCE_GROUP&
|
151
|
+
VarDesc=DistanceGroup&
|
152
|
+
VarType=Num&
|
153
|
+
VarName=CLASS&
|
154
|
+
VarDesc=Class&
|
155
|
+
VarType=Char&
|
156
|
+
VarName=DATA_SOURCE&
|
157
|
+
VarDesc=DataSource&
|
158
|
+
VarType=Char
|
159
|
+
}.gsub /[\s]+/,''
|
160
|
+
|
161
|
+
data_miner do
|
162
|
+
schema Earth.database_options do
|
163
|
+
string 'row_hash'
|
164
|
+
string 'propulsion_id'
|
165
|
+
integer 'bts_aircraft_group_code'
|
166
|
+
string 'configuration_id'
|
167
|
+
integer 'bts_aircraft_configuration_code'
|
168
|
+
string 'distance_group'
|
169
|
+
integer 'bts_distance_group_code'
|
170
|
+
string 'service_class_id'
|
171
|
+
string 'bts_service_class_code'
|
172
|
+
string 'domesticity_id'
|
173
|
+
string 'bts_data_source_code'
|
174
|
+
integer 'departures_performed'
|
175
|
+
integer 'payload'
|
176
|
+
integer 'total_seats'
|
177
|
+
integer 'passengers'
|
178
|
+
integer 'freight'
|
179
|
+
integer 'mail'
|
180
|
+
integer 'ramp_to_ramp'
|
181
|
+
integer 'air_time'
|
182
|
+
float 'load_factor'
|
183
|
+
float 'freight_share'
|
184
|
+
integer 'distance'
|
185
|
+
integer 'departures_scheduled'
|
186
|
+
string 'airline_iata_code'
|
187
|
+
string 'dot_airline_id_code'
|
188
|
+
string 'unique_carrier_name'
|
189
|
+
string 'unique_carrier_entity'
|
190
|
+
string 'region'
|
191
|
+
string 'current_airline_iata_code'
|
192
|
+
string 'carrier_name'
|
193
|
+
integer 'carrier_group'
|
194
|
+
integer 'carrier_group_new'
|
195
|
+
string 'origin_airport_iata_code'
|
196
|
+
string 'origin_city_name'
|
197
|
+
integer 'origin_city_num'
|
198
|
+
string 'origin_state_abr'
|
199
|
+
string 'origin_state_fips'
|
200
|
+
string 'origin_state_nm'
|
201
|
+
string 'origin_country_iso_3166_code'
|
202
|
+
string 'origin_country_name'
|
203
|
+
integer 'origin_wac'
|
204
|
+
string 'dest_airport_iata_code'
|
205
|
+
string 'dest_city_name'
|
206
|
+
integer 'dest_city_num'
|
207
|
+
string 'dest_state_abr'
|
208
|
+
string 'dest_state_fips'
|
209
|
+
string 'dest_state_nm'
|
210
|
+
string 'dest_country_iso_3166_code'
|
211
|
+
string 'dest_country_name'
|
212
|
+
integer 'dest_wac'
|
213
|
+
integer 'bts_aircraft_type_code'
|
214
|
+
integer 'year'
|
215
|
+
integer 'quarter'
|
216
|
+
integer 'month'
|
217
|
+
float 'seats'
|
218
|
+
string 'payload_units'
|
219
|
+
string 'freight_units'
|
220
|
+
string 'mail_units'
|
221
|
+
string 'distance_units'
|
222
|
+
index 'airline_iata_code'
|
223
|
+
index 'bts_aircraft_type_code'
|
224
|
+
index 'origin_airport_iata_code'
|
225
|
+
index 'dest_airport_iata_code'
|
226
|
+
index 'domesticity_id'
|
227
|
+
# add_index "flight_segments", ["flight_airline_id", "origin_airport_id", "destination_airport_id", "flight_configuration_id", "flight_aircraft_id", "flight_propulsion_id", "flight_service_id", "origin_country_id", "destination_country_id"], :name => "super_4_index"
|
228
|
+
end
|
229
|
+
|
230
|
+
months = Hash.new
|
231
|
+
(2008..2009).each do |year|
|
232
|
+
# (2008..2008).each do |year| # DEBUG MODE!
|
233
|
+
(1..12).each do |month|
|
234
|
+
# (1..1).each do |month| # DEBUG MODE!
|
235
|
+
time = Time.gm year, month
|
236
|
+
form_data = FORM_DATA.dup
|
237
|
+
form_data.gsub! '__YEAR__', time.year.to_s
|
238
|
+
form_data.gsub! '__MONTH_NUMBER__', time.month.to_s
|
239
|
+
form_data.gsub! '__MONTH_NAME__', time.strftime('%B')
|
240
|
+
months[time] = form_data
|
241
|
+
end
|
242
|
+
end
|
243
|
+
# creating dictionaries by hand so that a new one doesn't get created for every month
|
244
|
+
propulsion_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_GROUP'
|
245
|
+
configuration_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_CONFIG'
|
246
|
+
distance_group_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DISTANCE_GROUP_500'
|
247
|
+
service_class_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_SERVICE_CLASS'
|
248
|
+
domesticity_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DATA_SOURCE'
|
249
|
+
months.each do |month, form_data|
|
250
|
+
import "T100 flight segment data from #{month.strftime('%B %Y')}",
|
251
|
+
:url => URL,
|
252
|
+
:form_data => form_data,
|
253
|
+
:compression => :zip,
|
254
|
+
:glob => '/*.csv' do
|
255
|
+
|
256
|
+
key 'row_hash'
|
257
|
+
|
258
|
+
store 'propulsion_id', :field_name => 'AIRCRAFT_GROUP', :dictionary => propulsion_dictionary
|
259
|
+
store 'bts_aircraft_group_code', :field_name => 'AIRCRAFT_GROUP'
|
260
|
+
|
261
|
+
store 'configuration_id', :field_name => 'AIRCRAFT_CONFIG', :dictionary => configuration_dictionary
|
262
|
+
store 'bts_aircraft_configuration_code', :field_name => 'AIRCRAFT_CONFIG'
|
263
|
+
|
264
|
+
store 'distance_group', :field_name => 'DISTANCE_GROUP', :dictionary => distance_group_dictionary
|
265
|
+
store 'bts_distance_group_code', :field_name => 'DISTANCE_GROUP'
|
266
|
+
|
267
|
+
store 'service_class_id', :field_name => 'CLASS', :dictionary => service_class_dictionary
|
268
|
+
store 'bts_service_class_code', :field_name => 'CLASS'
|
269
|
+
|
270
|
+
store 'domesticity_id', :field_name => 'DATA_SOURCE', :dictionary => domesticity_dictionary
|
271
|
+
store 'bts_data_source_code', :field_name => 'DATA_SOURCE'
|
272
|
+
|
273
|
+
store 'departures_scheduled', :field_name => 'DEPARTURES_SCHEDULED'
|
274
|
+
store 'departures_performed', :field_name => 'DEPARTURES_PERFORMED'
|
275
|
+
store 'payload', :field_name => 'PAYLOAD', :from_units => :pounds, :to_units => :kilograms
|
276
|
+
store 'total_seats', :field_name => 'SEATS'
|
277
|
+
store 'passengers', :field_name => 'PASSENGERS'
|
278
|
+
store 'freight', :field_name => 'FREIGHT', :from_units => :pounds, :to_units => :kilograms
|
279
|
+
store 'mail', :field_name => 'MAIL', :from_units => :pounds, :to_units => :kilograms
|
280
|
+
store 'distance', :field_name => 'DISTANCE', :from_units => :miles, :to_units => :kilometres
|
281
|
+
store 'ramp_to_ramp', :field_name => 'RAMP_TO_RAMP'
|
282
|
+
store 'air_time', :field_name => 'AIR_TIME'
|
283
|
+
store 'airline_iata_code', :field_name => 'UNIQUE_CARRIER' # adjusted for uniqueness
|
284
|
+
store 'dot_airline_id_code', :field_name => 'AIRLINE_ID'
|
285
|
+
store 'unique_carrier_name', :field_name => 'UNIQUE_CARRIER_NAME'
|
286
|
+
store 'unique_carrier_entity', :field_name => 'UNIQUE_CARRIER_ENTITY'
|
287
|
+
store 'region', :field_name => 'REGION'
|
288
|
+
store 'current_airline_iata_code', :field_name => 'CARRIER'
|
289
|
+
store 'carrier_name', :field_name => 'CARRIER_NAME'
|
290
|
+
store 'carrier_group', :field_name => 'CARRIER_GROUP'
|
291
|
+
store 'carrier_group_new', :field_name => 'CARRIER_GROUP_NEW'
|
292
|
+
store 'origin_airport_iata_code', :field_name => 'ORIGIN'
|
293
|
+
store 'origin_city_name', :field_name => 'ORIGIN_CITY_NAME'
|
294
|
+
store 'origin_city_num', :field_name => 'ORIGIN_CITY_NUM'
|
295
|
+
store 'origin_state_abr', :field_name => 'ORIGIN_STATE_ABR'
|
296
|
+
store 'origin_state_fips', :field_name => 'ORIGIN_STATE_FIPS'
|
297
|
+
store 'origin_state_nm', :field_name => 'ORIGIN_STATE_NM'
|
298
|
+
store 'origin_country_iso_3166_code', :field_name => 'ORIGIN_COUNTRY'
|
299
|
+
store 'origin_country_name', :field_name => 'ORIGIN_COUNTRY_NAME'
|
300
|
+
store 'origin_wac', :field_name => 'ORIGIN_WAC'
|
301
|
+
store 'dest_airport_iata_code', :field_name => 'DEST'
|
302
|
+
store 'dest_city_name', :field_name => 'DEST_CITY_NAME'
|
303
|
+
store 'dest_city_num', :field_name => 'DEST_CITY_NUM'
|
304
|
+
store 'dest_state_abr', :field_name => 'DEST_STATE_ABR'
|
305
|
+
store 'dest_state_fips', :field_name => 'DEST_STATE_FIPS'
|
306
|
+
store 'dest_state_nm', :field_name => 'DEST_STATE_NM'
|
307
|
+
store 'dest_country_iso_3166_code', :field_name => 'DEST_COUNTRY'
|
308
|
+
store 'dest_country_name', :field_name => 'DEST_COUNTRY_NAME'
|
309
|
+
store 'dest_wac', :field_name => 'DEST_WAC'
|
310
|
+
store 'bts_aircraft_type_code', :field_name => 'AIRCRAFT_TYPE' # lol no dictionary please
|
311
|
+
store 'year', :field_name => 'YEAR'
|
312
|
+
store 'quarter', :field_name => 'QUARTER'
|
313
|
+
store 'month', :field_name => 'MONTH'
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
process "Derive freight share as a fraction of payload" do
|
318
|
+
update_all 'freight_share = (freight + mail) / payload', 'payload > 0'
|
319
|
+
end
|
320
|
+
|
321
|
+
process "Derive load factor, which is passengers divided by the total seats available" do
|
322
|
+
update_all 'load_factor = passengers / total_seats', 'passengers <= total_seats'
|
323
|
+
end
|
324
|
+
|
325
|
+
process "Derive average seats per departure" do
|
326
|
+
update_all 'seats = total_seats / departures_performed', 'departures_performed > 0'
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
FlightService.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema do
|
4
|
+
string 'name'
|
5
|
+
string 'bts_service_class_code'
|
6
|
+
end
|
7
|
+
|
8
|
+
process "derive from flight segments" do
|
9
|
+
FlightSegment.run_data_miner!
|
10
|
+
connection.execute %{
|
11
|
+
INSERT IGNORE INTO flight_services(name, bts_service_class_code)
|
12
|
+
SELECT flight_segments.service_class_id, flight_segments.bts_service_class_code FROM flight_segments WHERE LENGTH(flight_segments.service_class_id) > 0
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|