npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tcx-js

v1.0.1

Published

A Node.js library for parsing TCX/XML files, such as from a Garmin GPS device.

Downloads

22

Readme

tcx-js

Purpose

A Node.js library for parsing TCX/XML files, such as from a Garmin GPS device.

tcx-js @ npmjs.com

Implementation

This library was rewritten in TypeScript in July 2019, replacing the previous CoffeeScript implementation.

Several attributes were added to the parsed Trackpoints, such as location in GeoJSON format, and a doctype attribute. These attributes can be useful in Azure CosmosDB.

Examples

Setup

Add tcx-js to your project or package.json file:

npm install tcx-js

Require tcx-js in your code:

tcx = require("tcx-js")

Parse a TCX file from Garmin Connect - JavaScript example

Parsing elapsed time is typically sub-second, even for a marathon run.

The constructor method is now passed the input tcx filename

var infile = "data/activity_twin_cities_marathon.tcx"
var parser = new tcx.Parser(infile);

Get the parsed data:

var activity = parser.activity;
var sport = activity.sport;
var activityId = activity.activityId;
var creator = activity.creator;
var author = activity.author;
var trackpoints = activity.trackpoints;

creator is the device that recorded the data

console.log(JSON.stringify(creator, null, 2)) ->
{
  "type": "Creator",
  "name": "Garmin Forerunner 620",
  "product_id": "1623",
  "unit_id": "3875991210",
  "build_major": "0",
  "build_minor": "0",
  "version_major": "3",
  "version_minor": "0"
}

author is what software created the tcx/xml file

console.log(JSON.stringify(author, null, 2)) ->
{
  "type": "Author",
  "name": "Garmin Connect API",
  "part_number": "006-D2449-00",
  "lang": "en",
  "build_major": "0",
  "build_minor": "0",
  "version_major": "14",
  "version_minor": "10"
}

trackpoints is an Array of the recorded data points

console.log(trackpoints.length) -> 2256

console.log(JSON.stringify(trackpoints[0], null, 2)) ->
{
  "doctype": "trackpoint",
  "time": "2014-10-05T13:07:53.000Z",
  "seq": 1,
  "latitude": 44.97431952506304,
  "longitude": -93.26310088858008,
  "altitude_meters": 257,
  "altitude_feet": 843.1758530183727,
  "distance_meters": 0,
  "distance_miles": 0,
  "distance_km": 0,
  "distance_yds": 0,
  "heart_rate_bpm": 85,
  "speed": 0,
  "cadence": 89,
  "location": {
    "type": "Point",
    "coordinates": [
      -93.26310088858008,
      44.97431952506304
    ]
  },
  "elapsed_sec": 0,
  "elapsed_hhmmss": "00:00:00",
  "epoch_ms": 1412514473000
}

console.log(JSON.stringify(trackpoints[trackpoints.length - 1], null, 2)) ->
{
  "doctype": "trackpoint",
  "time": "2014-10-05T17:22:17.000Z",
  "seq": 2256,
  "latitude": 44.95180849917233,
  "longitude": -93.10493202880025,
  "altitude_meters": 260,
  "altitude_feet": 853.018372703412,
  "distance_meters": 42635.44921875,
  "distance_miles": 26.492439912628996,
  "distance_km": 42.63544921875,
  "distance_yds": 46626.69424622703,
  "heart_rate_bpm": 161,
  "speed": 3.5460000038146977,
  "cadence": 77,
  "location": {
    "type": "Point",
    "coordinates": [
      -93.10493202880025,
      44.95180849917233
    ]
  },
  "elapsed_sec": 15264,
  "elapsed_hhmmss": "04:14:24",
  "epoch_ms": 1412529737000
}

Parse a TCX file from Garmin Connect - TypeScript example

Example program:

import * as fs from "fs";

import { Parser }     from "tcx-js";
import { Activity }   from "tcx-js";
import { Author }     from "tcx-js";
import { Creator }    from "tcx-js";
import { Trackpoint } from "tcx-js";

var infile  = process.argv[2];
var outfile = process.argv[3];

var parser:   Parser   = new Parser(infile);
var activity: Activity = parser.activity;
var creator:  Creator  = activity.creator;
var author:   Author   = activity.author;
var trackpoints : Trackpoint[] = activity.trackpoints;

var jstr : string = JSON.stringify(parser.activity, (key, value) => {
    if (value !== null) {
        return value;
    }
}, 2);
fs.writeFileSync(outfile, jstr);

Execute the above compiled sample program:

node dist/example.js data/activity_twin_cities_marathon.tcx data/activity_twin_cities_marathon.json

Contributions

  • July 2019, Alex VanLaningham - suggestion to reimplement in TypeScript, and Watt/Cadence TCX file.

Release History

  • 2019-07-29, version 1.0.1, Added Activity.sport and Activity.activityId
  • 2019-07-26, version 1.0.0, Library rewritten in TypeScript.
  • 2014-11-09, version 0.1.2, Added optional calculated Trackpoint fields 'elapsed_sec' and 'elapsed_hhmmss'.
  • 2014-11-09, version 0.1.1, Added optional calculated Trackpoint fields 'alt_feet' and 'dist_miles'.
  • 2014-11-09, version 0.1.0, Initial working version, implemented in CoffeeScript.
  • 2014-11-09, version 0.0.1, Alpha 1