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

fit-decoder

v1.0.5

Published

Javascript library for parsing ANT/Garmin .FIT files

Downloads

157

Readme

fit-decoder

Javascript library for parsing ANT/Garmin .FIT files desinged to help developers to deal with complexities of FIT binary format. It's a small zero-dependency unopinionated library. Supports Node.js and browser environments.

The Flexible and Interoperable Data Transfer (FIT) protocol is a format designed specifically for the storing and sharing of data that originates from sport, fitness and health devices. It is specifically designed to be compact, interoperable and extensible.

Install

$ npm install -s fit-decoder 

Usage

// Require the module
const fitDecoder = require('fit-decoder');

// fit2json expects binary represetnation in FIT format as ArrayBuffer
// You can get it by reading a file in Node:

const fs = require('fs').promises;
const file = await fs.readFile('activity.fit');
const buffer = file.buffer;

// Or, by fetching it from S3 in the browser
const awsRequest = await s3.getObject({ Bucket: 'fit', Key: 'activity.fit' }).promise();
const buffer = awsRequest.Body.buffer;


// fit2json converts binary FIT into a raw JSON representation. No record names, types or values 
// are parsed. It is useful for low level data analysis
const jsonRaw = fitDecoder.fit2json(buffer);

// parseRecords converts raw JSON format into readable format using current 
// Global FIT Profile (SDK 21.47.00)
// It also performs simple conversions for some data formats like time, distance, coordinates.
const json = fitDecoder.parseRecords(jsonRaw);


// The library also includes a couple of utils for simple data recovery.

// getRecordFieldValue returns the timerange, covered by a fit file
const { minTimestamp, maxTimestamp } = fitUtils.getTimeLimits(json);

// getRecordFieldValue returns an array of values of one field of one record type
const powerArray = fitDecoder.getRecordFieldValue(json, 'record', 'power');

//getValueOverTime returns values for one field of one record type over time
const powerOverTime = fitDecoder.getValueOverTime(json, 'record', 'power');

Documentation

fit2json(ArrayBuffer)

fit2json designed to simpliy convert binary FIT data representation into more easy-to-deal JSON format. It doesn't do any opinionated parsing. Data stored as is, record and field names are left in numeric format. No data is removed. Illegal fields are left as is. Developer data field names are not updated.

This is an example of a record after the conversion:

{
  recordHeader: {
      headerType: 1,
      messageType: 2,
      localMessageType: 0,
  },
  globalMessageNumber: 0,
  fields: [
      { recordNumber: 3, baseType: 140, data: 3958807899 },
      { recordNumber: 4, baseType: 134, data: 961672796 },
      { recordNumber: 7, baseType: 134, data: 4294967295 },
      { recordNumber: 1, baseType: 132, data: 1 },
      { recordNumber: 2, baseType: 132, data: 2833 },
      { recordNumber: 5, baseType: 132, data: 65535 },
      { recordNumber: 0, baseType: 0, data: 4 },
  ],
}

###parseRecords(json, options) FIT format uses FIT Profiles to convey the meaning of data. This libaray can parse the FIT data using current Global FIT Profile. The Global FIT Profile is maintained by Garmin Canada Inc and it's distributed as an XLSX file in FIT SDK

parseRecords converts raw JSON representation result from fit2json and creates readable records like this:

{
  "type": "record",
  "data": {
      "87": 0,
      "timestamp": "2020-06-21T11:47:51.000Z",
      "distance": 1451.93,
      "speed": 2.538,
      "cadence": 29,
      "fractional_cadence": 0
  },
},

It performs some data format conversions:

  • Garmin timestamps are converted to Javascript Dates
  • Coordinates are converted from semicircles to degrees
  • Distance is converted to meters
  • Speed is converted to meters/sec

options allows to customize parsing. Currently supported options:

  • skipUnknown skips all records and fiels, not found in Global FIT profile. False by default.

License

MIT license; see LICENSE.