--- a/src/main/scala/Util.scala Thu Aug 25 12:56:24 2011 -0400
+++ b/src/main/scala/Util.scala Thu Aug 25 14:07:54 2011 -0400
@@ -54,7 +54,8 @@
* @return the file on disk
*/
def fromClasspath(path:String):File = {
- val dir = new File("/tmp", "virtual-trainer-" + scala.util.Random.nextInt(10000).toString)
+ val dir = new File(System.getProperty("java.io.tmpdir"),
+ "virtual-trainer-" + scala.util.Random.nextInt(10000).toString)
if (! dir.mkdir()) logger.error("Couldn't extract %s from jar to %s" format (path, dir.getAbsolutePath))
val entries = getResourceListing(path) foreach { entry =>
val url = classloader.getResource(path + entry)
--- a/src/main/scala/Workout.scala Thu Aug 25 12:56:24 2011 -0400
+++ b/src/main/scala/Workout.scala Thu Aug 25 14:07:54 2011 -0400
@@ -37,7 +37,7 @@
activity:String,
date: Long,
distance: Long,
- events:scala.collection.immutable.Seq[Event]) {
+ events:Seq[Event]) {
def asJSON:String = {
val formattedEvents = events map { _.asJSON } mkString ("[ ", ", ", " ]")
@@ -47,15 +47,27 @@
}
case class Event(@Key("t") timestamp:Long,
- @Key("c") coordinates:Option[(Double, Double, Option[Double])],
+ @Key("c") coordinates:Option[scala.collection.Seq[Double]],
@Key("s") status:Option[String]) {
+ def lon = longitude
+ def longitude = coordinates map { _.head }
+
+ def lat = latitude
+ def latitude = coordinates map { _(1) }
+
+ def alt = altitude
+ def altitude = coordinates flatMap { _.lift(2) }
+
def asJSON:String = {
val tString = """"t": "%s"""" format timestamp.toString
val cString = {
-// val c = coordinates.asInstanceOf[com.mongodb.BasicDBList]
- // coordinates map { case (lon, lat, alt) => ", [%f, %f, %f]" format (lon, lat, alt.get) } getOrElse ""
- coordinates.asInstanceOf[Option[com.mongodb.BasicDBList]] map { c => """, "c": "%s"""" format c.toString } getOrElse ""
+ coordinates match {
+ case Some(lon :: lat :: alt :: Nil) => """, [%f, %f, %f]""" format (lon, lat, alt)
+ case Some(lon :: lat :: Nil) => """, [%f, %f]""" format (lon, lat)
+ case None => ""
+ case _ => sys.error("found weird coordinate pattern: " + coordinates)
+ }
}
val sString = status map { s => """, "s": "%s"""" format s.toString } getOrElse ""
"{ %s%s%s }" format (tString, cString, sString)