1 if (Garmin == undefined) var Garmin = {};
  2 /**
  3  * Copyright � 2007 Garmin Ltd. or its subsidiaries.
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the 'License')
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  *    http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an 'AS IS' BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  * 
 17  * @fileoverview Garmin.Activity A data structure representing an activity
 18  * 
 19  * @author Bobby Yang bobby.yang.at.garmin.com
 20  * @version 1.0
 21  */
 22 /**A data structure for storing data commonly found in various
 23  * formats supported by various gps devices.  Some examples are
 24  * gpx track, gpx route, gpx wayoint, and tcx activity.
 25  * @class Garmin.Activity
 26  * @constructor 
 27  */
 28 Garmin.Activity = function(){};
 29 Garmin.Activity = Class.create();
 30 Garmin.Activity.prototype = {
 31 	
 32 	initialize: function() {
 33 		this.attributes = new Hash();
 34 		this.summary = new Garmin.Sample();
 35 		this.series = new Array();
 36 	},
 37 	
 38 	getAttributes: function() {
 39 		return this.attributes;
 40 	},
 41 	
 42 	getAttribute: function(aKey) {
 43 		return this.attributes[aKey];
 44 	},
 45 	
 46 	setAttribute: function(aKey, aValue) {
 47 		this.attributes[aKey] = aValue;
 48 	},
 49 	
 50 	getSeries: function() {
 51 		return this.series;
 52 	},
 53 	
 54 	getHistorySeries: function() {
 55 		for (var i = 0; i < this.series.length; i++) {
 56 			if (this.series[i].getSeriesType() == Garmin.Series.TYPES.history) {
 57 				return this.series[i];
 58 			}
 59 		}
 60 		return null;
 61 	},
 62 	
 63 	addSeries: function(series) {
 64 		this.series.push(series);
 65 	},
 66 	
 67 	getSingleSeries: function(index) {
 68 		var targetSeries = null;
 69 		if (index >= 0 && index < this.series.length) {
 70 			targetSeries = this.series[index];
 71 		}
 72 		return targetSeries;
 73 	},
 74 	
 75 	getSummary: function() {
 76 		return this.summary;
 77 	},
 78 	
 79 	getSummaryValue: function(sKey) {
 80 		return this.summary.getMeasurement(sKey);
 81 	},
 82 	
 83 	setSummaryValue: function(sKey, sValue, sContext) {
 84 		this.summary.setMeasurement(sKey, sValue, sContext);
 85 	},
 86 	
 87 	getEndTime: function() {
 88 		return this.getSummaryValue(Garmin.Activity.SUMMARY_KEYS.endTime).getValue();
 89 	},	
 90 	
 91 	getStartTime: function() {
 92 		return this.getSummaryValue(Garmin.Activity.SUMMARY_KEYS.startTime).getValue();
 93 	},
 94 	
 95 	printMe: function(tabs) {
 96 		var output = "";
 97 		output += tabs + "\n\n[Activity]\n";
 98 		
 99 		output += tabs + "  attributes:\n";
100 		var attKeys = this.attributes.keys();
101 		for (var i = 0; i < attKeys.length; i++) {
102 			output += tabs + "    " + attKeys[i] + ": " + this.attributes[attKeys[i]] + "\n"; 
103 		}
104 		
105 		output += tabs + "  summary:\n";
106 		output += this.summary.printMe(tabs + "  ");
107 
108 		output += tabs + "  series:\n";		
109 		for (var i = 0; i < this.series.length; i++) {
110 			output += this.series[i].printMe(tabs + "  ");
111 		}
112 		
113 		return output;
114 	},
115 	
116 	toString: function() {
117 		return "[Garmin.Activity]"
118 	}
119 };
120 
121 Garmin.Activity.ATTRIBUTE_KEYS = {
122 	activityName:		"activityName",
123 	activitySport:		"activitySport",
124 	creatorName:		"creatorName",
125 	creatorUnitId:		"creatorUnitId",
126 	creatorProdId:		"creatorProductId",
127 	creatorVersion:		"creatorVersion",
128 	dom:				"documentObjectModel"
129 };
130 
131 Garmin.Activity.SECTION_KEYS = {
132 	gpsSignals:			"gpsSignal",
133 	heartRateSignals:	"heartRateSignal",	
134 	laps:				"laps",
135 	tracks:				"tracks"
136 };
137 
138 Garmin.Activity.SUMMARY_KEYS = {
139 	avgHeartRate:		"averageHeartRate",
140 	calories:			"calories",	
141 	endTime:			"endTime",
142 	intensity:			"intensity",	
143 	maxHeartRate:		"maximumHeartRate",
144 	maxSpeed:			"maximumSpeed",		
145 	startTime:			"startTime",
146 	totalDistance:		"totalDistance",	
147 	totalTime:			"totalTime"
148 };
149 /*
150 // Dynamic include of required libraries and check for Prototype
151 // Code taken from scriptaculous
152 // TODO: put this code in a library and reuse is instead of copying it to new files
153 var GarminActivity = {
154 	require: function(libraryName) {
155 	  // inserting via DOM fails in Safari 2.0, so brute force approach
156 	  document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
157 	},
158 
159 	load: function() {
160 		if((typeof Prototype=='undefined') || 
161 			(typeof Element == 'undefined') || 
162 			(typeof Element.Methods=='undefined') ||
163 			parseFloat(Prototype.Version.split(".")[0] + "." +
164 			Prototype.Version.split(".")[1]) < 1.5) {
165 			throw("GarminActivity requires the Prototype JavaScript framework >= 1.5.0");
166 		}
167 
168 		$A(document.getElementsByTagName("script"))
169 		.findAll(
170 			function(s) {
171 				return (s.src && s.src.match(/GarminActivity\.js(\?.*)?$/))
172 			}
173 		)
174 		.each(
175 			function(s) {
176 				var path = s.src.replace(/GarminActivity\.js(\?.*)?$/,'../../');
177 				var includes = s.src.match(/\?.*load=([a-z,]*)/);
178 				var dependencies = 'garmin/activity/GarminMeasurement' +
179 									',garmin/activity/GarminSample' +
180 									',garmin/activity/GarminSeries';
181 			    (includes ? includes[1] : dependencies).split(',').each(
182 					function(include) {
183 						GarminActivity.require(path+include+'.js') 
184 					}
185 				);
186 			}
187 		);
188 	}
189 }
190 
191 GarminActivity.load();*/