UNPKG

@sports-alliance/sports-lib

Version:

A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc

84 lines (83 loc) 4.84 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const importer_fit_1 = require("./importer.fit"); const data_ground_time_1 = require("../../../../data/data.ground-time"); const data_ground_contact_time_1 = require("../../../../data/data.ground-contact-time"); const toArrayBuffer = (filePath) => { const fileContent = fs.readFileSync(filePath); return fileContent.buffer.slice(fileContent.byteOffset, fileContent.byteOffset + fileContent.byteLength); }; const getFiniteValues = (values) => { return values.filter((value) => Number.isFinite(value)); }; describe('EventImporterFIT Ground Time integration', () => { it('should fallback Ground Contact Time to Ground Time when stance_time is missing', () => __awaiter(void 0, void 0, void 0, function* () { const fitFilePath = path.join(__dirname, '../../../../specs/fixtures/runs/fit/6782987395.fit'); const event = yield importer_fit_1.EventImporterFIT.getFromArrayBuffer(toArrayBuffer(fitFilePath)); const activity = event.getFirstActivity(); expect(activity.hasStreamData(data_ground_time_1.DataGroundTime.type)).toBe(true); expect(activity.hasStreamData(data_ground_contact_time_1.DataGroundContactTime.type)).toBe(true); const groundTimeValues = getFiniteValues(activity.getStreamData(data_ground_time_1.DataGroundTime.type)); const groundContactTimeValues = getFiniteValues(activity.getStreamData(data_ground_contact_time_1.DataGroundContactTime.type)); expect(groundTimeValues.length).toBeGreaterThan(0); expect(groundContactTimeValues.length).toBeGreaterThan(0); expect(groundTimeValues[0]).toBe(1216); expect(groundContactTimeValues[0]).toBe(1216); })); it('should keep Ground Time and Ground Contact Time separated when stance_time exists', () => __awaiter(void 0, void 0, void 0, function* () { const fitFilePath = path.join(__dirname, '../../../../specs/fixtures/runs/fit/6860622783.fit'); const event = yield importer_fit_1.EventImporterFIT.getFromArrayBuffer(toArrayBuffer(fitFilePath)); const activity = event.getFirstActivity(); const groundTimeValues = getFiniteValues(activity.getStreamData(data_ground_time_1.DataGroundTime.type)); const groundContactTimeValues = getFiniteValues(activity.getStreamData(data_ground_contact_time_1.DataGroundContactTime.type)); expect(groundTimeValues.length).toBeGreaterThan(0); expect(groundContactTimeValues.length).toBeGreaterThan(0); expect(groundTimeValues[0]).toBe(0); expect(groundContactTimeValues[0]).toBe(296); expect(groundContactTimeValues[0]).not.toBe(groundTimeValues[0]); })); });