Skip to content

Commit

Permalink
Minor refactoring - fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierguihot committed Jun 15, 2018
1 parent 687e0bd commit fc48696
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ src/main/resources/optd_por_public.csv
src/main/resources/optd_airlines.csv

.ensime*
.idea
geobase.iml
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Overview


Version: 1.2.2
Version: 1.2.3

API Scaladoc: [GeoBase](http://xavierguihot.com/geobase/#com.geobase.GeoBase)

Expand Down Expand Up @@ -78,7 +78,7 @@ With sbt, add these lines to your build.sbt:
```scala
resolvers += "jitpack" at "https://jitpack.io"

libraryDependencies += "com.github.xavierguihot" % "geobase" % "v1.2.2"
libraryDependencies += "com.github.xavierguihot" % "geobase" % "v1.2.3"
```

With maven, add these lines to your pom.xml:
Expand All @@ -94,7 +94,7 @@ With maven, add these lines to your pom.xml:
<dependency>
<groupId>com.github.xavierguihot</groupId>
<artifactId>geobase</artifactId>
<version>v1.2.2</version>
<version>v1.2.3</version>
</dependency>
```

Expand All @@ -108,7 +108,7 @@ allprojects {
}
dependencies {
compile 'com.github.xavierguihot:geobase:v1.2.2'
compile 'com.github.xavierguihot:geobase:v1.2.3'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "geobase"

version := "1.2.2"
version := "1.2.3"

scalaVersion := "2.11.12"

Expand Down
18 changes: 9 additions & 9 deletions docs/com/geobase/GeoBase.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h4 id="signature" class="signature">
based on <a href="https://github.com/opentraveldata/opentraveldata">
opentraveldata</a> as well as other mappings (airlines, currencies, ...).
This tool also provides classic time-oriented methods such as the
computation of a trip duration.</p><p>Here are a few exemples:</p><pre><span class="kw">import</span> com.geobase.GeoBase
computation of a trip duration.</p><p>Here are a few examples:</p><pre><span class="kw">import</span> com.geobase.GeoBase

<span class="kw">val</span> geoBase = <span class="kw">new</span> GeoBase()

Expand All @@ -67,11 +67,11 @@ <h4 id="signature" class="signature">
the possibility to <b>broadcast GeoBase</b>).</p><p>Opentraveldata is an accurate and maintained source of various travel
mappings. This scala wrapper around opentraveldata mostly uses this
file: <a href="https://github.com/opentraveldata/opentraveldata/tree/master/opentraveldata/optd_por_public.csv">
optd_por_public.csv</a>.</p><p>Getters all have a return type embedded within the Try monade. Throwing
optd_por_public.csv</a>.</p><p>Getters all have a return type embedded within the Try monad. Throwing
exceptions as is when one might request mappings for non existing locations,
isn't realy the scala way, and simply embedding the result in the Option
isn't really the scala way, and simply embedding the result in the Option
monad doesn't give the user the possibility to understand what went wrong.
Thus the usage of the Try monade.</p><p>Source <a href="https://github.com/xavierguihot/geobase/blob/master/src/main/scala/com/geobase/GeoBase.scala">
Thus the usage of the Try monad.</p><p>Source <a href="https://github.com/xavierguihot/geobase/blob/master/src/main/scala/com/geobase/GeoBase.scala">
GeoBase</a>
</p></div><dl class="attributes block"> <dt>Since</dt><dd><p>2016-05</p></dd></dl><div class="toggleContainer block">
<span class="toggle">Linear Supertypes</span>
Expand Down Expand Up @@ -289,7 +289,7 @@ <h4 class="signature">
<img src="../../lib/permalink.png" alt="Permalink" />
</a>
</span>
<p class="shortcomment cmt">Returns the continent associated to the given airport, city or country.</p><div class="fullcomment"><div class="comment cmt"><p>Returns the continent associated to the given airport, city or country.</p><p>Possible values: EU (Eurrope) - NA (North America) - SA (South Africa) -
<p class="shortcomment cmt">Returns the continent associated to the given airport, city or country.</p><div class="fullcomment"><div class="comment cmt"><p>Returns the continent associated to the given airport, city or country.</p><p>Possible values: EU (Europe) - NA (North America) - SA (South Africa) -
AF (Africa) - AS (Asia) - AN (Antarctica) - OC (Oceania).</p><pre>assert(geoBase.continent(<span class="lit">"CDG"</span>) == Success(<span class="lit">"EU"</span>)) <span class="cmt">// location is an airport</span>
assert(geoBase.continent(<span class="lit">"NYC"</span>) == Success(<span class="lit">"NA"</span>)) <span class="cmt">// location is a city</span>
assert(geoBase.continent(<span class="lit">"CN"</span>) == Success(<span class="lit">"AS"</span>)) <span class="cmt">// location is a country</span>
Expand Down Expand Up @@ -460,7 +460,7 @@ <h4 class="signature">
assert(geoBase.geoType(<span class="std">List</span>(<span class="lit">"FR"</span>, <span class="lit">"FR"</span>)) == Success(DOMESTIC))
assert(geoBase.geoType(<span class="std">List</span>(<span class="lit">"FR"</span>, <span class="lit">"PAR"</span>, <span class="lit">"DUB"</span>)) == Success(CONTINENTAL))
assert(geoBase.geoType(<span class="std">List</span>(<span class="lit">"CDG"</span>, <span class="lit">"TLS"</span>, <span class="lit">"JFK"</span>, <span class="lit">"MEX"</span>)) == Success(INTER_CONTINENTAL))
assert(geoBase.geoType(<span class="std">List</span>(<span class="lit">"US"</span>, <span class="lit">"bbb"</span>, <span class="lit">"NCE"</span>, <span class="lit">"aaa"</span>)) == Failure(GeoBaseException: Unknown locations \<span class="lit">"bbb\", \"aaa\"))</span></pre></div><dl class="paramcmts block"><dt class="param">locations</dt><dd class="cmt"><p>a list of cities/ariports/countries representing the trip</p></dd><dt>returns</dt><dd class="cmt"><p>the type of the trip (a GeoType &quot;enum&quot; value, such as DOMESTIC)</p></dd></dl></div>
assert(geoBase.geoType(<span class="std">List</span>(<span class="lit">"US"</span>, <span class="lit">"bbb"</span>, <span class="lit">"NCE"</span>, <span class="lit">"aaa"</span>)) == Failure(GeoBaseException: Unknown locations \<span class="lit">"bbb\", \"aaa\"))</span></pre></div><dl class="paramcmts block"><dt class="param">locations</dt><dd class="cmt"><p>a list of cities/airports/countries representing the trip</p></dd><dt>returns</dt><dd class="cmt"><p>the type of the trip (a GeoType &quot;enum&quot; value, such as DOMESTIC)</p></dd></dl></div>
</li><li name="scala.AnyRef#getClass" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
<a id="getClass():Class[_]"></a>
<a id="getClass():Class[_]"></a>
Expand Down Expand Up @@ -643,7 +643,7 @@ <h4 class="signature">
sorted starting from the closest airport.</p><pre>assert(geoBase.nearbyAirports(<span class="lit">"CDG"</span>, <span class="num">50</span>) == Success(<span class="std">List</span>(<span class="lit">"LBG"</span>, <span class="lit">"ORY"</span>, <span class="lit">"VIY"</span>, <span class="lit">"POX"</span>)))
assert(geoBase.nearbyAirports(<span class="lit">"CDG"</span>, <span class="num">36</span>) == Success(<span class="std">List</span>(<span class="lit">"LBG"</span>, <span class="lit">"ORY"</span>)))
assert(geoBase.nearbyAirports(<span class="lit">"~#?"</span>, <span class="num">36</span>)) == Failure(GeoBaseException: Unknown location \<span class="lit">"~#?\""</span>))</pre></div><dl class="paramcmts block"><dt class="param">location</dt><dd class="cmt"><p>the airport or city for which to find nearby airports</p></dd><dt class="param">radius</dt><dd class="cmt"><p>the maximum distance (in km) for which an airport is
considered close.</p></dd><dt>returns</dt><dd class="cmt"><p>the sorted per incresaing distance list nearby airports</p></dd></dl></div>
considered close.</p></dd><dt>returns</dt><dd class="cmt"><p>the sorted per increasing distance list nearby airports</p></dd></dl></div>
</li><li name="com.geobase.GeoBase#nearbyAirportsWithDetails" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
<a id="nearbyAirportsWithDetails(location:String,radius:Int):scala.util.Try[List[(String,Int)]]"></a>
<a id="nearbyAirportsWithDetails(String,Int):Try[List[(String,Int)]]"></a>
Expand All @@ -667,7 +667,7 @@ <h4 class="signature">
(airport/distance).</p><pre>assert(geoBase.nearbyAirportsWithDetails(<span class="lit">"CDG"</span>, <span class="num">50</span>) == Success(<span class="std">List</span>((<span class="lit">"LBG"</span>, <span class="num">9</span>), (<span class="lit">"ORY"</span>, <span class="num">35</span>), (<span class="lit">"VIY"</span>, <span class="num">37</span>), (<span class="lit">"POX"</span>, <span class="num">38</span>))))
assert(geoBase.nearbyAirportsWithDetails(<span class="lit">"CDG"</span>, <span class="num">36</span>) == Success(<span class="std">List</span>((<span class="lit">"LBG"</span>, <span class="num">9</span>), (<span class="lit">"ORY"</span>, <span class="num">35</span>))))
assert(geoBase.nearbyAirportsWithDetails(<span class="lit">"~#?"</span>, <span class="num">36</span>)) == Failure(GeoBaseException: Unknown location \<span class="lit">"~#?\""</span>))</pre></div><dl class="paramcmts block"><dt class="param">location</dt><dd class="cmt"><p>the airport or city for which to find nearby airports.</p></dd><dt class="param">radius</dt><dd class="cmt"><p>the maximum distance (in km) for which an airport is
considered close.</p></dd><dt>returns</dt><dd class="cmt"><p>the sorted per incresaing distance list of tuples (airport,
considered close.</p></dd><dt>returns</dt><dd class="cmt"><p>the sorted per increasing distance list of tuples (airport,
distance).</p></dd></dl></div>
</li><li name="scala.AnyRef#notify" visbl="pub" data-isabs="false" fullComment="yes" group="Ungrouped">
<a id="notify():Unit"></a>
Expand Down Expand Up @@ -797,7 +797,7 @@ <h4 class="signature">
<img src="../../lib/permalink.png" alt="Permalink" />
</a>
</span>
<p class="shortcomment cmt">Returns the trip duration between two locations (airport or city).</p><div class="fullcomment"><div class="comment cmt"><p>Returns the trip duration between two locations (airport or city).</p><p>In the travel indeuxtry, the trip duration is synonym with elapsed flying
<p class="shortcomment cmt">Returns the trip duration between two locations (airport or city).</p><div class="fullcomment"><div class="comment cmt"><p>Returns the trip duration between two locations (airport or city).</p><p>In the travel industry, the trip duration is synonym with elapsed flying
time (EFT).</p><p>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.</p><pre>assert(geoBase.tripDurationFromLocalDates(
Expand Down
2 changes: 1 addition & 1 deletion docs/com/geobase/model/GeoType.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h4 id="signature" class="signature">
</span>
</h4>

<div id="comment" class="fullcommenttop"><div class="comment cmt"><p>An enumeration which represents the geograpic types of a trip</p></div><div class="toggleContainer block">
<div id="comment" class="fullcommenttop"><div class="comment cmt"><p>An enumeration which represents the geographic types of a trip</p></div><div class="toggleContainer block">
<span class="toggle">Linear Supertypes</span>
<div class="superTypes hiddenContent"><span class="extype" name="scala.AnyRef">AnyRef</span>, <span class="extype" name="scala.Any">Any</span></div>
</div><div class="toggleContainer block">
Expand Down
2 changes: 1 addition & 1 deletion docs/com/geobase/model/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h4 class="signature">
<img src="../../../lib/permalink.png" alt="Permalink" />
</a>
</span>
<p class="shortcomment cmt">An enumeration which represents the geograpic types of a trip</p>
<p class="shortcomment cmt">An enumeration which represents the geographic types of a trip</p>
</li></ol>
</div>

Expand Down
8 changes: 4 additions & 4 deletions docs/com/geobase/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h4 class="signature">
based on <a href="https://github.com/opentraveldata/opentraveldata">
opentraveldata</a> as well as other mappings (airlines, currencies, ...).
This tool also provides classic time-oriented methods such as the
computation of a trip duration.</p><p>Here are a few exemples:</p><pre><span class="kw">import</span> com.geobase.GeoBase
computation of a trip duration.</p><p>Here are a few examples:</p><pre><span class="kw">import</span> com.geobase.GeoBase

<span class="kw">val</span> geoBase = <span class="kw">new</span> GeoBase()

Expand All @@ -100,11 +100,11 @@ <h4 class="signature">
the possibility to <b>broadcast GeoBase</b>).</p><p>Opentraveldata is an accurate and maintained source of various travel
mappings. This scala wrapper around opentraveldata mostly uses this
file: <a href="https://github.com/opentraveldata/opentraveldata/tree/master/opentraveldata/optd_por_public.csv">
optd_por_public.csv</a>.</p><p>Getters all have a return type embedded within the Try monade. Throwing
optd_por_public.csv</a>.</p><p>Getters all have a return type embedded within the Try monad. Throwing
exceptions as is when one might request mappings for non existing locations,
isn't realy the scala way, and simply embedding the result in the Option
isn't really the scala way, and simply embedding the result in the Option
monad doesn't give the user the possibility to understand what went wrong.
Thus the usage of the Try monade.</p><p>Source <a href="https://github.com/xavierguihot/geobase/blob/master/src/main/scala/com/geobase/GeoBase.scala">
Thus the usage of the Try monad.</p><p>Source <a href="https://github.com/xavierguihot/geobase/blob/master/src/main/scala/com/geobase/GeoBase.scala">
GeoBase</a>
</p></div><dl class="attributes block"> <dt>Since</dt><dd><p>2016-05</p></dd></dl></div>
</li></ol>
Expand Down
28 changes: 14 additions & 14 deletions src/main/scala/com/geobase/GeoBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import cats.implicits._
* This tool also provides classic time-oriented methods such as the
* computation of a trip duration.
*
* Here are a few exemples:
* Here are a few examples:
*
* {{{
* import com.geobase.GeoBase
Expand All @@ -49,11 +49,11 @@ import cats.implicits._
* file: <a href="https://github.com/opentraveldata/opentraveldata/tree/master/opentraveldata/optd_por_public.csv">
* optd_por_public.csv</a>.
*
* Getters all have a return type embedded within the Try monade. Throwing
* Getters all have a return type embedded within the Try monad. Throwing
* exceptions as is when one might request mappings for non existing locations,
* isn't realy the scala way, and simply embedding the result in the Option
* isn't really the scala way, and simply embedding the result in the Option
* monad doesn't give the user the possibility to understand what went wrong.
* Thus the usage of the Try monade.
* Thus the usage of the Try monad.
*
* Source <a href="https://github.com/xavierguihot/geobase/blob/master/src/main/scala/com/geobase/GeoBase.scala">
* GeoBase</a>
Expand Down Expand Up @@ -147,7 +147,7 @@ class GeoBase() extends Serializable {

/** Returns the continent associated to the given airport, city or country.
*
* Possible values: EU (Eurrope) - NA (North America) - SA (South Africa) -
* Possible values: EU (Europe) - NA (North America) - SA (South Africa) -
* AF (Africa) - AS (Asia) - AN (Antarctica) - OC (Oceania).
*
* {{{
Expand Down Expand Up @@ -394,7 +394,7 @@ class GeoBase() extends Serializable {
format: String = "yyyyMMdd"
): Try[Int] =
timeZone(location).map(timeZone => {
val dateTime = new SimpleDateFormat(format).parse(localDate).getTime()
val dateTime = new SimpleDateFormat(format).parse(localDate).getTime
TimeZone.getTimeZone(timeZone).getOffset(dateTime) / 60000
})

Expand Down Expand Up @@ -439,7 +439,7 @@ class GeoBase() extends Serializable {

/** Returns the trip duration between two locations (airport or city).
*
* In the travel indeuxtry, the trip duration is synonym with elapsed flying
* In the travel industry, the trip duration is synonym with elapsed flying
* time (EFT).
*
* This is meant to be used to compute the trip duration for a segment/bound
Expand Down Expand Up @@ -495,7 +495,7 @@ class GeoBase() extends Serializable {
val depDate = formatter.parse(gmtDepDate)
val arrDate = formatter.parse(gmtArrDate)

val tripDurationMillis = arrDate.getTime() - depDate.getTime()
val tripDurationMillis = arrDate.getTime - depDate.getTime

if (tripDurationMillis < 0)
Failure(
Expand Down Expand Up @@ -525,7 +525,7 @@ class GeoBase() extends Serializable {
* assert(geoBase.geoType(List("US", "bbb", "NCE", "aaa")) == Failure(GeoBaseException: Unknown locations \"bbb\", \"aaa\"))
* }}}
*
* @param locations a list of cities/ariports/countries representing the trip
* @param locations a list of cities/airports/countries representing the trip
* @return the type of the trip (a GeoType "enum" value, such as DOMESTIC)
*/
def geoType(locations: List[String]): Try[GeoType] = {
Expand Down Expand Up @@ -577,7 +577,7 @@ class GeoBase() extends Serializable {
* @param location the airport or city for which to find nearby airports
* @param radius the maximum distance (in km) for which an airport is
* considered close.
* @return the sorted per incresaing distance list nearby airports
* @return the sorted per increasing distance list nearby airports
*/
def nearbyAirports(location: String, radius: Int): Try[List[String]] =
for {
Expand All @@ -600,7 +600,7 @@ class GeoBase() extends Serializable {
* @param location the airport or city for which to find nearby airports.
* @param radius the maximum distance (in km) for which an airport is
* considered close.
* @return the sorted per incresaing distance list of tuples (airport,
* @return the sorted per increasing distance list of tuples (airport,
* distance).
*/
def nearbyAirportsWithDetails(
Expand All @@ -616,11 +616,11 @@ class GeoBase() extends Serializable {
val nearbyAirports = for {

randomLocation <- airportsAndCities.keys.toList
if (airportsAndCities(randomLocation).isAirport())
if airportsAndCities(randomLocation).isAirport

distance = distanceBetween(location, randomLocation).getOrElse(-1)
if (distance > 0)
if (distance <= radius)
if distance > 0
if distance <= radius

} yield (randomLocation, distance)

Expand Down
22 changes: 7 additions & 15 deletions src/main/scala/com/geobase/load/Loader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.geobase.model.{Airline, AirportOrCity, Country}

import scala.io.Source

/** Functions called when initializating GeoBase (data loads).
/** Functions called when initializing GeoBase (data loads).
*
* @author Xavier Guihot
* @since 2017-01
Expand All @@ -22,7 +22,7 @@ private[geobase] object Loader {
.fromURL(getClass.getResource("/optd_por_public.csv"), "UTF-8")
.getLines()
.map(_.split("\\^", -1))
// Only lines for which the last date of validity is not definied:
// Only lines for which the last date of validity is not defined:
.filter(_(14).isEmpty)
.map(splitLine => {

Expand All @@ -45,21 +45,14 @@ private[geobase] object Loader {
.map {
// Since we have iata codes shared by both an airport and a city
// (NCE for instance), we choose to only keep the airport one:
case (airportOrCityCode, locations) => {

val location = locations.map {
case (airportOrCityCode, location) => location
}.foldLeft(locations.head._2) {
case (locA, locB) => if (locA.isAirport()) locA else locB
}

case (airportOrCityCode, locations) =>
val location = locations
.map(_._2)
.reduceLeft((locA, locB) => if (locA.isAirport) locA else locB)
(airportOrCityCode, location)
}
}
.toMap
}

/** Loads the country dataset */
def loadCountries(): Map[String, Country] = {

Source
Expand All @@ -83,7 +76,6 @@ private[geobase] object Loader {
.toMap
}

/** Loads the airline dataset */
def loadAirlines(): Map[String, Airline] = {

// Airline code to airline name:
Expand Down Expand Up @@ -129,6 +121,6 @@ private[geobase] object Loader {
(code, Airline(code, country, name))
// No information on the country, but several names available:
case (code, Airline(_, "", name) :: _) => (code, Airline(code, "", name))
}.toMap
}
}
}
Loading

0 comments on commit fc48696

Please sign in to comment.