def test_load_airports(self): """ Remove all the airports then add them """ connection = ctx.get_connection(ctx.CONTEXT, ctx.DB_USER) context = ctx.CONTEXT remove_all_airports() make_aps_file = make_test_data_file(AIRPORTS_DATA_FILE) load_airports(make_aps_file(), context, connection)
def test_load_airports(self): connection = ctx.get_connection(ctx.CONTEXT, ctx.DB_USER) context = ctx.CONTEXT make_movements_airports_file = make_test_data_file( MOVEMENTS_REPORTING_AIRPORTS_DATA_FILE) ok = load_airports(make_movements_airports_file(), context, connection) connection_owner = ctx.get_connection(ctx.CONTEXT, ctx.POSTGRES_DB) create_GIST_index(context, connection_owner) self.assertTrue(ok) # # Check we actually added some user sectors # schemaName = context[ctx.SCHEMA_NAME] with connection.cursor(cursor_factory=DictCursor) as dict_cursor: dict_cursor.execute("SELECT count(id) FROM %s.airports;", [AsIs(schemaName)]) self.assertTrue(dict_cursor.fetchone()[0] > 0) dict_cursor.execute( "SELECT * FROM %s.airports where icao_ap_code = 'EGLL';", [AsIs(schemaName)]) heathrow = dict_cursor.fetchone() latitude = heathrow['latitude'] longitude = heathrow['longitude'] icao_code = heathrow['icao_ap_code'] self.assertEquals(icao_code, 'EGLL') self.assertTrue(51.3 < latitude < 51.5) self.assertTrue(-0.48 < longitude < -0.44) connection.close()
def test_find_airport_intersections(self): """ Check a simple airport intersection """ RADIUS_1 = 30 AIRPORT_ID_1 = "NONO" AIRPORT_ID_2 = "LFPG" connection = ctx.get_connection(ctx.CONTEXT, ctx.DB_USER) context = ctx.CONTEXT remove_all_airports() make_aps_file = make_test_data_file(AIRPORTS_DATA_FILE) load_airports(make_aps_file(), context, connection) ok, airports = finder('icao_ap_code', AIRPORT_ID_2) self.assertTrue(ok) self.assertEqual(1, len(airports)) airport = airports[0] self.assertEqual(airport['icao_ap_code'], 'LFPG') FLIGHT_ID_1 = "test-1-id-1" LATS_1 = [ 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0 ] LONS_1 = [-0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5] FLIGHT_ID_2 = "test-1-id-2" LATS_2 = [ 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0 ] LONS_2 = [1.5, -1.4, 1.0, 1.2, 1.7, 2.0, 2.1, 2.4, 2.5, 2.6, 2.7] # An airport we do not intersect with lats, lons = find_airport_cylinder_intersection( FLIGHT_ID_1, LATS_1, LONS_1, AIRPORT_ID_1, RADIUS_1, False) self.assertEqual(0, len(lats)) self.assertEqual(0, len(lons)) # An airport we do intersect with lats, lons = find_airport_cylinder_intersection( FLIGHT_ID_2, LATS_2, LONS_2, AIRPORT_ID_2, RADIUS_1, False) self.assertEqual(1, len(lats)) self.assertEqual(1, len(lons))
def initialise_airports(airports_file_path, reset=False): """ Uses the provided file path to load an airports file, must be csv. If no airports file is found we return false. Reset=True Remove all and replace with this file. Reset=False Add these airports to the sectors table. Note, this is not an update. return True if we succeeded A tuple of (False, message) if we fail """ connection = ctx.get_connection(ctx.CONTEXT, ctx.DB_USER) context = ctx.CONTEXT if os.path.exists(airports_file_path): if reset: remove_all_airports() load_airports(airports_file_path, context, connection) return True else: return (False, "Path not found " + airports_file_path)