@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
86 lines (85 loc) • 7.81 kB
JavaScript
"use strict";
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const importer_fit_1 = require("./importer.fit");
const data_heart_rate_zone_one_duration_1 = require("../../../../data/data.heart-rate-zone-one-duration");
const data_heart_rate_zone_two_duration_1 = require("../../../../data/data.heart-rate-zone-two-duration");
const data_power_zone_one_duration_1 = require("../../../../data/data.power-zone-one-duration");
const data_power_zone_two_duration_1 = require("../../../../data/data.power-zone-two-duration");
const data_power_zone_six_duration_1 = require("../../../../data/data.power-zone-six-duration");
const data_power_zone_seven_duration_1 = require("../../../../data/data.power-zone-seven-duration");
const data_heart_rate_1 = require("../../../../data/data.heart-rate");
const data_power_1 = require("../../../../data/data.power");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
describe('EventImporterFIT Zone Indexing (Garmin vs Suunto)', () => {
it('should correctly map Heart Rate and Power zones from Garmin FIT files (1-indexed)', () => __awaiter(void 0, void 0, void 0, function* () {
const filePath = path_1.default.join(__dirname, '../../../../../samples/fit/file-with-zones.fit');
// Note: file-with-zones.fit is a Garmin file confirmed to have 1-indexed zones
const arrayBuffer = fs_1.default.readFileSync(filePath).buffer;
const event = yield importer_fit_1.EventImporterFIT.getFromArrayBuffer(arrayBuffer);
const activity = event.getActivities()[0];
const hrZone1 = activity.getStat(data_heart_rate_zone_one_duration_1.DataHeartRateZoneOneDuration.type);
const powerZone1 = activity.getStat(data_power_zone_one_duration_1.DataPowerZoneOneDuration.type);
const powerZone2 = activity.getStat(data_power_zone_two_duration_1.DataPowerZoneTwoDuration.type);
const powerZone6 = activity.getStat(data_power_zone_six_duration_1.DataPowerZoneSixDuration.type);
const powerZone7 = activity.getStat(data_power_zone_seven_duration_1.DataPowerZoneSevenDuration.type);
// Verification of Garmin 1-indexed mapping (offset = 1)
expect(powerZone1).toBeDefined();
expect(powerZone1 === null || powerZone1 === void 0 ? void 0 : powerZone1.getValue()).toBeCloseTo(2939.995, 2);
expect(powerZone2 === null || powerZone2 === void 0 ? void 0 : powerZone2.getValue()).toBeCloseTo(2690.028, 2);
expect(powerZone6 === null || powerZone6 === void 0 ? void 0 : powerZone6.getValue()).toBeCloseTo(49.991, 2);
expect(powerZone7 === null || powerZone7 === void 0 ? void 0 : powerZone7.getValue()).toBeCloseTo(14.008, 2);
expect(hrZone1).toBeDefined();
// Garmin HR Zone 1 in this file is index 1 with offset 1 (value 716.01)
expect(hrZone1 === null || hrZone1 === void 0 ? void 0 : hrZone1.getValue()).toBeCloseTo(716.01, 2);
const hrIntensityZones = activity.intensityZones.find(iz => iz.type === data_heart_rate_1.DataHeartRate.type);
expect(hrIntensityZones).toBeDefined();
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone1LowerLimit).toBe(93);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone2LowerLimit).toBe(111);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone3LowerLimit).toBe(130);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone4LowerLimit).toBe(148);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone5LowerLimit).toBe(167);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone6LowerLimit).toBe(185);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone7LowerLimit).toBeUndefined();
const powerIntensityZones = activity.intensityZones.find(iz => iz.type === data_power_1.DataPower.type);
expect(powerIntensityZones).toBeDefined();
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone1LowerLimit).toBe(0);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone2LowerLimit).toBe(129);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone3LowerLimit).toBe(175);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone4LowerLimit).toBe(211);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone5LowerLimit).toBe(245);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone6LowerLimit).toBe(281);
expect(powerIntensityZones === null || powerIntensityZones === void 0 ? void 0 : powerIntensityZones.zone7LowerLimit).toBe(352);
}));
it('should correctly map Heart Rate and Power zones from Suunto FIT files (0-indexed)', () => __awaiter(void 0, void 0, void 0, function* () {
const filePath = path_1.default.join(__dirname, '../../../../specs/fixtures/runs/fit/6909950168.fit');
// Note: 6909950168.fit is a Suunto file with time_in_hr_zone: [ 79.086, 1999.014... ]
const arrayBuffer = fs_1.default.readFileSync(filePath).buffer;
const event = yield importer_fit_1.EventImporterFIT.getFromArrayBuffer(arrayBuffer);
const activity = event.getActivities()[0];
const hrZone1 = activity.getStat(data_heart_rate_zone_one_duration_1.DataHeartRateZoneOneDuration.type);
const hrZone2 = activity.getStat(data_heart_rate_zone_two_duration_1.DataHeartRateZoneTwoDuration.type);
// Verification of Suunto 0-indexed mapping (offset = 0)
expect(hrZone1).toBeDefined();
expect(hrZone1 === null || hrZone1 === void 0 ? void 0 : hrZone1.getValue()).toBeCloseTo(79.086, 3);
expect(hrZone2 === null || hrZone2 === void 0 ? void 0 : hrZone2.getValue()).toBeCloseTo(1999.014, 3);
const hrIntensityZones = activity.intensityZones.find(iz => iz.type === data_heart_rate_1.DataHeartRate.type);
expect(hrIntensityZones).toBeDefined();
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone1Duration).toBeCloseTo(79.086, 3);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone2Duration).toBeCloseTo(1999.014, 3);
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone1LowerLimit).toBeUndefined();
expect(hrIntensityZones === null || hrIntensityZones === void 0 ? void 0 : hrIntensityZones.zone2LowerLimit).toBeUndefined();
}));
});