earth 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ Airline.class_eval do
|
|
36
36
|
|
37
37
|
process "Determine whether airlines fly internationally by looking at flight segments" do
|
38
38
|
FlightSegment.run_data_miner!
|
39
|
-
update_all 'international = 1', '(SELECT COUNT(*) FROM flight_segments WHERE flight_segments.airline_iata_code = airlines.iata_code AND flight_segments.origin_country_iso_3166_code != flight_segments.
|
39
|
+
update_all 'international = 1', '(SELECT COUNT(*) FROM flight_segments WHERE flight_segments.airline_iata_code = airlines.iata_code AND flight_segments.origin_country_iso_3166_code != flight_segments.destination_country_iso_3166_code AND flight_segments.origin_country_iso_3166_code IS NOT NULL AND flight_segments.destination_country_iso_3166_code IS NOT NULL) > 0'
|
40
40
|
end
|
41
41
|
|
42
42
|
process "Derive some average flight characteristics from flight segments" do
|
@@ -51,11 +51,11 @@ Airport.class_eval do
|
|
51
51
|
|
52
52
|
process "Determine whether each airport serves international flights" do
|
53
53
|
FlightSegment.run_data_miner!
|
54
|
-
|
55
|
-
update_all 'international_destination = 1', '(SELECT COUNT(*) FROM flight_segments WHERE flight_segments.
|
54
|
+
c update_all 'international_origin = 1','(SELECT COUNT(*) FROM flight_segments WHERE flight_segments.origin_airport_iata_code = airports.iata_code AND flight_segments.origin_country_iso_3166_code != flight_segments.destination_country_iso_3166_code AND flight_segments.origin_country_iso_3166_code IS NOT NULL AND flight_segments.destination_country_iso_3166_code IS NOT NULL LIMIT 1) > 0'
|
55
|
+
update_all 'international_destination = 1', '(SELECT COUNT(*) FROM flight_segments WHERE flight_segments.destination_airport_iata_code = airports.iata_code AND flight_segments.origin_country_iso_3166_code != flight_segments.destination_country_iso_3166_code AND flight_segments.origin_country_iso_3166_code IS NOT NULL AND flight_segments.destination_country_iso_3166_code IS NOT NULL LIMIT 1) > 0'
|
56
56
|
end
|
57
57
|
|
58
|
-
# sabshere 5/24/10 using temporary tables because the WHERE clause has a very slow OR condition: iata_code =
|
58
|
+
# sabshere 5/24/10 using temporary tables because the WHERE clause has a very slow OR condition: iata_code = destination_iata_code OR iata_code = origin_iata_code
|
59
59
|
process "Derive some average flight characteristics from flight segments" do
|
60
60
|
FlightSegment.run_data_miner!
|
61
61
|
segments = FlightSegment.arel_table
|
@@ -64,7 +64,7 @@ Airport.class_eval do
|
|
64
64
|
find_in_batches do |batch|
|
65
65
|
batch.each do |airport|
|
66
66
|
targeting_relation = airports[:iata_code].eq airport.iata_code
|
67
|
-
conditional_relation = segments[:origin_airport_iata_code].eq(airport.iata_code).or(segments[:
|
67
|
+
conditional_relation = segments[:origin_airport_iata_code].eq(airport.iata_code).or(segments[:destination_airport_iata_code].eq(airport.iata_code))
|
68
68
|
connection.execute "CREATE TEMPORARY TABLE tmp1 #{FlightSegment.where(conditional_relation).to_sql}"
|
69
69
|
update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
|
70
70
|
update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).to_sql.gsub('flight_segments', 'tmp1')})", targeting_relation.to_sql
|