@sports-alliance/sports-lib 6.1.7 → 6.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/activities/activity-parsing-options.d.ts +1 -0
- package/lib/cjs/activities/activity-parsing-options.js +4 -1
- package/lib/cjs/events/utilities/activity.utilities.js +3 -1
- package/lib/cjs/events/utilities/activity.utilities.spec.js +55 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/esm/activities/activity-parsing-options.d.ts +1 -0
- package/lib/esm/activities/activity-parsing-options.js +4 -1
- package/lib/esm/events/utilities/activity.utilities.js +3 -1
- package/lib/esm/events/utilities/activity.utilities.spec.js +55 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/package.json +1 -1
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ActivityParsingOptions = void 0;
|
|
4
4
|
class ActivityParsingOptions {
|
|
5
5
|
constructor(options) {
|
|
6
|
+
var _a;
|
|
6
7
|
this.streams = options.streams;
|
|
7
8
|
this.maxActivityDurationDays = options.maxActivityDurationDays;
|
|
9
|
+
this.generateUnitStreams = (_a = options.generateUnitStreams) !== null && _a !== void 0 ? _a : true;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.ActivityParsingOptions = ActivityParsingOptions;
|
|
@@ -13,5 +15,6 @@ ActivityParsingOptions.DEFAULT = new ActivityParsingOptions({
|
|
|
13
15
|
smooth: { altitudeSmooth: true, grade: true, gradeSmooth: true },
|
|
14
16
|
fixAbnormal: { speed: false }
|
|
15
17
|
},
|
|
16
|
-
maxActivityDurationDays: 14
|
|
18
|
+
maxActivityDurationDays: 14,
|
|
19
|
+
generateUnitStreams: true
|
|
17
20
|
});
|
|
@@ -291,7 +291,9 @@ class ActivityUtilities {
|
|
|
291
291
|
static generateMissingStreams(activity) {
|
|
292
292
|
// Compute missing streams
|
|
293
293
|
this.generateMissingStreamsForActivity(activity);
|
|
294
|
-
|
|
294
|
+
if (!activity.parseOptions || activity.parseOptions.generateUnitStreams) {
|
|
295
|
+
activity.addStreams(this.createUnitStreamsFromStreams(activity.getAllStreams(), activity.type));
|
|
296
|
+
}
|
|
295
297
|
}
|
|
296
298
|
static getSummaryStatsForActivities(activities) {
|
|
297
299
|
const stats = [];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const event_1 = require("../event");
|
|
4
|
+
const data_speed_max_1 = require("../../data/data.speed-max");
|
|
4
5
|
const activity_1 = require("../../activities/activity");
|
|
5
6
|
const data_heart_rate_1 = require("../../data/data.heart-rate");
|
|
6
7
|
const data_altitude_1 = require("../../data/data.altitude");
|
|
@@ -261,4 +262,58 @@ describe('Activity Utilities', () => {
|
|
|
261
262
|
expect(paceUnitStream).toBeUndefined();
|
|
262
263
|
});
|
|
263
264
|
});
|
|
265
|
+
describe('generateMissingStreams', () => {
|
|
266
|
+
it('should generate unit streams by default (generateUnitStreams = true)', () => {
|
|
267
|
+
const activity = new activity_1.Activity(new Date(), new Date(), activity_types_1.ActivityTypes.Running, new creator_1.Creator('test'));
|
|
268
|
+
// Add a speed stream
|
|
269
|
+
activity.addStream(new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20]));
|
|
270
|
+
activity_utilities_1.ActivityUtilities.generateMissingStreams(activity);
|
|
271
|
+
// Should have generated "sister" types (e.g. Pace) and unit variants (e.g. Speed km/h)
|
|
272
|
+
expect(activity.hasStreamData(data_speed_2.DataSpeedKilometersPerHour.type)).toBe(true);
|
|
273
|
+
expect(activity.hasStreamData(data_pace_1.DataPaceMinutesPerMile.type)).toBe(true);
|
|
274
|
+
});
|
|
275
|
+
it('should NOT generate unit streams when generateUnitStreams = false', () => {
|
|
276
|
+
const activity = new activity_1.Activity(new Date(), new Date(), activity_types_1.ActivityTypes.Running, new creator_1.Creator('test'));
|
|
277
|
+
// Mock parsing options
|
|
278
|
+
activity.parseOptions = {
|
|
279
|
+
streams: { smooth: {}, fixAbnormal: {} },
|
|
280
|
+
maxActivityDurationDays: 14,
|
|
281
|
+
generateUnitStreams: false,
|
|
282
|
+
};
|
|
283
|
+
// Add a speed stream
|
|
284
|
+
activity.addStream(new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20]));
|
|
285
|
+
activity_utilities_1.ActivityUtilities.generateMissingStreams(activity);
|
|
286
|
+
// Should NOT have generated unit variants
|
|
287
|
+
expect(activity.hasStreamData(data_speed_2.DataSpeedKilometersPerHour.type)).toBe(false);
|
|
288
|
+
// It might still generate some "derived" streams depending on other flags, but our specific unit loop should be skipped
|
|
289
|
+
// The Pace stream comes from createUnitStreamsFromStreams too, so it should also be missing
|
|
290
|
+
expect(activity.hasStreamData(data_pace_1.DataPaceMinutesPerMile.type)).toBe(false);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
describe('generateMissingStreamsAndStatsForActivity', () => {
|
|
294
|
+
it('should generate unit STATS even if unit STREAMS are disabled', () => {
|
|
295
|
+
const activity = new activity_1.Activity(new Date(), new Date(), activity_types_1.ActivityTypes.Running, new creator_1.Creator('test'));
|
|
296
|
+
activity.parseOptions = {
|
|
297
|
+
streams: { smooth: {}, fixAbnormal: {} },
|
|
298
|
+
maxActivityDurationDays: 14,
|
|
299
|
+
generateUnitStreams: false, // DISABLE streams
|
|
300
|
+
};
|
|
301
|
+
// Add a speed stream [10 m/s, 20 m/s]
|
|
302
|
+
// Max speed = 20 m/s
|
|
303
|
+
activity.addStream(new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20]));
|
|
304
|
+
activity_utilities_1.ActivityUtilities.generateMissingStreamsAndStatsForActivity(activity);
|
|
305
|
+
// 1. Verify Streams are missing (as requested)
|
|
306
|
+
expect(activity.hasStreamData(data_speed_2.DataSpeedKilometersPerHour.type)).toBe(false);
|
|
307
|
+
// 1. Verify Streams are missing (as requested)
|
|
308
|
+
expect(activity.hasStreamData(data_speed_2.DataSpeedKilometersPerHour.type)).toBe(false);
|
|
309
|
+
// 2. Verify Stats are PRESENT (Safety Check)
|
|
310
|
+
// 20 m/s = 72 km/h
|
|
311
|
+
// We check for the stat by its string type if we can't import the constant easily, or iterate.
|
|
312
|
+
// Based on activity.utilities.ts it uses: DataSpeedMaxKilometersPerHour
|
|
313
|
+
const allStats = Array.from(activity.getStats().values());
|
|
314
|
+
const speedMaxKmh = allStats.find(s => s.getType() === data_speed_max_1.DataSpeedMaxKilometersPerHour.type);
|
|
315
|
+
expect(speedMaxKmh).toBeDefined();
|
|
316
|
+
expect(speedMaxKmh === null || speedMaxKmh === void 0 ? void 0 : speedMaxKmh.getValue()).toBe(72);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
264
319
|
});
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare class SportsLib {
|
|
|
34
34
|
static importFromJSON(json: EventJSONInterface): EventInterface;
|
|
35
35
|
}
|
|
36
36
|
export * from './activities/activity.interface';
|
|
37
|
+
export * from './activities/activity-parsing-options';
|
|
37
38
|
export * from './activities/activity.json.interface';
|
|
38
39
|
export * from './activities/activity.types';
|
|
39
40
|
export * from './constants/constants';
|
package/lib/cjs/index.js
CHANGED
|
@@ -60,6 +60,7 @@ class SportsLib {
|
|
|
60
60
|
}
|
|
61
61
|
exports.SportsLib = SportsLib;
|
|
62
62
|
__exportStar(require("./activities/activity.interface"), exports);
|
|
63
|
+
__exportStar(require("./activities/activity-parsing-options"), exports);
|
|
63
64
|
__exportStar(require("./activities/activity.json.interface"), exports);
|
|
64
65
|
__exportStar(require("./activities/activity.types"), exports);
|
|
65
66
|
__exportStar(require("./constants/constants"), exports);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export class ActivityParsingOptions {
|
|
2
2
|
constructor(options) {
|
|
3
|
+
var _a;
|
|
3
4
|
this.streams = options.streams;
|
|
4
5
|
this.maxActivityDurationDays = options.maxActivityDurationDays;
|
|
6
|
+
this.generateUnitStreams = (_a = options.generateUnitStreams) !== null && _a !== void 0 ? _a : true;
|
|
5
7
|
}
|
|
6
8
|
}
|
|
7
9
|
ActivityParsingOptions.DEFAULT = new ActivityParsingOptions({
|
|
@@ -9,5 +11,6 @@ ActivityParsingOptions.DEFAULT = new ActivityParsingOptions({
|
|
|
9
11
|
smooth: { altitudeSmooth: true, grade: true, gradeSmooth: true },
|
|
10
12
|
fixAbnormal: { speed: false }
|
|
11
13
|
},
|
|
12
|
-
maxActivityDurationDays: 14
|
|
14
|
+
maxActivityDurationDays: 14,
|
|
15
|
+
generateUnitStreams: true
|
|
13
16
|
});
|
|
@@ -288,7 +288,9 @@ export class ActivityUtilities {
|
|
|
288
288
|
static generateMissingStreams(activity) {
|
|
289
289
|
// Compute missing streams
|
|
290
290
|
this.generateMissingStreamsForActivity(activity);
|
|
291
|
-
|
|
291
|
+
if (!activity.parseOptions || activity.parseOptions.generateUnitStreams) {
|
|
292
|
+
activity.addStreams(this.createUnitStreamsFromStreams(activity.getAllStreams(), activity.type));
|
|
293
|
+
}
|
|
292
294
|
}
|
|
293
295
|
static getSummaryStatsForActivities(activities) {
|
|
294
296
|
const stats = [];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Event } from '../event';
|
|
2
|
+
import { DataSpeedMaxKilometersPerHour } from '../../data/data.speed-max';
|
|
2
3
|
import { Activity } from '../../activities/activity';
|
|
3
4
|
import { DataHeartRate } from '../../data/data.heart-rate';
|
|
4
5
|
import { DataAltitude } from '../../data/data.altitude';
|
|
@@ -259,4 +260,58 @@ describe('Activity Utilities', () => {
|
|
|
259
260
|
expect(paceUnitStream).toBeUndefined();
|
|
260
261
|
});
|
|
261
262
|
});
|
|
263
|
+
describe('generateMissingStreams', () => {
|
|
264
|
+
it('should generate unit streams by default (generateUnitStreams = true)', () => {
|
|
265
|
+
const activity = new Activity(new Date(), new Date(), ActivityTypes.Running, new Creator('test'));
|
|
266
|
+
// Add a speed stream
|
|
267
|
+
activity.addStream(new Stream(DataSpeed.type, [10, 20]));
|
|
268
|
+
ActivityUtilities.generateMissingStreams(activity);
|
|
269
|
+
// Should have generated "sister" types (e.g. Pace) and unit variants (e.g. Speed km/h)
|
|
270
|
+
expect(activity.hasStreamData(DataSpeedKilometersPerHour.type)).toBe(true);
|
|
271
|
+
expect(activity.hasStreamData(DataPaceMinutesPerMile.type)).toBe(true);
|
|
272
|
+
});
|
|
273
|
+
it('should NOT generate unit streams when generateUnitStreams = false', () => {
|
|
274
|
+
const activity = new Activity(new Date(), new Date(), ActivityTypes.Running, new Creator('test'));
|
|
275
|
+
// Mock parsing options
|
|
276
|
+
activity.parseOptions = {
|
|
277
|
+
streams: { smooth: {}, fixAbnormal: {} },
|
|
278
|
+
maxActivityDurationDays: 14,
|
|
279
|
+
generateUnitStreams: false,
|
|
280
|
+
};
|
|
281
|
+
// Add a speed stream
|
|
282
|
+
activity.addStream(new Stream(DataSpeed.type, [10, 20]));
|
|
283
|
+
ActivityUtilities.generateMissingStreams(activity);
|
|
284
|
+
// Should NOT have generated unit variants
|
|
285
|
+
expect(activity.hasStreamData(DataSpeedKilometersPerHour.type)).toBe(false);
|
|
286
|
+
// It might still generate some "derived" streams depending on other flags, but our specific unit loop should be skipped
|
|
287
|
+
// The Pace stream comes from createUnitStreamsFromStreams too, so it should also be missing
|
|
288
|
+
expect(activity.hasStreamData(DataPaceMinutesPerMile.type)).toBe(false);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
describe('generateMissingStreamsAndStatsForActivity', () => {
|
|
292
|
+
it('should generate unit STATS even if unit STREAMS are disabled', () => {
|
|
293
|
+
const activity = new Activity(new Date(), new Date(), ActivityTypes.Running, new Creator('test'));
|
|
294
|
+
activity.parseOptions = {
|
|
295
|
+
streams: { smooth: {}, fixAbnormal: {} },
|
|
296
|
+
maxActivityDurationDays: 14,
|
|
297
|
+
generateUnitStreams: false, // DISABLE streams
|
|
298
|
+
};
|
|
299
|
+
// Add a speed stream [10 m/s, 20 m/s]
|
|
300
|
+
// Max speed = 20 m/s
|
|
301
|
+
activity.addStream(new Stream(DataSpeed.type, [10, 20]));
|
|
302
|
+
ActivityUtilities.generateMissingStreamsAndStatsForActivity(activity);
|
|
303
|
+
// 1. Verify Streams are missing (as requested)
|
|
304
|
+
expect(activity.hasStreamData(DataSpeedKilometersPerHour.type)).toBe(false);
|
|
305
|
+
// 1. Verify Streams are missing (as requested)
|
|
306
|
+
expect(activity.hasStreamData(DataSpeedKilometersPerHour.type)).toBe(false);
|
|
307
|
+
// 2. Verify Stats are PRESENT (Safety Check)
|
|
308
|
+
// 20 m/s = 72 km/h
|
|
309
|
+
// We check for the stat by its string type if we can't import the constant easily, or iterate.
|
|
310
|
+
// Based on activity.utilities.ts it uses: DataSpeedMaxKilometersPerHour
|
|
311
|
+
const allStats = Array.from(activity.getStats().values());
|
|
312
|
+
const speedMaxKmh = allStats.find(s => s.getType() === DataSpeedMaxKilometersPerHour.type);
|
|
313
|
+
expect(speedMaxKmh).toBeDefined();
|
|
314
|
+
expect(speedMaxKmh === null || speedMaxKmh === void 0 ? void 0 : speedMaxKmh.getValue()).toBe(72);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
262
317
|
});
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare class SportsLib {
|
|
|
34
34
|
static importFromJSON(json: EventJSONInterface): EventInterface;
|
|
35
35
|
}
|
|
36
36
|
export * from './activities/activity.interface';
|
|
37
|
+
export * from './activities/activity-parsing-options';
|
|
37
38
|
export * from './activities/activity.json.interface';
|
|
38
39
|
export * from './activities/activity.types';
|
|
39
40
|
export * from './constants/constants';
|
package/lib/esm/index.js
CHANGED
|
@@ -46,6 +46,7 @@ export class SportsLib {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export * from './activities/activity.interface';
|
|
49
|
+
export * from './activities/activity-parsing-options';
|
|
49
50
|
export * from './activities/activity.json.interface';
|
|
50
51
|
export * from './activities/activity.types';
|
|
51
52
|
export * from './constants/constants';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sports-alliance/sports-lib",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.9",
|
|
4
4
|
"description": "A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gpx",
|