@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
49 lines (48 loc) • 1.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouteStream = void 0;
const data_store_1 = require("../data/data.store");
const helpers_1 = require("../events/utilities/helpers");
class RouteStream {
constructor(type, data) {
this.data = [];
this.type = type;
if (data) {
this.data = data;
}
}
getData(onlyNumeric = false, filterInfinity = false) {
if (!onlyNumeric && !filterInfinity) {
return this.data;
}
return this.data.filter(dataItem => !this.shouldDataBeFiltered(dataItem, onlyNumeric, filterInfinity));
}
setData(data) {
this.data = data;
return this;
}
getStreamDataByIndex(onlyNumeric = false, filterInfinity = false) {
return this.data.reduce((accu, dataItem, index) => {
if (this.shouldDataBeFiltered(dataItem, onlyNumeric, filterInfinity)) {
return accu;
}
accu.push({ index, value: dataItem });
return accu;
}, []);
}
isExportable() {
return (!data_store_1.DynamicDataLoader.isUnitDerivedDataType(this.type) &&
!data_store_1.DynamicDataLoader.isSpeedDerivedDataType(this.type) &&
!data_store_1.DynamicDataLoader.isBlackListedStream(this.type));
}
toJSON() {
return {
type: this.type,
data: this.data
};
}
shouldDataBeFiltered(data, onlyNumeric, filterInfinity) {
return (onlyNumeric && !(0, helpers_1.isNumber)(data)) || (filterInfinity && (data === Infinity || data === -Infinity));
}
}
exports.RouteStream = RouteStream;