~ fixed getAscent and getBounds to take into account events without coordinates (eg pauses)
authortgambet
Fri, 26 Aug 2011 14:16:11 -0400
changeset 119 fcb3b039cf94
parent 118 ce7721bbc705
child 120 41c2ee29ab55
~ fixed getAscent and getBounds to take into account events without coordinates (eg pauses)
src/main/resources/scripts/map.js
--- a/src/main/resources/scripts/map.js	Fri Aug 26 13:36:42 2011 -0400
+++ b/src/main/resources/scripts/map.js	Fri Aug 26 14:16:11 2011 -0400
@@ -40,6 +40,8 @@
 		var minLong = events[0].c[1];
 		var maxLong = minLong;
 		for (i=1; i < events.length; i++) {
+			if (!events[i].c)
+				continue;
 			if ((lat = events[i].c[0]) < minLat) {
 				minLat = lat;
 				continue;
@@ -70,6 +72,7 @@
 
 function getWorkouts() {
 	return Util.requestJSON('http://localhost:2719/user/dummy@example.com/workouts');
+	//return Util.requestJSON('http://localhost:2719/user/jdoe/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" } ];
 }
 
@@ -106,7 +109,28 @@
 }
 
 function getAscent(events) {
-	return events[events.length - 1].c[2] - events[0].c[2];
+	var first, last;
+	first = (function() {
+		var i = 0;
+		while (!events[i].c) {
+			i++;
+			if (!events[i])
+				return 0;
+			continue;
+		}
+		return events[i].c[2];
+	})();
+	last = (function() {
+		var i = events.length - 1;
+		while (!events[i].c) {
+			i--;
+			if (!events[i])
+				return 0;
+			continue;
+		}
+		return events[i].c[2];
+	})();
+	return last - first;
 }
 
 // returns min/km