# Sports Lib
*A Library for processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc*
About
-----
Sports Lib tries to achieve a common domain model and lib for sport activity formats
such as GPX, TCX, FIT and other popular formats.
Currently the support is limited to the main formats: GPX, TCX, FIT and JSON*
*JSON is for specific services while GPX, TCX, FIT should be compatible with the move common services,
such as Strava, Movescount, Garmin, Polar and any other service that supports the above formats.
Install
-------
- Install via npm
`npm install @sports-alliance/sports-lib --save`
Examples
=======
GPX
---
```typescript
import {SportsLib} from '@sports-alliance/sports-lib';
// For GPX you need a string
const gpxString = 'Some string from a file etc';
SportsLib.importFromGPX(gpxString).then((event)=>{
// do Stuff with the file
const distance = event.getDistance();
const duration = event.getDuration();
});
```
TCX
---
```typescript
import {SportsLib} from '@sports-alliance/sports-lib';
// For TCX you need a string
const tcxString = 'Some string from a file etc';
SportsLib.importFromTCX((new DOMParser()).parseFromString(tcxString, 'application/xml')).then((event)=>{
// do Stuff with the file
const distance = event.getDistance();
const duration = event.getDuration();
});
```
FIT
---
```typescript
import {SportsLib} from '@sports-alliance/sports-lib';
// For FIT you need an ArrayBuffer (binary)
SportsLib.importFromFit(arrayBuffer).then((event)=>{
// do Stuff with the file
const distance = event.getDistance();
const duration = event.getDuration();
});
```
Export
---
```typescript
// Get an event as seen above
const gpxString = await new EventExporterGPX().getAsString(event);
// Send the blob
const blob = new Blob(
[jsonString],
{type: new EventExporterGPX().fileType},
);
```
Example converting a FIT file to GPX
---
Thanks to [@guikeller](https://github.com/guikeller)
```typescript
import fs from 'fs';
import sportsLibPkg from '@sports-alliance/sports-lib';
import exporterPkg from '@sports-alliance/sports-lib/lib/events/adapters/exporters/exporter.gpx.js'
const { SportsLib } = sportsLibPkg;
const { EventExporterGPX } = exporterPkg;
// Input and output file path
const inputFilePath = '/tmp/test.fit';
const outputGpxFilePath = '/tmp/test.gpx';
// reads the FIT file into memory
const inputFile = fs.readFileSync(inputFilePath, null);
if (!inputFile || !inputFile.buffer) {
console.error('Ooops, could not read the inputFile or it does not exists, see details below');
console.error(JSON.stringify(inputFilePath));
return;
}
const inputFileBuffer = inputFile.buffer;
// uses lib to read the FIT file
SportsLib.importFromFit(inputFileBuffer).then((event) => {
// convert to gpx
const gpxPromise = new EventExporterGPX().getAsString(event);
gpxPromise.then((gpxString) => {
// writes the gpx to file
fs.writeFileSync(outputGpxFilePath, gpxString, (wError) => {
if (wError) {
console.error('Ooops, something went wrong while saving the GPX file, see details below.');
console.error(JSON.stringify(wError));
}
});
// all done, celebrate!
console.log('Converted FIT file to GPX successfully!');
console.log('GPX file saved here: ' + outputGpxFilePath);
}).catch((cError) => {
console.error('Ooops, something went wrong while converting the FIT file, see details below');
console.error(JSON.stringify(cError));
});
});
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
体育库 一个用于处理来自Strava,Movescount,Garmin,Polar等服务的GPX,TCX,FIT和JSON文件的库 关于 Sports Lib尝试为体育活动格式(例如GPX,TCX,FIT和其他流行格式)实现通用域模型和库。 目前,支持仅限于以下主要格式:GPX,TCX,FIT和JSON * * JSON用于特定服务,而GPX,TCX,FIT应与移动常用服务兼容,例如Strava,Movescount,Garmin,Polar和支持上述格式的任何其他服务。 安装 通过npm安装 npm install @sports-alliance/sports-lib --save 例子 GPX import { SportsLib } from '@sports-alliance/sports-lib' ; // For GPX you need a string cons
资源详情
资源评论
资源推荐
收起资源包目录
sports-lib:一个用于处理来自Strava,Movescount,Garmin,Polar等服务的GPX,TCX,FIT和JSON文件的库 (339个子文件)
.codebeatignore 7B
.editorconfig 245B
20181013_kona_ironman.fit 1.83MB
garmin.fit 440KB
garmin_828989227.fit 316KB
suunto-uphill.fit 251KB
TrailRun20200215111630.fit 248KB
OutdoorRun20200314145229.fit 115KB
20151130_virtualride_971150603.fit 93KB
broken.fit 84KB
20190811_ride_3939576645.fit 76KB
5e5fde38c2de24635a30d383.fit 73KB
5e5fde38c2de24635a30d383-2.fit 73KB
2020-01-09_virtualride.fit 38KB
20171011_run_2088390344.fit 14KB
.gitignore 539B
garmin_828989227.gpx 5.11MB
strava.gpx 2.59MB
sports-tracker.gpx 2.19MB
20160119_virtualride_1023440829.gpx 1.3MB
movescount.gpx 1.23MB
20160422_virtualride_553573871.gpx 1.12MB
mytrail_export.gpx 818KB
20190929_ride_4108490848.gpx 727KB
20190721_ride_2551623996.gpx 612KB
amazfit.gpx 409KB
20170319_run_906581465.gpx 291KB
20171008_run_2067489619.gpx 182KB
garmin.gpx 79KB
garmin.tcx.json 3.48MB
polar.tcx.json 3.37MB
strava.gpx.json 2.7MB
sports-tracker.gpx.json 2.29MB
suunto.json 1.82MB
movescount.gpx.json 1.23MB
strava_343080886.json 1012KB
strava_3171487458_tcx.json 785KB
strava_2709634581.json 640KB
strava_3171472783_gpx.json 570KB
strava_3183490558.json 567KB
movescount.tcx.json 386KB
strava_3025855594.json 322KB
amazfit.gpx.json 318KB
strava_3183465494.json 194KB
strava_3025376963.json 165KB
strava_3156040843.json 160KB
strava_3182900697.json 158KB
garmin.gpx.json 82KB
move_cycling_strava_stream.json 63KB
miltisport-laps.json 45KB
move_running_strava_stream.json 29KB
multisport.json 20KB
tsconfig.json 5KB
tslint.json 3KB
package.json 2KB
LICENSE 34KB
yarn.lock 163KB
README.md 4KB
CODE_OF_CONDUCT.md 3KB
.npmignore 75B
strava_gap_modelization.png 127KB
garmin_828989227.tcx 8.51MB
garmin.tcx 3.4MB
polar.tcx 3.29MB
20190815_ride_3953195468.tcx 2.06MB
20160126_virtualride_1023441137.tcx 1.6MB
20160223_virtualride_500553714.tcx 1.37MB
20190622_ride_1655245835.tcx 1.32MB
20160911_run_708752345.tcx 833KB
movescount.tcx 502KB
unknown_example.tcx 488KB
20181021_run_3106033902.tcx 292KB
activity.utilities.ts 75KB
data.store.ts 51KB
activities-parsing.integration.spec.ts 44KB
strava-streams-compliance.spec.ts 40KB
importer.suunto.json.ts 32KB
importer.fit.ts 26KB
activity.types.ts 26KB
grade-calculator.spec.ts 14KB
activity.spec.ts 12KB
activity.ts 11KB
activity.utilities.spec.ts 10KB
importer.tcx.ts 10KB
grade-calculator.ts 9KB
importer.fit.mapper.ts 7KB
importer.json.ts 6KB
importer.fit.garmin.device.names.ts 6KB
activity.interface.ts 6KB
stream.spec.ts 5KB
importer.suunto.sml.ts 5KB
importer.gpx.mapper.ts 5KB
event.ts 5KB
importer.tcx.mapper.ts 4KB
importer.gpx.ts 4KB
data.vertical-speed.ts 4KB
exporter.gpx.ts 4KB
data.grade-adjusted-speed.ts 3KB
data.speed.ts 3KB
helpers.ts 3KB
共 339 条
- 1
- 2
- 3
- 4
流浪的夏先森
- 粉丝: 22
- 资源: 4688
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1