From 194067e976da0eefd22dc3fbd532b916dc7ee16f Mon Sep 17 00:00:00 2001
From: Xavier GUIHOT The GeoBase object can be used within Spark jobs (in this case, don't forget
+assert(geoBase.getCityFor("CDG") == Success("PAR"))
+assert(geoBase.getCountry("CDG") == Success("FR"))
+assert(geoBase.getCurrencyFor("NYC") == Success("USD"))
+assert(geoBase.getCountryForAirline("AF") == Success("FR"))
+assert(geoBase.getDistanceBetween("PAR", "NCE") == Success(686))
+assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK") == Success(7.5d))
+assert(geoBase.getNearbyAirports("CDG", 50) == Success(List("LBG", "ORY", "VIY", "POX"))) The GeoBase object can be used within Spark jobs (in this case, don't forget
the possibility to broadcast GeoBase). Opentraveldata is an accurate and maintained source of various travel
mappings. This scala wrapper around opentraveldata mostly uses this
file:
@@ -306,10 +306,8 @@ The method getCityFor returns the first city corresponding to the
given airport, which is by assumption the biggest corresponding city. the airport IATA code (for instance AZA) for which to get
+assert(geoBase.getCitiesFor("?*#") == Failure(GeoBaseException: Unknown airport "?*#") the airport IATA code (for instance AZA) for which to get
the associated cities. the list of city codes corresponding to the given airport (for
instance List("PHX", "MSC")). Returns the city associated to the given airport. the airport IATA code (for instance CDG) for which to get
the associated city. the city code corresponding to the given airport (for instance
PAR). Returns the continent associated to the given airport, city or country. Returns the continent associated to the given airport, city or country. Possible values: EU (Eurrope) - NA (North America) - SA (South Africa) -
AF (Africa) - AS (Asia) - AN (Antarctica) - OC (Oceania). the country, city or airport IATA code (for instance
+assert(geoBase.getContinentFor("NYC") == Success("NA")) // location is a city
+assert(geoBase.getContinentFor("CN") == Success("AS")) // location is a country
+assert(geoBase.getContinentFor("?*#") == Failure(GeoBaseException: Unknown location "?*#")) the country, city or airport IATA code (for instance
PAR) for which to get the associated continent. the continent code corresponding to the given location (for
instance EU). Returns the country associated to the given location (city or airport). Returns the country associated to the given location (city or airport). the location IATA code (city or airport - for instance
+assert(geoBase.getCountryFor("ORY") == Success("FR"))
+assert(geoBase.getCountryFor("?*#") == Failure(GeoBaseException: Unknown location "?*#")) the location IATA code (city or airport - for instance
PAR) for which to get the associated country. the country code corresponding to the given city or airport (for
instance FR). Returns the country associated to the given airline. Returns the country associated to the given airline. the airline IATA code (for instance AF) for which to get
+assert(geoBase.getCountryForAirline("#?") == Failure(GeoBaseException: Unknown airline "#?")) the airline IATA code (for instance AF) for which to get
the associated country. the country code corresponding to the given airline (for
instance FR). Returns the currency associated to the given location (airport, city or country). Returns the currency associated to the given location (airport, city or country). the country, city or airport IATA code (for instance FR)
+assert(geoBase.getCurrencyFor("FR") == Success("EUR"))
+assert(geoBase.getCurrencyFor("?#") == Failure(GeoBaseException: Unknown country "#?")) the country, city or airport IATA code (for instance FR)
for which to get the associated currency. the currency code corresponding to the given location (for
instance EUR). Returns the distance between two locations (airports/cities). Returns the distance between two locations (airports/cities). an airport or city IATA code (for instance ORY) for
+assert(geoBase.getDistanceBetween("PAR", "NCE") == Success(686))
+assert(geoBase.getDistanceBetween("PAR", "~#?") == Failure(GeoBaseException: Unknown location "~#?")) an airport or city IATA code (for instance ORY) for
which to get the distance with locationB. an airport or city IATA code (for instance NCE) for
which to get the distance with locationA. the distance rounded in km between locationA and locationB (for
instance 674 km). Returns the geo type of a trip (domestic, continental or inter continental). Returns the geo type of a trip (domestic, continental or inter continental). Return an enum value: GeoType.DOMESTIC, GeoType.CONTINENTAL or
GeoType.INTER_CONTINENTAL. The distinction between continental and intercontinental is made based
on iata zones. a list of cities/ariports/countries representing the
+assert(geoBase.getGeoType(List("FR", "FR")) == Success(GeoType.DOMESTIC))
+assert(geoBase.getGeoType(List("FR", "PAR", "DUB")) == Success(GeoType.CONTINENTAL))
+assert(geoBase.getGeoType(List("CDG", "TLS", "JFK", "MEX")) == Success(GeoType.INTER_CONTINENTAL))
+assert(geoBase.getGeoType(List("US", "bbb", "NCE", "aaa")) == Failure(GeoBaseException: Unknown locations \"bbb\", \"aaa\")) a list of cities/ariports/countries representing the
trip. the type of the trip (a GeoType enum value, such as
GeoType.DOMESTIC). Returns the IATA zone associated to the given airport, city or country. Returns the IATA zone associated to the given airport, city or country. Possible values are 11, 12, 13, 21, 22, 23, 31, 32 or 33. the country, city or airport IATA code (for instance
+assert(geoBase.getIataZoneFor("NYC") == Success("11"))
+assert(geoBase.getIataZoneFor("ZA") == Success("23"))
+assert(geoBase.getIataZoneFor("?*#") == Failure(GeoBaseException: Unknown location "?*#")) the country, city or airport IATA code (for instance
PAR) for which to get the associated IATA zone. the IATA zone code corresponding to the given location (for
instance 21). Returns the list of nearby airports (within the radius) for the given airport or city. Returns the list of nearby airports (within the radius) for the given airport or city. Find the list of nearby airports, within the requested radius. The list
is sorted starting from the closest airport. the airport or city for which to find nearby airports. the maximum distance (in km) for which an airport is
+assert(geoBase.getNearbyAirportsWithDetails("CDG", 36) == Success(List("LBG", "ORY")))
+assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)) == Failure(GeoBaseException: Unknown location \"~#?\"")) the airport or city for which to find nearby airports. the maximum distance (in km) for which an airport is
considered close. the sorted per incresaing distance list nearby airports Returns the list of nearby airports (within the radius) for the given airport or city. Returns the list of nearby airports (within the radius) for the given airport or city. Find the list of nearby airports, within the requested radius. The list
is sorted starting from the closest airport. This list is a tuple of
(airport/distance). the airport or city for which to find nearby
+assert(geoBase.getNearbyAirportsWithDetails("CDG", 36) == Success(List(("LBG", 9), ("ORY", 35))))
+assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)) == Failure(GeoBaseException: Unknown location \"~#?\"")) the airport or city for which to find nearby
airports. the maximum distance (in km) for which an airport is
considered close. the sorted per incresaing distance list of tuples (airport,
distance). Returns the offset in minutes for the given date at the given city/airport. Returns the offset in minutes for the given date at the given city/airport. the local date the airport or the city where this local date applies (default = "yyyyMMdd") the format under which localDate is
+assert(geoBase.getOffsetForLocalDate("2017-07-12", "NCE", "yyyy-MM-dd") == Success(120))
+assert(geoBase.getOffsetForLocalDate("20171224", "NCE") == Success(60))
+assert(geoBase.getOffsetForLocalDate("20171224", "NYC") == Success(-300))
+assert(geoBase.getOffsetForLocalDate("20171224", "~#?") == Failure(GeoBaseException: Unknown location "~#?")) the local date the airport or the city where this local date applies (default = "yyyyMMdd") the format under which localDate is
provided. the the offset in minutes for the given date at the given
city/airport (can be negative).
val geoBase = new GeoBase()
-assert(geoBase.getCityFor("CDG").get == "PAR")
-assert(geoBase.getCountry("CDG").get == "FR")
-assert(geoBase.getCurrencyFor("NYC").get == "USD")
-assert(geoBase.getCountryForAirline("AF").get == "FR")
-assert(geoBase.getDistanceBetween("PAR", "NCE").get == 686)
-assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK").get == 7.5d)
-assert(geoBase.getNearbyAirports("CDG", 50).get == List("LBG", "ORY", "VIY", "POX"))
method, returns this list of cities (usually the list will only contain
one city).
assert(geoBase.getCitiesFor("CDG") == Success(List("PAR")))
-assert(geoBase.getCitiesFor("CDG").get == List("PAR"))
assert(geoBase.getCitiesFor("AZA") == Success(List("PHX", "MSC")))
-assert(geoBase.getCitiesFor("?*#") == Failure(GeoBaseException: Unknown airport "?*#")
-assert(geoBase.getCitiesFor("?*#").getOrElse(Nil) == List())
assert(geoBase.getContinentFor("CDG") == Success("EU")) // location is an airport
-assert(geoBase.getContinentFor("NYC").get == "NA") // location is a city
-assert(geoBase.getContinentFor("CN").get == "AS") // location is a country
-assert(geoBase.getContinentFor("?*#") == Failure(GeoBaseException: Unknown location "?*#"))
-assert(geoBase.getContinentFor("?*#").getOrElse("") == "")
assert(geoBase.getCountryFor("PAR") == Success("FR"))
-assert(geoBase.getCountryFor("PAR").get == "FR")
-assert(geoBase.getCountryFor("ORY").get == "FR")
-assert(geoBase.getCountryFor("?*#") == Failure(GeoBaseException: Unknown location "?*#"))
-assert(geoBase.getCountryFor("?*#").getOrElse("") == "")
assert(geoBase.getCountryForAirline("AF") == Success("FR"))
-assert(geoBase.getCountryForAirline("AF").get == "FR")
-assert(geoBase.getCountryForAirline("#?") == Failure(GeoBaseException: Unknown airline "#?"))
-assert(geoBase.getCountryForAirline("#?").getOrElse("") == "")
assert(geoBase.getCurrencyFor("JFK") == Success("USD"))
-assert(geoBase.getCurrencyFor("FR").get == "EUR")
-assert(geoBase.getCurrencyFor("?#").get == Failure(GeoBaseException: Unknown country "#?"))
-assert(geoBase.getCurrencyFor("?#").getOrElse("USD") == "USD")
assert(geoBase.getDistanceBetween("ORY", "NCE") == Success(674))
-assert(geoBase.getDistanceBetween("PAR", "NCE").get == 686)
-assert(geoBase.getDistanceBetween("PAR", "~#?").get == Failure(GeoBaseException: Unknown location "~#?"))
-assert(geoBase.getDistanceBetween("PAR", "~#?").getOrElse(-1) == -1)
@@ -484,12 +473,10 @@
assert(geoBase.getGeoType(List("CDG", "ORY")) == Success(GeoType.DOMESTIC))
-assert(geoBase.getGeoType(List("CDG", "ORY")).get == GeoType.DOMESTIC)
-assert(geoBase.getGeoType(List("FR", "FR")).get == GeoType.DOMESTIC)
-assert(geoBase.getGeoType(List("FR", "PAR", "DUB")).get == GeoType.CONTINENTAL)
-assert(geoBase.getGeoType(List("CDG", "TLS", "JFK", "MEX")).get == GeoType.INTER_CONTINENTAL)
-assert(geoBase.getGeoType(List("US", "bbb", "NCE", "aaa")).get == Failure(GeoBaseException: Unknown locations \"bbb\", \"aaa\"))
-assert(geoBase.getGeoType(List("US", "bbb", "NCE", "aaa")).toOption == None)
assert(geoBase.getIataZoneFor("CDG") == Success("21"))
-assert(geoBase.getIataZoneFor("NYC").get == "11")
-assert(geoBase.getIataZoneFor("ZA").get == "23")
-assert(geoBase.getIataZoneFor("?*#") == Failure(GeoBaseException: Unknown location "?*#"))
-assert(geoBase.getIataZoneFor("?*#").getOrElse("") == "")
assert(geoBase.getNearbyAirportsWithDetails("CDG", 50) == Success(List("LBG", "ORY", "VIY", "POX")))
-assert(geoBase.getNearbyAirportsWithDetails("CDG", 36).get == List("LBG", "ORY"))
-assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)).get == Failure(GeoBaseException: Unknown location \"~#?\""))
-assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)).getOrElse(Nil) == List())
assert(geoBase.getNearbyAirportsWithDetails("CDG", 50) == Success(List(("LBG", 9), ("ORY", 35), ("VIY", 37), ("POX", 38))))
-assert(geoBase.getNearbyAirportsWithDetails("CDG", 36).get == List(("LBG", 9), ("ORY", 35)))
-assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)).get == Failure(GeoBaseException: Unknown location \"~#?\""))
-assert(geoBase.getNearbyAirportsWithDetails("~#?", 36)).getOrElse(Nil) == List())
@@ -579,12 +563,10 @@
assert(geoBase.getOffsetForLocalDate("20170712", "NCE") == Success(120))
-assert(geoBase.getOffsetForLocalDate("20170712", "NCE").get == 120)
-assert(geoBase.getOffsetForLocalDate("2017-07-12", "NCE", "yyyy-MM-dd").get == 120)
-assert(geoBase.getOffsetForLocalDate("20171224", "NCE").get == 60)
-assert(geoBase.getOffsetForLocalDate("20171224", "NYC").get == -300)
-assert(geoBase.getOffsetForLocalDate("20171224", "~#?") == Failure(GeoBaseException: Unknown location "~#?"))
-assert(geoBase.getOffsetForLocalDate("20171224", "~#?").getOrElse("0") == 0)
flying time (EFT).
This is meant to be used to compute the trip duration for a segment/bound for which we know the origin/destination airports/cities and the local time. i.e. when we don't have gmt times.
assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK") == Success(7.5d)) -assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "CDG", "20160606_1757", "JFK").get == 7.5d) val computedTripDuration = geoBase.getTripDurationFromLocalDates( "2016-06-06T16:27", "CDG", "2016-06-06T17:57", "JFK", format = "yyyy-MM-dd'T'HH:mm", unit = "minutes" ) -assert(computedTripDuration.get == 450d) +assert(computedTripDuration == Success(450d)) -assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "~#?", "20160606_1757", "JFK").get == Failure(GeoBaseException: Unknown location "~#?")) -assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "~#?", "20160606_1757", "JFK").getOrElse(-1d) == -1d)
the departure local date
the origin airport or city
the arrival local date
the destination airport or city
(default = "hours") either "hours" or "minutes"
(default = "yyyyMMdd_HHmm") the format under which local +assert(geoBase.getTripDurationFromLocalDates("20160606_1627", "~#?", "20160606_1757", "JFK") == Failure(GeoBaseException: Unknown location "~#?"))
the departure local date
the origin airport or city
the arrival local date
the destination airport or city
(default = "hours") either "hours" or "minutes"
(default = "yyyyMMdd_HHmm") the format under which local departure and arrival dates are provided.
the trip duration in the chosen unit (in hours by default) and format.
assert(geoBase.gmtDateToLocal("20160606_1427", "NCE") == Success("20160606_1627")) -assert(geoBase.gmtDateToLocal("20160606_1427", "NCE").get == "20160606_1627") -assert(geoBase.gmtDateToLocal("2016-06-07T02:27", "NYC", "yyyy-MM-dd'T'HH:mm").get == "2016-06-06T22:27") -assert(geoBase.gmtDateToLocal("20160606_2227", "~#?") == Failure(GeoBaseException: Unknown location "~#?")) -assert(geoBase.gmtDateToLocal("20160606_2227", "~#?").getOrElse("20000101_1200") == "20000101_1200")
Returns the city associated to the given airport.
the airport IATA code (for instance CDG) for which to get +assert(geoBase.getCityFor("?*#") == Failure(GeoBaseException: Unknown airport "?*#")