Skip to content

Commit

Permalink
Assert in tests, build standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Dec 27, 2013
1 parent d44690f commit 38e2f03
Show file tree
Hide file tree
Showing 6 changed files with 2,184 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Convert [TCX](https://en.wikipedia.org/wiki/Training_Center_XML) files to

npm install tcx

Standalone:

https://raw.github.com/mapbox/tcx/master/tcx.js

## usage

```js
Expand All @@ -15,3 +19,10 @@ var parse = require('tcx');
// a tcx file dom, via xmldom
parse(tcxDom);
```

## api

### `parse(xmlDom)`

Given a DOM of TCX data either as a browser DOM object or via `xmldom` or
`jsdom`, parse and return a GeoJSON FeatureCollection object.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,24 @@ module.exports = function(doc) {
var i,
laps = get(doc, 'Lap'),
// a feature collection
gj = fc();
gj = fc(),
totalMeters = 0,
startTime = '',
totalSeconds = 0;

gj.properties = {
totalMeters: 0,
totalSeconds: 0,
startTime: ''
};

for (i = 0; i < laps.length; i++) {
gj.features.push(getLinestring(laps[i]));
gj.properties.totalMeters += parseFloat(nodeVal(get1(laps[i], 'DistanceMeters')));
gj.properties.totalSeconds += parseFloat(nodeVal(get1(laps[i], 'TotalTimeSeconds')));
gj.properties.startTime += attr(laps[i], 'StartTime');
}

function getLinestring(node) {
var j, pts = get(node, 'Trackpoint'), line = [];
for (j = 0; j < pts.length; j++) {
Expand All @@ -63,6 +77,7 @@ module.exports = function(doc) {
}
};
}

function getProperties(node) {
var meta = ['TotalTimeSeconds', 'DistanceMeters', 'Calories',
'MaximumSpeed'],
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "parse tcx files, generating geojson",
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
"test": "mocha -R spec",
"build": "browserify -s tcx index.js > tcx.js"
},
"repository": {
"type": "git",
Expand All @@ -24,6 +25,7 @@
"xmldom": "~3.4.0"
},
"devDependencies": {
"expect.js": "~0.2.0"
"expect.js": "~0.2.0",
"browserify": "~3.14.1"
}
}
Loading

0 comments on commit 38e2f03

Please sign in to comment.