earth 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/.rvmrc +8 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +38 -0
  7. data/Rakefile +71 -0
  8. data/VERSION +1 -0
  9. data/earth.gemspec +265 -0
  10. data/lib/earth.rb +169 -0
  11. data/lib/earth/air.rb +13 -0
  12. data/lib/earth/air/aircraft.rb +32 -0
  13. data/lib/earth/air/aircraft/data_miner.rb +171 -0
  14. data/lib/earth/air/aircraft_class.rb +10 -0
  15. data/lib/earth/air/aircraft_class/data_miner.rb +42 -0
  16. data/lib/earth/air/aircraft_manufacturer.rb +9 -0
  17. data/lib/earth/air/aircraft_manufacturer/data_miner.rb +20 -0
  18. data/lib/earth/air/airline.rb +16 -0
  19. data/lib/earth/air/airline/data_miner.rb +57 -0
  20. data/lib/earth/air/airport.rb +44 -0
  21. data/lib/earth/air/airport/data_miner.rb +80 -0
  22. data/lib/earth/air/data_miner.rb +15 -0
  23. data/lib/earth/air/flight_configuration.rb +18 -0
  24. data/lib/earth/air/flight_configuration/data_miner.rb +4 -0
  25. data/lib/earth/air/flight_distance_class.rb +7 -0
  26. data/lib/earth/air/flight_distance_class/data_miner.rb +16 -0
  27. data/lib/earth/air/flight_domesticity.rb +6 -0
  28. data/lib/earth/air/flight_domesticity/data_miner.rb +57 -0
  29. data/lib/earth/air/flight_fuel_type.rb +17 -0
  30. data/lib/earth/air/flight_fuel_type/data_miner.rb +4 -0
  31. data/lib/earth/air/flight_propulsion.rb +18 -0
  32. data/lib/earth/air/flight_propulsion/data_miner.rb +4 -0
  33. data/lib/earth/air/flight_seat_class.rb +12 -0
  34. data/lib/earth/air/flight_seat_class/data_miner.rb +36 -0
  35. data/lib/earth/air/flight_segment.rb +38 -0
  36. data/lib/earth/air/flight_segment/data_miner.rb +334 -0
  37. data/lib/earth/air/flight_service.rb +18 -0
  38. data/lib/earth/air/flight_service/data_miner.rb +4 -0
  39. data/lib/earth/all.rb +10 -0
  40. data/lib/earth/automobile.rb +8 -0
  41. data/lib/earth/automobile/automobile_fuel_type.rb +18 -0
  42. data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +45 -0
  43. data/lib/earth/automobile/automobile_make.rb +14 -0
  44. data/lib/earth/automobile/automobile_make/data_miner.rb +68 -0
  45. data/lib/earth/automobile/automobile_make_fleet_year.rb +15 -0
  46. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +29 -0
  47. data/lib/earth/automobile/automobile_make_year.rb +14 -0
  48. data/lib/earth/automobile/automobile_make_year/data_miner.rb +45 -0
  49. data/lib/earth/automobile/automobile_model.rb +14 -0
  50. data/lib/earth/automobile/automobile_model/data_miner.rb +38 -0
  51. data/lib/earth/automobile/automobile_model_year.rb +15 -0
  52. data/lib/earth/automobile/automobile_model_year/data_miner.rb +51 -0
  53. data/lib/earth/automobile/automobile_size_class.rb +14 -0
  54. data/lib/earth/automobile/automobile_size_class/data_miner.rb +43 -0
  55. data/lib/earth/automobile/automobile_variant.rb +17 -0
  56. data/lib/earth/automobile/automobile_variant/data_miner.rb +464 -0
  57. data/lib/earth/automobile/data_miner.rb +8 -0
  58. data/lib/earth/bus.rb +1 -0
  59. data/lib/earth/bus/bus_class.rb +19 -0
  60. data/lib/earth/bus/bus_class/data_miner.rb +41 -0
  61. data/lib/earth/bus/data_miner.rb +1 -0
  62. data/lib/earth/conversions_ext.rb +45 -0
  63. data/lib/earth/data_miner.rb +10 -0
  64. data/lib/earth/diet.rb +2 -0
  65. data/lib/earth/diet/data_miner.rb +2 -0
  66. data/lib/earth/diet/diet_class.rb +15 -0
  67. data/lib/earth/diet/diet_class/data_miner.rb +36 -0
  68. data/lib/earth/diet/food_group.rb +17 -0
  69. data/lib/earth/diet/food_group/data_miner.rb +26 -0
  70. data/lib/earth/fuel.rb +2 -0
  71. data/lib/earth/fuel/data_miner.rb +2 -0
  72. data/lib/earth/fuel/fuel_price.rb +13 -0
  73. data/lib/earth/fuel/fuel_price/data_miner.rb +20 -0
  74. data/lib/earth/fuel/fuel_type.rb +18 -0
  75. data/lib/earth/fuel/fuel_type/data_miner.rb +37 -0
  76. data/lib/earth/industry.rb +10 -0
  77. data/lib/earth/industry/data_miner.rb +2 -0
  78. data/lib/earth/industry/industries_product_lines.rb +6 -0
  79. data/lib/earth/industry/industries_sectors.rb +6 -0
  80. data/lib/earth/industry/industry.rb +12 -0
  81. data/lib/earth/industry/industry/data_miner.rb +21 -0
  82. data/lib/earth/industry/merchant.rb +5 -0
  83. data/lib/earth/industry/merchant_categories_industries.rb +8 -0
  84. data/lib/earth/industry/merchant_category.rb +6 -0
  85. data/lib/earth/industry/product_line.rb +10 -0
  86. data/lib/earth/industry/product_line/data_miner.rb +18 -0
  87. data/lib/earth/industry/product_lines_sectors.rb +6 -0
  88. data/lib/earth/industry/sector.rb +3 -0
  89. data/lib/earth/inflectors.rb +9 -0
  90. data/lib/earth/locality.rb +10 -0
  91. data/lib/earth/locality/census_division.rb +17 -0
  92. data/lib/earth/locality/census_division/data_miner.rb +21 -0
  93. data/lib/earth/locality/census_region.rb +13 -0
  94. data/lib/earth/locality/census_region/data_miner.rb +17 -0
  95. data/lib/earth/locality/climate_division.rb +17 -0
  96. data/lib/earth/locality/climate_division/data_miner.rb +20 -0
  97. data/lib/earth/locality/country.rb +13 -0
  98. data/lib/earth/locality/country/data_miner.rb +19 -0
  99. data/lib/earth/locality/data_miner.rb +10 -0
  100. data/lib/earth/locality/egrid_region.rb +15 -0
  101. data/lib/earth/locality/egrid_region/data_miner.rb +19 -0
  102. data/lib/earth/locality/egrid_subregion.rb +16 -0
  103. data/lib/earth/locality/egrid_subregion/data_miner.rb +26 -0
  104. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +13 -0
  105. data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +21 -0
  106. data/lib/earth/locality/state.rb +22 -0
  107. data/lib/earth/locality/state/data_miner.rb +37 -0
  108. data/lib/earth/locality/urbanity.rb +20 -0
  109. data/lib/earth/locality/urbanity/data_miner.rb +4 -0
  110. data/lib/earth/locality/zip_code.rb +29 -0
  111. data/lib/earth/locality/zip_code/data_miner.rb +36 -0
  112. data/lib/earth/pet.rb +4 -0
  113. data/lib/earth/pet/breed.rb +15 -0
  114. data/lib/earth/pet/breed/data_miner.rb +25 -0
  115. data/lib/earth/pet/breed_gender.rb +14 -0
  116. data/lib/earth/pet/breed_gender/data_miner.rb +21 -0
  117. data/lib/earth/pet/data_miner.rb +4 -0
  118. data/lib/earth/pet/gender.rb +10 -0
  119. data/lib/earth/pet/gender/data_miner.rb +13 -0
  120. data/lib/earth/pet/species.rb +40 -0
  121. data/lib/earth/pet/species/data_miner.rb +42 -0
  122. data/lib/earth/rail.rb +1 -0
  123. data/lib/earth/rail/data_miner.rb +1 -0
  124. data/lib/earth/rail/rail_class.rb +16 -0
  125. data/lib/earth/rail/rail_class/data_miner.rb +36 -0
  126. data/lib/earth/residence.rb +8 -0
  127. data/lib/earth/residence/air_conditioner_use.rb +30 -0
  128. data/lib/earth/residence/air_conditioner_use/data_miner.rb +4 -0
  129. data/lib/earth/residence/clothes_machine_use.rb +33 -0
  130. data/lib/earth/residence/clothes_machine_use/data_miner.rb +4 -0
  131. data/lib/earth/residence/data_miner.rb +8 -0
  132. data/lib/earth/residence/dishwasher_use.rb +33 -0
  133. data/lib/earth/residence/dishwasher_use/data_miner.rb +4 -0
  134. data/lib/earth/residence/residence_appliance.rb +7 -0
  135. data/lib/earth/residence/residence_appliance/data_miner.rb +19 -0
  136. data/lib/earth/residence/residence_class.rb +26 -0
  137. data/lib/earth/residence/residence_class/data_miner.rb +4 -0
  138. data/lib/earth/residence/residence_fuel_price.rb +18 -0
  139. data/lib/earth/residence/residence_fuel_price/data_miner.rb +200 -0
  140. data/lib/earth/residence/residence_fuel_type.rb +33 -0
  141. data/lib/earth/residence/residence_fuel_type/data_miner.rb +18 -0
  142. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +67 -0
  143. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +264 -0
  144. data/lib/earth/schema.rb +8 -0
  145. data/spec/lib/earth_spec.rb +25 -0
  146. data/spec/spec_helper.rb +11 -0
  147. data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
  148. data/vendor/geokit-rails/MIT-LICENSE +20 -0
  149. data/vendor/geokit-rails/README.markdown +561 -0
  150. data/vendor/geokit-rails/Rakefile +18 -0
  151. data/vendor/geokit-rails/about.yml +9 -0
  152. data/vendor/geokit-rails/assets/api_keys_template +61 -0
  153. data/vendor/geokit-rails/init.rb +1 -0
  154. data/vendor/geokit-rails/install.rb +14 -0
  155. data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
  156. data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
  157. data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
  158. data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
  159. data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
  160. data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
  161. data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
  162. data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
  163. data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
  164. data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
  165. data/vendor/geokit-rails/test/boot.rb +25 -0
  166. data/vendor/geokit-rails/test/database.yml +20 -0
  167. data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
  168. data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
  169. data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
  170. data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
  171. data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
  172. data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
  173. data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
  174. data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
  175. data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
  176. data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
  177. data/vendor/geokit-rails/test/models/company.rb +3 -0
  178. data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
  179. data/vendor/geokit-rails/test/models/location.rb +4 -0
  180. data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
  181. data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
  182. data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
  183. data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
  184. data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
  185. data/vendor/geokit-rails/test/models/store.rb +3 -0
  186. data/vendor/geokit-rails/test/schema.rb +60 -0
  187. data/vendor/geokit-rails/test/tasks.rake +31 -0
  188. data/vendor/geokit-rails/test/test_helper.rb +23 -0
  189. metadata +444 -0
@@ -0,0 +1,38 @@
1
+ class FlightSegment < ActiveRecord::Base
2
+ set_primary_key :row_hash
3
+
4
+ extend CohortScope
5
+ self.minimum_cohort_size = 5 #FIXME ??
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
+
30
+ INPUT_CHARACTERISTICS = [
31
+ :origin_airport,
32
+ :destination_airport,
33
+ :aircraft,
34
+ :airline,
35
+ :propulsion,
36
+ :domesticity
37
+ ]
38
+ end
@@ -0,0 +1,334 @@
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
+ process "Don't re-import too often" do
163
+ raise DataMiner::Skip unless DataMiner::Run.allowed? FlightSegment
164
+ end
165
+
166
+ schema Earth.database_options do
167
+ string 'row_hash'
168
+ string 'propulsion_id'
169
+ integer 'bts_aircraft_group_code'
170
+ string 'configuration_id'
171
+ integer 'bts_aircraft_configuration_code'
172
+ string 'distance_group'
173
+ integer 'bts_distance_group_code'
174
+ string 'service_class_id'
175
+ string 'bts_service_class_code'
176
+ string 'domesticity_id'
177
+ string 'bts_data_source_code'
178
+ integer 'departures_performed'
179
+ integer 'payload'
180
+ integer 'total_seats'
181
+ integer 'passengers'
182
+ integer 'freight'
183
+ integer 'mail'
184
+ integer 'ramp_to_ramp'
185
+ integer 'air_time'
186
+ float 'load_factor'
187
+ float 'freight_share'
188
+ integer 'distance'
189
+ integer 'departures_scheduled'
190
+ string 'airline_iata_code'
191
+ string 'dot_airline_id_code'
192
+ string 'unique_carrier_name'
193
+ string 'unique_carrier_entity'
194
+ string 'region'
195
+ string 'current_airline_iata_code'
196
+ string 'carrier_name'
197
+ integer 'carrier_group'
198
+ integer 'carrier_group_new'
199
+ string 'origin_airport_iata_code'
200
+ string 'origin_city_name'
201
+ integer 'origin_city_num'
202
+ string 'origin_state_abr'
203
+ string 'origin_state_fips'
204
+ string 'origin_state_nm'
205
+ string 'origin_country_iso_3166_code'
206
+ string 'origin_country_name'
207
+ integer 'origin_wac'
208
+ string 'dest_airport_iata_code'
209
+ string 'dest_city_name'
210
+ integer 'dest_city_num'
211
+ string 'dest_state_abr'
212
+ string 'dest_state_fips'
213
+ string 'dest_state_nm'
214
+ string 'dest_country_iso_3166_code'
215
+ string 'dest_country_name'
216
+ integer 'dest_wac'
217
+ integer 'bts_aircraft_type_code'
218
+ integer 'year'
219
+ integer 'quarter'
220
+ integer 'month'
221
+ float 'seats'
222
+ string 'payload_units'
223
+ string 'freight_units'
224
+ string 'mail_units'
225
+ string 'distance_units'
226
+ index 'airline_iata_code'
227
+ index 'bts_aircraft_type_code'
228
+ index 'origin_airport_iata_code'
229
+ index 'dest_airport_iata_code'
230
+ index 'domesticity_id'
231
+ # 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"
232
+ end
233
+
234
+ months = Hash.new
235
+ (2008..2009).each do |year|
236
+ # (2008..2008).each do |year| # DEBUG MODE!
237
+ (1..12).each do |month|
238
+ # (1..1).each do |month| # DEBUG MODE!
239
+ time = Time.gm year, month
240
+ form_data = FORM_DATA.dup
241
+ form_data.gsub! '__YEAR__', time.year.to_s
242
+ form_data.gsub! '__MONTH_NUMBER__', time.month.to_s
243
+ form_data.gsub! '__MONTH_NAME__', time.strftime('%B')
244
+ months[time] = form_data
245
+ end
246
+ end
247
+ # creating dictionaries by hand so that a new one doesn't get created for every month
248
+ propulsion_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_GROUP'
249
+ configuration_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_CONFIG'
250
+ distance_group_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DISTANCE_GROUP_500'
251
+ service_class_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_SERVICE_CLASS'
252
+ domesticity_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DATA_SOURCE'
253
+ months.each do |month, form_data|
254
+ import "T100 flight segment data from #{month.strftime('%B %Y')}",
255
+ :url => URL,
256
+ :form_data => form_data,
257
+ :compression => :zip,
258
+ :glob => '/*.csv' do
259
+
260
+ key 'row_hash'
261
+
262
+ store 'propulsion_id', :field_name => 'AIRCRAFT_GROUP', :dictionary => propulsion_dictionary
263
+ store 'bts_aircraft_group_code', :field_name => 'AIRCRAFT_GROUP'
264
+
265
+ store 'configuration_id', :field_name => 'AIRCRAFT_CONFIG', :dictionary => configuration_dictionary
266
+ store 'bts_aircraft_configuration_code', :field_name => 'AIRCRAFT_CONFIG'
267
+
268
+ store 'distance_group', :field_name => 'DISTANCE_GROUP', :dictionary => distance_group_dictionary
269
+ store 'bts_distance_group_code', :field_name => 'DISTANCE_GROUP'
270
+
271
+ store 'service_class_id', :field_name => 'CLASS', :dictionary => service_class_dictionary
272
+ store 'bts_service_class_code', :field_name => 'CLASS'
273
+
274
+ store 'domesticity_id', :field_name => 'DATA_SOURCE', :dictionary => domesticity_dictionary
275
+ store 'bts_data_source_code', :field_name => 'DATA_SOURCE'
276
+
277
+ store 'departures_scheduled', :field_name => 'DEPARTURES_SCHEDULED'
278
+ store 'departures_performed', :field_name => 'DEPARTURES_PERFORMED'
279
+ store 'payload', :field_name => 'PAYLOAD', :from_units => :pounds, :to_units => :kilograms
280
+ store 'total_seats', :field_name => 'SEATS'
281
+ store 'passengers', :field_name => 'PASSENGERS'
282
+ store 'freight', :field_name => 'FREIGHT', :from_units => :pounds, :to_units => :kilograms
283
+ store 'mail', :field_name => 'MAIL', :from_units => :pounds, :to_units => :kilograms
284
+ store 'distance', :field_name => 'DISTANCE', :from_units => :miles, :to_units => :kilometres
285
+ store 'ramp_to_ramp', :field_name => 'RAMP_TO_RAMP'
286
+ store 'air_time', :field_name => 'AIR_TIME'
287
+ store 'airline_iata_code', :field_name => 'UNIQUE_CARRIER' # adjusted for uniqueness
288
+ store 'dot_airline_id_code', :field_name => 'AIRLINE_ID'
289
+ store 'unique_carrier_name', :field_name => 'UNIQUE_CARRIER_NAME'
290
+ store 'unique_carrier_entity', :field_name => 'UNIQUE_CARRIER_ENTITY'
291
+ store 'region', :field_name => 'REGION'
292
+ store 'current_airline_iata_code', :field_name => 'CARRIER'
293
+ store 'carrier_name', :field_name => 'CARRIER_NAME'
294
+ store 'carrier_group', :field_name => 'CARRIER_GROUP'
295
+ store 'carrier_group_new', :field_name => 'CARRIER_GROUP_NEW'
296
+ store 'origin_airport_iata_code', :field_name => 'ORIGIN'
297
+ store 'origin_city_name', :field_name => 'ORIGIN_CITY_NAME'
298
+ store 'origin_city_num', :field_name => 'ORIGIN_CITY_NUM'
299
+ store 'origin_state_abr', :field_name => 'ORIGIN_STATE_ABR'
300
+ store 'origin_state_fips', :field_name => 'ORIGIN_STATE_FIPS'
301
+ store 'origin_state_nm', :field_name => 'ORIGIN_STATE_NM'
302
+ store 'origin_country_iso_3166_code', :field_name => 'ORIGIN_COUNTRY'
303
+ store 'origin_country_name', :field_name => 'ORIGIN_COUNTRY_NAME'
304
+ store 'origin_wac', :field_name => 'ORIGIN_WAC'
305
+ store 'dest_airport_iata_code', :field_name => 'DEST'
306
+ store 'dest_city_name', :field_name => 'DEST_CITY_NAME'
307
+ store 'dest_city_num', :field_name => 'DEST_CITY_NUM'
308
+ store 'dest_state_abr', :field_name => 'DEST_STATE_ABR'
309
+ store 'dest_state_fips', :field_name => 'DEST_STATE_FIPS'
310
+ store 'dest_state_nm', :field_name => 'DEST_STATE_NM'
311
+ store 'dest_country_iso_3166_code', :field_name => 'DEST_COUNTRY'
312
+ store 'dest_country_name', :field_name => 'DEST_COUNTRY_NAME'
313
+ store 'dest_wac', :field_name => 'DEST_WAC'
314
+ store 'bts_aircraft_type_code', :field_name => 'AIRCRAFT_TYPE' # lol no dictionary please
315
+ store 'year', :field_name => 'YEAR'
316
+ store 'quarter', :field_name => 'QUARTER'
317
+ store 'month', :field_name => 'MONTH'
318
+ end
319
+ end
320
+
321
+ process "Derive freight share as a fraction of payload" do
322
+ update_all 'freight_share = (freight + mail) / payload', 'payload > 0'
323
+ end
324
+
325
+ process "Derive load factor, which is passengers divided by the total seats available" do
326
+ update_all 'load_factor = passengers / total_seats', 'passengers <= total_seats'
327
+ end
328
+
329
+ process "Derive average seats per departure" do
330
+ update_all 'seats = total_seats / departures_performed', 'departures_performed > 0'
331
+ end
332
+ end
333
+ end
334
+
@@ -0,0 +1,18 @@
1
+ class FlightService < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ data_miner do
5
+ schema do
6
+ string 'name'
7
+ string 'bts_service_class_code'
8
+ end
9
+
10
+ process "derive from flight segments" do
11
+ FlightSegment.run_data_miner!
12
+ connection.execute %{
13
+ INSERT IGNORE INTO flight_services(name, bts_service_class_code)
14
+ SELECT flight_segments.service_class_id, flight_segments.bts_service_class_code FROM flight_segments WHERE LENGTH(flight_segments.service_class_id) > 0
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ FlightService.class_eval do
2
+ # data_miner do
3
+ #...
4
+ end
data/lib/earth/all.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'earth/air'
2
+ require 'earth/automobile'
3
+ require 'earth/bus'
4
+ require 'earth/diet'
5
+ require 'earth/fuel'
6
+ require 'earth/industry'
7
+ require 'earth/locality'
8
+ require 'earth/pet'
9
+ require 'earth/rail'
10
+ require 'earth/residence'
@@ -0,0 +1,8 @@
1
+ require 'earth/automobile/automobile_fuel_type'
2
+ require 'earth/automobile/automobile_make'
3
+ require 'earth/automobile/automobile_make_fleet_year'
4
+ require 'earth/automobile/automobile_make_year'
5
+ require 'earth/automobile/automobile_model'
6
+ require 'earth/automobile/automobile_model_year'
7
+ require 'earth/automobile/automobile_size_class'
8
+ require 'earth/automobile/automobile_variant'
@@ -0,0 +1,18 @@
1
+ class AutomobileFuelType < ActiveRecord::Base
2
+ set_primary_key :code
3
+
4
+ has_many :automobiles, :foreign_key => 'fuel_type_id'
5
+
6
+ scope :ordered, :order => 'name'
7
+
8
+ falls_back_on :emission_factor => 20.781.pounds_per_gallon.to(:kilograms_per_litre) # https://brighterplanet.sifterapp.com/projects/30/issues/428
9
+
10
+ data_miner do
11
+ tap "Brighter Planet's sanitized automobile fuel type data", Earth.taps_server
12
+ end
13
+
14
+ CODES = {
15
+ :electricity => 'El',
16
+ :diesel => 'D'
17
+ }
18
+ end
@@ -0,0 +1,45 @@
1
+ AutomobileFuelType.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'code'
5
+ string 'name'
6
+ float 'emission_factor'
7
+ string 'emission_factor_units'
8
+ float 'annual_distance'
9
+ string 'annual_distance_units'
10
+ end
11
+
12
+ import("the fuels used in the 2000 EPA fuel economy guide",
13
+ :url => 'http://www.fueleconomy.gov/FEG/epadata/00data.zip',
14
+ :filename => 'Gd6-dsc.txt',
15
+ :format => :fixed_width,
16
+ :crop => 21..26, # inclusive
17
+ :cut => '2-',
18
+ :select => lambda { |row| /\A[A-Z]/.match row[:code] },
19
+ :schema => [[ 'code', 2, { :type => :string } ],
20
+ [ 'spacer', 2 ],
21
+ [ 'name', 52, { :type => :string } ]]) do
22
+ key 'code'
23
+ store 'name'
24
+ end
25
+
26
+ import "a pre-calculated emission factor and average annual distance for each fuel",
27
+ :url => 'http://static.brighterplanet.com/science/data/transport/automobiles/models_export/automobile_fuel_type.csv' do
28
+ key 'code', :field_name => 'code'
29
+ store 'name'
30
+ store 'annual_distance', :units => :kilometres
31
+ store 'emission_factor', :units => :kilograms_per_litre
32
+ end
33
+
34
+ # pull electricity emission factor from residential electricity
35
+ import "a pre-calculated emission factor for electricity",
36
+ :url => 'http://spreadsheets.google.com/pub?key=rukxnmuhhsOsrztTrUaFCXQ',
37
+ :select => lambda { |row| row['name'] == 'electricity' } do
38
+ key 'name'
39
+ store 'emission_factor', :units => :kilograms_per_litre
40
+ end
41
+
42
+ # still need distance estimate for electric cars
43
+ end
44
+ end
45
+