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

132 lines (131 loc) 5.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataJumpEvent = exports.DataRotations = exports.DataScore = exports.DataJumpScore = void 0; const data_event_1 = require("./data.event"); const data_distance_1 = require("./data.distance"); const data_speed_1 = require("./data.speed"); const data_duration_1 = require("./data.duration"); const data_number_1 = require("./data.number"); const data_latitude_degrees_1 = require("./data.latitude-degrees"); const data_longitude_degrees_1 = require("./data.longitude-degrees"); const data_jump_distance_1 = require("./data.jump-distance"); class DataJumpScore extends data_number_1.DataNumber { getDisplayValue() { return this.getValue().toFixed(1); } } exports.DataJumpScore = DataJumpScore; DataJumpScore.type = 'Jump Score'; DataJumpScore.unit = ''; DataJumpScore.aliases = ['Score']; /** @deprecated Use DataJumpScore instead. */ exports.DataScore = DataJumpScore; class DataRotations extends data_number_1.DataNumber { } exports.DataRotations = DataRotations; DataRotations.type = 'Rotations'; class DataJumpEvent extends data_event_1.DataEvent { constructor(timestampOrObj, jumpData) { if (typeof timestampOrObj === 'object') { super(timestampOrObj.timestamp); this.jumpData = this.hydrate(timestampOrObj.jumpData); } else { super(timestampOrObj); this.jumpData = this.hydrate(jumpData); } } hydrate(data) { const isFiniteNumber = (value) => { return typeof value === 'number' && Number.isFinite(value); }; const jumpData = { distance: data.distance instanceof data_jump_distance_1.DataJumpDistance ? data.distance : new data_jump_distance_1.DataJumpDistance(data.distance), score: data.score instanceof DataJumpScore ? data.score : new DataJumpScore(data.score) }; const height = data.height instanceof data_distance_1.DataDistance ? data.height : isFiniteNumber(data.height) ? new data_distance_1.DataDistance(data.height) : undefined; if (height !== undefined) { jumpData.height = height; } const hangTime = data.hang_time instanceof data_duration_1.DataDuration ? data.hang_time : isFiniteNumber(data.hang_time) ? new data_duration_1.DataDuration(data.hang_time) : undefined; if (hangTime !== undefined) { jumpData.hang_time = hangTime; } const positionLat = data.position_lat instanceof data_latitude_degrees_1.DataLatitudeDegrees ? data.position_lat : isFiniteNumber(data.position_lat) ? new data_latitude_degrees_1.DataLatitudeDegrees(data.position_lat) : undefined; if (positionLat !== undefined) { jumpData.position_lat = positionLat; } const positionLong = data.position_long instanceof data_longitude_degrees_1.DataLongitudeDegrees ? data.position_long : isFiniteNumber(data.position_long) ? new data_longitude_degrees_1.DataLongitudeDegrees(data.position_long) : undefined; if (positionLong !== undefined) { jumpData.position_long = positionLong; } const speed = data.speed instanceof data_speed_1.DataSpeed ? data.speed : isFiniteNumber(data.speed) ? new data_speed_1.DataSpeed(data.speed) : undefined; if (speed !== undefined) { jumpData.speed = speed; } const rotations = data.rotations instanceof DataRotations ? data.rotations : isFiniteNumber(data.rotations) ? new DataRotations(data.rotations) : undefined; if (rotations !== undefined) { jumpData.rotations = rotations; } return jumpData; } toJSON() { super.toJSON(); const jumpData = { distance: this.jumpData.distance.getValue(), score: this.jumpData.score.getValue() }; if (this.jumpData.height) { jumpData.height = this.jumpData.height.getValue(); } if (this.jumpData.hang_time) { jumpData.hang_time = this.jumpData.hang_time.getValue(); } if (this.jumpData.position_lat) { jumpData.position_lat = this.jumpData.position_lat.getValue(); } if (this.jumpData.position_long) { jumpData.position_long = this.jumpData.position_long.getValue(); } if (this.jumpData.speed) { jumpData.speed = this.jumpData.speed.getValue(); } if (this.jumpData.rotations) { jumpData.rotations = this.jumpData.rotations.getValue(); } return { [DataJumpEvent.type]: { timestamp: this.getValue(), jumpData } }; } } exports.DataJumpEvent = DataJumpEvent; DataJumpEvent.type = 'Jump Event';