@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
82 lines (81 loc) • 4.59 kB
JavaScript
;
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_battery_consumption_1 = require("../../../../data/data.battery-consumption");
const data_battery_life_estimation_1 = require("../../../../data/data.battery-life-estimation");
const activity_parsing_options_1 = require("../../../../activities/activity-parsing-options");
describe('EventImporterFIT Battery Stats', () => {
const fitFilePath = path.join(__dirname, '../../../../../samples/fit/suunto-bat.fit');
it.each(['raw', 'changes'])('should parse suunto-bat.fit and extract battery consumption and life estimation in %s mode', (deviceInfoMode) => __awaiter(void 0, void 0, void 0, function* () {
const fileContent = fs.readFileSync(fitFilePath);
const arrayBuffer = fileContent.buffer.slice(fileContent.byteOffset, fileContent.byteOffset + fileContent.byteLength);
// Mock FitFileParser to return raw data if possible, or just use the importer and spy/log
// Since we can't easily spy on the internal parser callback, we'll assume the importer
// attaches device info to activity.creator.devices or we can log from within the importer if needed.
// For now, let's see what the current importer does.
const options = new activity_parsing_options_1.ActivityParsingOptions({ generateUnitStreams: false, deviceInfoMode });
const event = yield importer_fit_1.EventImporterFIT.getFromArrayBuffer(arrayBuffer, options, 'Battery Test Activity');
const activity = event.getFirstActivity();
// Check for Battery Consumption
const consumptionStat = activity.getStat(data_battery_consumption_1.DataBatteryConsumption.type);
expect(consumptionStat).toBeDefined();
if (consumptionStat) {
// Expect 5% drop based on suunto-bat.fit data
expect(consumptionStat.getValue()).toBe(5);
}
// Check for Battery Life Estimation
const lifeEstStat = activity.getStat(data_battery_life_estimation_1.DataBatteryLifeEstimation.type);
expect(lifeEstStat).toBeDefined();
if (lifeEstStat) {
// Duration and consumption imply approx 25h (90180s)
// Allow some margin for exact timestamp differences
const val = lifeEstStat.getValue();
expect(val).toBeGreaterThan(90000);
expect(val).toBeLessThan(90500);
}
}));
});