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

207 lines (205 loc) 10.2 kB
import { ActivityInterface } from '../../activities/activity.interface'; import { StreamInterface } from '../../streams/stream.interface'; import { DataCriticalPower } from '../../data/data.critical-power'; import { DataWPrime } from '../../data/data.w-prime'; import { DataInterface } from '../../data/data.interface'; import { ActivityTypes } from '../../activities/activity.types'; import { StatsClassInterface } from '../../stats/stats.class.interface'; import { DataPowerCurve } from '../../data/data.power-curve'; export declare class ActivityUtilities { private static geoLibAdapter; private static readonly FTP_DURATION_SECONDS; private static readonly FTP_FACTOR; private static readonly INTENSITY_FACTOR_DECIMALS; private static readonly TRAINING_STRESS_SCORE_DECIMALS; private static readonly jumpStatFamilies; /** * Provide average from laps a given stat type */ static getDataTypeAvgFromLaps(activity: ActivityInterface, statType: string, filterOver?: number): number | null; /** * Provide average of a given stream type */ static getDataTypeAvg(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date, filterOver?: number): number; static round(value: number, decimals?: number): number; private static addLeftRightBalanceStatsFromStreams; static getAverage(data: number[]): number; static getSum(data: number[]): number; static getDataTypeMax(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date): number; static getDataTypeMin(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date, filterOver?: number): number; static getDataTypeMinToMaxDifference(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date): number; static getDataTypeFirst(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date): number; static getDataTypeLast(activity: ActivityInterface, streamType: string, startDate?: Date, endDate?: Date): number; static cropDistance(startDistance: number, endDistance: number, activity: ActivityInterface): ActivityInterface; /** * Crops left,right on time. * Start and end date need to be relative to the activity start / end time * @param activity * @param startDate * @param endDate */ static cropTime(activity: ActivityInterface, startDate?: Date, endDate?: Date): ActivityInterface; static getStreamDataTypesBasedOnDataType(streamToBaseOn: StreamInterface, streams: StreamInterface[]): { [type: string]: number | null; }[]; static getStreamDataTypesBasedOnTime(startDate: Date, endDate: Date, streams: StreamInterface[]): { [type: number]: { [type: string]: number | null; }; }; static getDataLength(startDate: Date, endDate: Date): number; private static createJumpAggregate; private static getJumpEvents; private static getFiniteStatValue; private static getJumpAggregatesFromEvents; private static addMissingJumpStatsFromEvents; private static getSummaryJumpStatsForActivities; static generateMissingStreamsAndStatsForActivity(activity: ActivityInterface): void; static fixAbnormalStreamData(activity: ActivityInterface): void; static generateMissingStreams(activity: ActivityInterface): void; static getSummaryStatsForActivities(activities: ActivityInterface[]): DataInterface[]; /** * Calculate Mean Max Power for specified durations * @param activity The activity to analyze * @param durations Array of durations in seconds. If not provided, a "Best-in-Class" high-granularity set is used. */ static calculateMeanMaxPower(activity: ActivityInterface, durations?: number[]): DataPowerCurve; private static calculateFTP; private static calculatePowerIntensityFactor; private static toPositiveFiniteNumber; private static resolvePowerWattsPerKg; private static getDurationSecondsWithoutPauses; private static getTssOverrideValue; private static getZoneFiveLowerLimit; private static getStreamSamplesByDuration; private static resolveNormalizedPower; private static resolveFunctionalThresholdPower; private static persistFunctionalThresholdPowerOverride; private static resolveLactateThresholdHr; private static resolveMaxHeartRate; private static resolveRestingHeartRate; private static resolveGender; private static resolveFunctionalThresholdPace; private static resolveSwimSpeed; private static resolveThresholdSwimSpeed; private static resolveMetScore; private static resolveMetThreshold; private static calculatePowerTss; private static calculateHrTss; private static calculatePaceTss; private static calculateSwimPaceTss; private static calculateMetTss; private static supportsPaceTss; private static calculateTrainingStressScoreByPriority; private static updatePowerOutputsFromPowerTss; private static setTrainingStressScoreMethod; private static generateTrainingStressScore; /** * Calculate Critical Power (CP) and W' (Anaerobic Work Capacity) * using the Monod & Scherrer 2-parameter model (Power vs 1/Time). * @param activity */ static calculateCriticalPowerAndWPrime(activity: StatsClassInterface): { cp: DataCriticalPower; wPrime: DataWPrime; } | null; static getIntensityZonesStatsAggregated(statClassInstances: StatsClassInterface[]): DataInterface[]; static getActivityDataTypeGain(activity: ActivityInterface, streamType: string, starDate?: Date, endDate?: Date, minDiff?: number): number | null; static getActivityDataTypeLoss(activity: ActivityInterface, streamType: string, starDate?: Date, endDate?: Date, minDiff?: number): number | null; static getGainOrLoss(data: number[], gain: boolean, minDiff?: number): number | null; static getMax(data: number[]): number; static getMin(data: number[]): number; static calculateTotalDistanceForActivity(activity: ActivityInterface, startDate?: Date, endDate?: Date): number; /** * Returns streams that derive from speed based on the activity type * @param speedStream * @param activityType */ private static createByActivityTypeSpeedBasedStreams; /** * Returns streams that derive from grade adjusted speed based on the activity type * @param gradeAdjustedSpeedStream * @param activityType */ private static createByActivityTypeAltiDistanceSpeedBasedStreams; /** * @todo unit test (get the pun?) * This creates streams that are deriving as unit based streams * For example it will create pace from speed, swim pace from speed but also speed in km/h as a unitstream * @param streams * @param activityType * @param unitStreamTypes DynamicDataLoader.allUnitDerivedDataTypes this acts like a whitelist for the unit derived units ONLY! * @param options */ static createUnitStreamsFromStreams(streams: StreamInterface[], activityType: ActivityTypes, unitStreamTypes?: string[], options?: { includeDerivedTypes?: boolean; includeUnitVariants?: boolean; }): StreamInterface[]; /** * Generates missing streams for an activity such as distance etc if they are missing * This will always create a steam even if the distance is 0 * @param activity */ static generateMissingStreamsForActivity(activity: ActivityInterface): ActivityInterface; /** * Provides squashed stream data through callback for data manipulation. * Then rebuild the stream based on duration including the missing values (null, Infinity, ...) like the source stream * @param streamType * @param activity * @param shapeStreamData */ static shapeStream(streamType: string, activity: ActivityInterface, shapeStreamData: (squashedStreamData: number[]) => number[]): void; static cloneStream(activity: ActivityInterface, sourceStreamType: string, targetStreamType: string): void; /** * Create derived primitive streams which will be needed for others streams & stats computations * @param activity */ static createDerivedStreams(activity: ActivityInterface): ActivityInterface; private static canGenerateDerivedStream; /** * Back and forth fills an activity's stream data so they can be more "tree" like * It does this for: * * [DataAltitude.type, * DataHeartRate.type, * DataCadence.type, * DataDistance.type] * * Example * * Distance[0, 10, 30, 40, 50,null,60] #null here is legit eg missing record * Altitude[100, 101, null, 103, null, null, 106] * Should be * Altitude[100,101,101,103,103,103,106] * * @param activity */ static addMissingDataToStreams(activity: ActivityInterface): void; /** * * @param secondsPer100m * @param avgStrokesPerMin * @param poolLength */ static computeSwimSwolf(secondsPer100m: number, avgStrokesPerMin: number, poolLength: number): number; /** * Andrew Coggan weighted power compute method * 1) starting at the 30s mark, calculate a rolling 30 s average (of the preceding time points, obviously). * 2) raise all the values obtained in step #1 to the 4th power. * 3) take the average of all of the values obtained in step #2. * 4) take the 4th root of the value obtained in step #3. * (And when you get tired of exporting every file to, e.g., Excel to perform such calculations, help develop a program * like WKO+ to do the work for you <g>.) */ private static computeNormalizedPower; private static getActivityDataTypeGainOrLoss; private static getActivityDataTypeMinOrMax; /** * Generates the stats for an activity * @todo move to factory with next version * @param activity */ private static generateMissingStatsForActivity; private static generateMissingSpeedDerivedStatsForActivity; private static generateMissingUnitStatsForActivity; }