+ stats from JSON
authortgambet
Fri, 26 Aug 2011 13:22:13 -0400
changeset 117 2f630fc466d8
parent 116 62a6ef3e6702
child 118 ce7721bbc705
+ stats from JSON
src/main/resources/scripts/map.js
--- a/src/main/resources/scripts/map.js	Fri Aug 26 13:20:55 2011 -0400
+++ b/src/main/resources/scripts/map.js	Fri Aug 26 13:22:13 2011 -0400
@@ -69,8 +69,8 @@
 }
 
 function getWorkouts() {
-	//return Util.requestJSON('http://localhost:2719/user/dummy@example.com/workouts');
-	return [ { "activity": "http://dbpedia.org/resource/Running", "date": 1312971214000, "duration": 6652, "distance": 12.000000, "json": "http://localhost:2719/user/dummy@example.com/workout/4e56a110ccf2406c3515bccb.json", "gpx": "http://localhost:2719/user/dummy@example.com/workout/4e56a110ccf2406c3515bccb.gpx" }, { "activity": "http://dbpedia.org/resource/Running", "date": 1309083594000, "duration": 14703, "distance": 12.000000, "json": "http://localhost:2719/user/dummy@example.com/workout/4e56a250ccf23d3128a27d0f.json", "gpx": "http://localhost:2719/user/dummy@example.com/workout/4e56a250ccf23d3128a27d0f.gpx" } ];
+	return Util.requestJSON('http://localhost:2719/user/dummy@example.com/workouts');
+	//return [ { "activity": "http://dbpedia.org/resource/Running", "date": 1312971214000, "duration": 6652, "distance": 12.000000, "json": "http://localhost:2719/user/dummy@example.com/workout/4e56a110ccf2406c3515bccb.json", "gpx": "http://localhost:2719/user/dummy@example.com/workout/4e56a110ccf2406c3515bccb.gpx" }, { "activity": "http://dbpedia.org/resource/Running", "date": 1309083594000, "duration": 14703, "distance": 12.000000, "json": "http://localhost:2719/user/dummy@example.com/workout/4e56a250ccf23d3128a27d0f.json", "gpx": "http://localhost:2719/user/dummy@example.com/workout/4e56a250ccf23d3128a27d0f.gpx" } ];
 }
 
 function getWorkout(uri) {
@@ -96,20 +96,23 @@
 
 function updateStats(workout) {
 	var list = document.getElementById('stats').getElementsByTagName('ul')[0];
-	list.getElementsByClassName('date')[0].getElementsByTagName('span')[0].innerHTML = workout.date;
-	list.getElementsByClassName('start')[0].getElementsByTagName('span')[0].innerHTML = workout.date;
+	list.getElementsByClassName('date')[0].getElementsByTagName('span')[0].innerHTML = Util.formatDate(workout.date);
+	list.getElementsByClassName('start')[0].getElementsByTagName('span')[0].innerHTML = Util.formatTime2(workout.date);
 	list.getElementsByClassName('duration')[0].getElementsByTagName('span')[0].innerHTML = workout.duration;
-	list.getElementsByClassName('distance')[0].getElementsByTagName('span')[0].innerHTML = workout.distance;
-	list.getElementsByClassName('pace')[0].getElementsByTagName('span')[0].innerHTML = workout.distance;
-	list.getElementsByClassName('speed')[0].getElementsByTagName('span')[0].innerHTML = workout.distance;
-	list.getElementsByClassName('climb')[0].getElementsByTagName('span')[0].innerHTML = workout.climb;
+	list.getElementsByClassName('distance')[0].getElementsByTagName('span')[0].innerHTML = Util.formatDistance(workout.distance);
+	list.getElementsByClassName('pace')[0].getElementsByTagName('span')[0].innerHTML = parseInt(workout.duration)/parseInt(workout.distance);
+	list.getElementsByClassName('speed')[0].getElementsByTagName('span')[0].innerHTML = workout.distance / workout.duration;
+	list.getElementsByClassName('climb')[0].getElementsByTagName('span')[0].innerHTML = getAscent(workout.events);
+}
+
+function getAscent(events) {
+	return events[events.length - 1].c[2] - events[0].c[2];
 }
 
 function showResult(workout) {
 	// update the map
 	OLMap.clearMap();
 	OLMap.addTrail(workout.gpx, "red");
-	//OLMap.addTrail("Jun-26-11.gpx", "red");
 	// fetch the json data containing the events
 	workout = getWorkout(workout.json);
 	// center the map on the events