--- a/src/main/scala/Workout.scala Wed Aug 24 17:53:46 2011 -0400
+++ b/src/main/scala/Workout.scala Thu Aug 25 10:36:04 2011 -0400
@@ -36,13 +36,30 @@
activity:String,
events:List[Event]) {
- def asJSON:String = grater[Workout].asDBObject(this).toString
+ def asJSON:String = {
+ val formattedEvents = events map { _.asJSON } mkString ("[ ", ", ", " ]")
+ """{ "activity": "%s", "events": %s }""" format (activity, formattedEvents)
+ }
}
case class Event(@Key("t") timestamp:Long,
@Key("c") coordinates:Option[(Double, Double, Option[Double])],
- @Key("s") status:Option[String])
+ @Key("s") status:Option[String]) {
+
+ 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 ""
+ }
+ val sString = status map { s => """, "s": "%s"""" format s.toString } getOrElse ""
+ "{ %s%s%s }" format (tString, cString, sString)
+ }
+
+}
+
object WorkoutDAO extends SalatDAO[Workout, ObjectId](collection = MongoConnection("gw42.w3.org", 27017)("virtual_trainer")("user/workouts")) {