--- a/src/main/scala/Workout.scala Thu Aug 25 14:07:54 2011 -0400
+++ b/src/main/scala/Workout.scala Thu Aug 25 14:13:10 2011 -0400
@@ -37,7 +37,7 @@
activity:String,
date: Long,
distance: Long,
- events:Seq[Event]) {
+ events:scala.collection.immutable.Seq[Event]) {
def asJSON:String = {
val formattedEvents = events map { _.asJSON } mkString ("[ ", ", ", " ]")
@@ -47,27 +47,15 @@
}
case class Event(@Key("t") timestamp:Long,
- @Key("c") coordinates:Option[scala.collection.Seq[Double]],
+ @Key("c") coordinates:Option[(Double, Double, Option[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 = {
- 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 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 ""
}
val sString = status map { s => """, "s": "%s"""" format s.toString } getOrElse ""
"{ %s%s%s }" format (tString, cString, sString)