Skip to content

Commit

Permalink
Issue-3: Force LH's name to be Lufthansa (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierguihot authored Apr 15, 2019
1 parent f905ba8 commit f4f40e8
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/main/scala/com/geobase/load/Loader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,21 @@ private[geobase] object Loader {

println("GeoBase: Loading airlines")

// Since during the parsing of the csv file providing the mapping airline code to airline name,
// we choose the first name amongst the list of possible names, we might not always choose the
// most appropriate name. Thus this list of custom exceptions:
val forcedAirlineNames = List(Airline("LH", "DE", "Lufthansa"))

// Airline code to airline name:
val airlineNames =
Source
.fromURL(getClass.getResource("/optd_airlines.csv"))
.getLines
.drop(1) // Remove the header
.map { line =>
val splitLine = line.split("\\^", -1)

val airlineCode = splitLine(5)
val airlineName = splitLine(7)

Airline(airlineCode, "", airlineName)
.map(_.split("\\^", -1))
.collect {
case Array(_, _, _, _, _, code, _, name, _*) if code.nonEmpty && name.nonEmpty =>
Airline(code, "", name)
}
.toList

Expand All @@ -96,17 +98,11 @@ private[geobase] object Loader {
.fromURL(getClass.getResource("/airlines.csv"))
.getLines
.drop(1) // Remove the header
.map { line =>
val splitLine = line.split("\\^", -1)

val airlineCode = splitLine(0)
val countryCode = splitLine(1)

Airline(airlineCode, countryCode, "")
}
.map(_.split("\\^", -1))
.map { case Array(code, country) => Airline(code, country, "") }
.toList

(airlineNames ::: airlineCountries)
(forcedAirlineNames ::: airlineNames ::: airlineCountries)
.groupBy(_.airlineCode)
.mapValues { airlines =>
val code = airlines.head.airlineCode
Expand Down

0 comments on commit f4f40e8

Please sign in to comment.