@sports-alliance/sports-lib 6.1.5 → 6.1.7

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/jest.config.js CHANGED
@@ -8,7 +8,7 @@ module.exports = {
8
8
  moduleNameMapper: {
9
9
  '^node:buffer$': '<rootDir>/node_modules/buffer/index.js'
10
10
  },
11
- testTimeout: 480000, // Allow 240s for integrations tests
11
+ testTimeout: 960000, // Allow 480s for integrations tests
12
12
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
13
13
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
14
14
  // Since Jest 27 'node' env is the default and recommended one.
@@ -39,4 +39,40 @@ describe('DataStore', () => {
39
39
  // @todo here we should think
40
40
  expect(data_store_1.DynamicDataLoader.allUnitDerivedDataTypes.sort()).toEqual(unitDerivedDataTypes.sort());
41
41
  });
42
+ describe('getUnitBasedDataTypesFromDataTypes', () => {
43
+ it('should include derived types by default', () => {
44
+ const types = [data_speed_1.DataSpeedKilometersPerHour.type, data_pace_1.DataPace.type];
45
+ const settings = {
46
+ speedUnits: [data_speed_1.DataSpeedKilometersPerHour.type],
47
+ swimPaceUnits: [],
48
+ paceUnits: [data_pace_1.DataPaceMinutesPerMile.type],
49
+ gradeAdjustedSpeedUnits: [],
50
+ gradeAdjustedPaceUnits: [],
51
+ verticalSpeedUnits: [],
52
+ distanceUnits: [],
53
+ elevationUnits: [],
54
+ temperatureUnits: [],
55
+ weightUnits: []
56
+ };
57
+ const result = data_store_1.DynamicDataLoader.getUnitBasedDataTypesFromDataTypes([data_speed_1.DataSpeed.type], settings);
58
+ expect(result).toContain(data_pace_1.DataPaceMinutesPerMile.type);
59
+ });
60
+ it('should exclude derived types when includeDerivedTypes is false', () => {
61
+ const settings = {
62
+ speedUnits: [data_speed_1.DataSpeedKilometersPerHour.type],
63
+ swimPaceUnits: [],
64
+ paceUnits: [data_pace_1.DataPaceMinutesPerMile.type],
65
+ gradeAdjustedSpeedUnits: [],
66
+ gradeAdjustedPaceUnits: [],
67
+ verticalSpeedUnits: [],
68
+ distanceUnits: [],
69
+ elevationUnits: [],
70
+ temperatureUnits: [],
71
+ weightUnits: []
72
+ };
73
+ const result = data_store_1.DynamicDataLoader.getUnitBasedDataTypesFromDataTypes([data_speed_1.DataSpeed.type], settings, { includeDerivedTypes: false });
74
+ expect(result).toContain(data_speed_1.DataSpeedKilometersPerHour.type);
75
+ expect(result).not.toContain(data_pace_1.DataPaceMinutesPerMile.type);
76
+ });
77
+ });
42
78
  });
@@ -45,7 +45,9 @@ export declare class DynamicDataLoader {
45
45
  * @param dataTypes
46
46
  * @param userUnitSettings
47
47
  */
48
- static getUnitBasedDataTypesFromDataTypes(dataTypes: string[], userUnitSettings?: UserUnitSettingsInterface): string[];
48
+ static getUnitBasedDataTypesFromDataTypes(dataTypes: string[], userUnitSettings?: UserUnitSettingsInterface, options?: {
49
+ includeDerivedTypes?: boolean;
50
+ }): string[];
49
51
  /**
50
52
  * Gets the unitbased types
51
53
  * @param dataType
@@ -498,19 +498,23 @@ class DynamicDataLoader {
498
498
  * @param dataTypes
499
499
  * @param userUnitSettings
500
500
  */
501
- static getUnitBasedDataTypesFromDataTypes(dataTypes, userUnitSettings) {
501
+ static getUnitBasedDataTypesFromDataTypes(dataTypes, userUnitSettings, options = { includeDerivedTypes: true }) {
502
502
  let unitBasedDataTypes = [];
503
503
  if (!userUnitSettings) {
504
504
  return unitBasedDataTypes;
505
505
  }
506
506
  if (dataTypes.indexOf(data_speed_1.DataSpeed.type) !== -1) {
507
507
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.speedUnits);
508
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.swimPaceUnits);
509
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.paceUnits);
508
+ if (options.includeDerivedTypes) {
509
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.swimPaceUnits);
510
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.paceUnits);
511
+ }
510
512
  }
511
513
  if (dataTypes.indexOf(data_grade_adjusted_speed_1.DataGradeAdjustedSpeed.type) !== -1) {
512
514
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedSpeedUnits);
513
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedPaceUnits);
515
+ if (options.includeDerivedTypes) {
516
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedPaceUnits);
517
+ }
514
518
  }
515
519
  if (dataTypes.indexOf(data_vertical_speed_1.DataVerticalSpeed.type) !== -1) {
516
520
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.verticalSpeedUnits);
@@ -63,14 +63,19 @@ export declare class ActivityUtilities {
63
63
  */
64
64
  private static createByActivityTypeAltiDistanceSpeedBasedStreams;
65
65
  /**
66
+
66
67
  * @todo unit test (get the pun?)
67
68
  * This creates streams that are deriving as unit based streams
68
69
  * For example it will create pace from speed, swim pace from speed but also speed in km/h as a unitstream
69
70
  * @param streams
70
71
  * @param activityType
71
72
  * @param unitStreamTypes DynamicDataLoader.allUnitDerivedDataTypes this acts like a whitelist for the unit derived units ONLY!
73
+ * @param options
72
74
  */
73
- static createUnitStreamsFromStreams(streams: StreamInterface[], activityType: ActivityTypes, unitStreamTypes?: string[]): StreamInterface[];
75
+ static createUnitStreamsFromStreams(streams: StreamInterface[], activityType: ActivityTypes, unitStreamTypes?: string[], options?: {
76
+ includeDerivedTypes?: boolean;
77
+ includeUnitVariants?: boolean;
78
+ }): StreamInterface[];
74
79
  /**
75
80
  * Generates missing streams for an activity such as distance etc if they are missing
76
81
  * This will always create a steam even if the distance is 0
@@ -664,24 +664,39 @@ class ActivityUtilities {
664
664
  }, []);
665
665
  }
666
666
  /**
667
+
667
668
  * @todo unit test (get the pun?)
668
669
  * This creates streams that are deriving as unit based streams
669
670
  * For example it will create pace from speed, swim pace from speed but also speed in km/h as a unitstream
670
671
  * @param streams
671
672
  * @param activityType
672
673
  * @param unitStreamTypes DynamicDataLoader.allUnitDerivedDataTypes this acts like a whitelist for the unit derived units ONLY!
674
+ * @param options
673
675
  */
674
- static createUnitStreamsFromStreams(streams, activityType, unitStreamTypes) {
676
+ static createUnitStreamsFromStreams(streams, activityType, unitStreamTypes, options = {
677
+ includeDerivedTypes: true,
678
+ includeUnitVariants: true
679
+ }) {
675
680
  // @todo perhaps check input to be unitStreamTypesStrictly
676
681
  const unitStreamTypesToCreate = unitStreamTypes || data_store_1.DynamicDataLoader.allUnitDerivedDataTypes;
677
682
  let baseUnitStreams = [];
678
683
  const speedStream = streams.find(stream => stream.type === data_speed_1.DataSpeed.type);
679
684
  if (speedStream) {
680
- baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeSpeedBasedStreams(speedStream, activityType));
685
+ if (options.includeDerivedTypes) {
686
+ baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeSpeedBasedStreams(speedStream, activityType));
687
+ }
688
+ else {
689
+ baseUnitStreams.push(speedStream);
690
+ }
681
691
  }
682
692
  const gradeAdjustedSpeedStream = streams.find(stream => stream.type === data_grade_adjusted_speed_1.DataGradeAdjustedSpeed.type);
683
693
  if (gradeAdjustedSpeedStream) {
684
- baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeAltiDistanceSpeedBasedStreams(gradeAdjustedSpeedStream, activityType));
694
+ if (options.includeDerivedTypes) {
695
+ baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeAltiDistanceSpeedBasedStreams(gradeAdjustedSpeedStream, activityType));
696
+ }
697
+ else {
698
+ baseUnitStreams.push(gradeAdjustedSpeedStream);
699
+ }
685
700
  }
686
701
  const verticalSpeedStream = streams.find(stream => stream.type === data_vertical_speed_1.DataVerticalSpeed.type);
687
702
  if (verticalSpeedStream) {
@@ -692,6 +707,9 @@ class ActivityUtilities {
692
707
  }
693
708
  // @todo add distance ?
694
709
  const startWith = baseUnitStreams.filter(baseUnitStream => unitStreamTypesToCreate.indexOf(baseUnitStream.type) !== -1 && streams.indexOf(baseUnitStream) === -1);
710
+ if (options.includeUnitVariants === false) {
711
+ return startWith;
712
+ }
695
713
  return Object.keys(data_store_1.DynamicDataLoader.dataTypeUnitGroups).reduce((array, baseDataType) => {
696
714
  const baseStream = baseUnitStreams.find(stream => stream.type === baseDataType);
697
715
  if (!baseStream) {
@@ -847,7 +865,7 @@ class ActivityUtilities {
847
865
  activity.addStream(leftPowerStream);
848
866
  }
849
867
  // If left stance time stream available, then add the right balance stream too
850
- if (activity.hasStreamData(data_stance_time_balance_left_1.DataStanceTimeBalanceLeft.type)) {
868
+ if (activity.hasStreamData(data_stance_time_balance_left_1.DataStanceTimeBalanceLeft.type) && !activity.hasStreamData(data_stance_time_balance_right_1.DataStanceTimeBalanceRight.type)) {
851
869
  const rightStanceBalanceTimeStream = activity.createStream(data_stance_time_balance_right_1.DataStanceTimeBalanceRight.type);
852
870
  const leftStanceBalanceTimeStream = activity.getStreamData(data_stance_time_balance_left_1.DataStanceTimeBalanceLeft.type);
853
871
  const rightStanceBalanceTimeData = leftStanceBalanceTimeStream.map(leftBalance => {
@@ -17,6 +17,8 @@ const lap_types_1 = require("../../laps/lap.types");
17
17
  const data_time_1 = require("../../data/data.time");
18
18
  const file_type_enum_1 = require("../adapters/file-type.enum");
19
19
  const importer_json_1 = require("../adapters/importers/json/importer.json");
20
+ const data_pace_1 = require("../../data/data.pace");
21
+ const data_speed_2 = require("../../data/data.speed");
20
22
  describe('Activity Utilities', () => {
21
23
  let event;
22
24
  beforeEach(() => {
@@ -224,4 +226,39 @@ describe('Activity Utilities', () => {
224
226
  done();
225
227
  });
226
228
  });
229
+ describe('createUnitStreamsFromStreams', () => {
230
+ it('should include derived types and unit variants by default', () => {
231
+ const streams = [new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20])];
232
+ const result = activity_utilities_1.ActivityUtilities.createUnitStreamsFromStreams(streams, activity_types_1.ActivityTypes.Running);
233
+ const paceStream = result.find(s => s.type === data_pace_1.DataPaceMinutesPerMile.type);
234
+ const kmhStream = result.find(s => s.type === data_speed_2.DataSpeedKilometersPerHour.type);
235
+ expect(paceStream).toBeDefined();
236
+ expect(kmhStream).toBeDefined();
237
+ });
238
+ it('should exclude derived types when includeDerivedTypes is false', () => {
239
+ const streams = [new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20])];
240
+ const result = activity_utilities_1.ActivityUtilities.createUnitStreamsFromStreams(streams, activity_types_1.ActivityTypes.Running, undefined, { includeDerivedTypes: false, includeUnitVariants: true });
241
+ const paceStream = result.find(s => s.type === data_pace_1.DataPaceMinutesPerMile.type);
242
+ const kmhStream = result.find(s => s.type === data_speed_2.DataSpeedKilometersPerHour.type);
243
+ expect(paceStream).toBeUndefined();
244
+ expect(kmhStream).toBeDefined();
245
+ });
246
+ it('should exclude unit variants when includeUnitVariants is false', () => {
247
+ const streams = [new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20])];
248
+ // We pass DataPace.type in unitStreamTypes so we can check if the derived base stream is present
249
+ const result = activity_utilities_1.ActivityUtilities.createUnitStreamsFromStreams(streams, activity_types_1.ActivityTypes.Running, [data_pace_1.DataPace.type], { includeDerivedTypes: true, includeUnitVariants: false });
250
+ const paceStream = result.find(s => s.type === data_pace_1.DataPace.type);
251
+ const paceUnitStream = result.find(s => s.type === data_pace_1.DataPaceMinutesPerMile.type);
252
+ expect(paceStream).toBeDefined(); // Derived type should be there
253
+ expect(paceUnitStream).toBeUndefined(); // Unit variant should be gone
254
+ });
255
+ it('should exclude both derived types and unit variants', () => {
256
+ const streams = [new stream_1.Stream(data_speed_1.DataSpeed.type, [10, 20])];
257
+ const result = activity_utilities_1.ActivityUtilities.createUnitStreamsFromStreams(streams, activity_types_1.ActivityTypes.Running, [data_pace_1.DataPace.type], { includeDerivedTypes: false, includeUnitVariants: false });
258
+ const paceStream = result.find(s => s.type === data_pace_1.DataPace.type);
259
+ const paceUnitStream = result.find(s => s.type === data_pace_1.DataPaceMinutesPerMile.type);
260
+ expect(paceStream).toBeUndefined();
261
+ expect(paceUnitStream).toBeUndefined();
262
+ });
263
+ });
227
264
  });
@@ -16,7 +16,6 @@ export declare class User implements UserInterface {
16
16
  displayName?: string;
17
17
  description?: string;
18
18
  settings?: UserSettingsInterface;
19
- lastSeenPromo?: number;
20
19
  constructor(userID: string, displayName?: string, photoURL?: string, privacy?: Privacy, description?: string);
21
20
  toJSON(): {
22
21
  uid: string;
@@ -1,4 +1,4 @@
1
- import { DataSpeedFeetPerMinute, DataSpeedFeetPerSecond, DataSpeedKilometersPerHour, DataSpeedKnots, DataSpeedMetersPerMinute, DataSpeedMilesPerHour } from './data.speed';
1
+ import { DataSpeedFeetPerMinute, DataSpeedFeetPerSecond, DataSpeedKilometersPerHour, DataSpeedKnots, DataSpeedMetersPerMinute, DataSpeedMilesPerHour, DataSpeed } from './data.speed';
2
2
  import { DataPace, DataPaceMinutesPerMile } from './data.pace';
3
3
  import { DataSwimPace, DataSwimPaceMinutesPer100Yard } from './data.swim-pace';
4
4
  import { DataGradeAdjustedSpeedFeetPerMinute, DataGradeAdjustedSpeedFeetPerSecond, DataGradeAdjustedSpeedKilometersPerHour, DataGradeAdjustedSpeedKnots, DataGradeAdjustedSpeedMetersPerMinute, DataGradeAdjustedSpeedMilesPerHour } from './data.grade-adjusted-speed';
@@ -37,4 +37,40 @@ describe('DataStore', () => {
37
37
  // @todo here we should think
38
38
  expect(DynamicDataLoader.allUnitDerivedDataTypes.sort()).toEqual(unitDerivedDataTypes.sort());
39
39
  });
40
+ describe('getUnitBasedDataTypesFromDataTypes', () => {
41
+ it('should include derived types by default', () => {
42
+ const types = [DataSpeedKilometersPerHour.type, DataPace.type];
43
+ const settings = {
44
+ speedUnits: [DataSpeedKilometersPerHour.type],
45
+ swimPaceUnits: [],
46
+ paceUnits: [DataPaceMinutesPerMile.type],
47
+ gradeAdjustedSpeedUnits: [],
48
+ gradeAdjustedPaceUnits: [],
49
+ verticalSpeedUnits: [],
50
+ distanceUnits: [],
51
+ elevationUnits: [],
52
+ temperatureUnits: [],
53
+ weightUnits: []
54
+ };
55
+ const result = DynamicDataLoader.getUnitBasedDataTypesFromDataTypes([DataSpeed.type], settings);
56
+ expect(result).toContain(DataPaceMinutesPerMile.type);
57
+ });
58
+ it('should exclude derived types when includeDerivedTypes is false', () => {
59
+ const settings = {
60
+ speedUnits: [DataSpeedKilometersPerHour.type],
61
+ swimPaceUnits: [],
62
+ paceUnits: [DataPaceMinutesPerMile.type],
63
+ gradeAdjustedSpeedUnits: [],
64
+ gradeAdjustedPaceUnits: [],
65
+ verticalSpeedUnits: [],
66
+ distanceUnits: [],
67
+ elevationUnits: [],
68
+ temperatureUnits: [],
69
+ weightUnits: []
70
+ };
71
+ const result = DynamicDataLoader.getUnitBasedDataTypesFromDataTypes([DataSpeed.type], settings, { includeDerivedTypes: false });
72
+ expect(result).toContain(DataSpeedKilometersPerHour.type);
73
+ expect(result).not.toContain(DataPaceMinutesPerMile.type);
74
+ });
75
+ });
40
76
  });
@@ -45,7 +45,9 @@ export declare class DynamicDataLoader {
45
45
  * @param dataTypes
46
46
  * @param userUnitSettings
47
47
  */
48
- static getUnitBasedDataTypesFromDataTypes(dataTypes: string[], userUnitSettings?: UserUnitSettingsInterface): string[];
48
+ static getUnitBasedDataTypesFromDataTypes(dataTypes: string[], userUnitSettings?: UserUnitSettingsInterface, options?: {
49
+ includeDerivedTypes?: boolean;
50
+ }): string[];
49
51
  /**
50
52
  * Gets the unitbased types
51
53
  * @param dataType
@@ -493,19 +493,23 @@ export class DynamicDataLoader {
493
493
  * @param dataTypes
494
494
  * @param userUnitSettings
495
495
  */
496
- static getUnitBasedDataTypesFromDataTypes(dataTypes, userUnitSettings) {
496
+ static getUnitBasedDataTypesFromDataTypes(dataTypes, userUnitSettings, options = { includeDerivedTypes: true }) {
497
497
  let unitBasedDataTypes = [];
498
498
  if (!userUnitSettings) {
499
499
  return unitBasedDataTypes;
500
500
  }
501
501
  if (dataTypes.indexOf(DataSpeed.type) !== -1) {
502
502
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.speedUnits);
503
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.swimPaceUnits);
504
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.paceUnits);
503
+ if (options.includeDerivedTypes) {
504
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.swimPaceUnits);
505
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.paceUnits);
506
+ }
505
507
  }
506
508
  if (dataTypes.indexOf(DataGradeAdjustedSpeed.type) !== -1) {
507
509
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedSpeedUnits);
508
- unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedPaceUnits);
510
+ if (options.includeDerivedTypes) {
511
+ unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.gradeAdjustedPaceUnits);
512
+ }
509
513
  }
510
514
  if (dataTypes.indexOf(DataVerticalSpeed.type) !== -1) {
511
515
  unitBasedDataTypes = unitBasedDataTypes.concat(userUnitSettings.verticalSpeedUnits);
@@ -63,14 +63,19 @@ export declare class ActivityUtilities {
63
63
  */
64
64
  private static createByActivityTypeAltiDistanceSpeedBasedStreams;
65
65
  /**
66
+
66
67
  * @todo unit test (get the pun?)
67
68
  * This creates streams that are deriving as unit based streams
68
69
  * For example it will create pace from speed, swim pace from speed but also speed in km/h as a unitstream
69
70
  * @param streams
70
71
  * @param activityType
71
72
  * @param unitStreamTypes DynamicDataLoader.allUnitDerivedDataTypes this acts like a whitelist for the unit derived units ONLY!
73
+ * @param options
72
74
  */
73
- static createUnitStreamsFromStreams(streams: StreamInterface[], activityType: ActivityTypes, unitStreamTypes?: string[]): StreamInterface[];
75
+ static createUnitStreamsFromStreams(streams: StreamInterface[], activityType: ActivityTypes, unitStreamTypes?: string[], options?: {
76
+ includeDerivedTypes?: boolean;
77
+ includeUnitVariants?: boolean;
78
+ }): StreamInterface[];
74
79
  /**
75
80
  * Generates missing streams for an activity such as distance etc if they are missing
76
81
  * This will always create a steam even if the distance is 0
@@ -661,24 +661,39 @@ export class ActivityUtilities {
661
661
  }, []);
662
662
  }
663
663
  /**
664
+
664
665
  * @todo unit test (get the pun?)
665
666
  * This creates streams that are deriving as unit based streams
666
667
  * For example it will create pace from speed, swim pace from speed but also speed in km/h as a unitstream
667
668
  * @param streams
668
669
  * @param activityType
669
670
  * @param unitStreamTypes DynamicDataLoader.allUnitDerivedDataTypes this acts like a whitelist for the unit derived units ONLY!
671
+ * @param options
670
672
  */
671
- static createUnitStreamsFromStreams(streams, activityType, unitStreamTypes) {
673
+ static createUnitStreamsFromStreams(streams, activityType, unitStreamTypes, options = {
674
+ includeDerivedTypes: true,
675
+ includeUnitVariants: true
676
+ }) {
672
677
  // @todo perhaps check input to be unitStreamTypesStrictly
673
678
  const unitStreamTypesToCreate = unitStreamTypes || DynamicDataLoader.allUnitDerivedDataTypes;
674
679
  let baseUnitStreams = [];
675
680
  const speedStream = streams.find(stream => stream.type === DataSpeed.type);
676
681
  if (speedStream) {
677
- baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeSpeedBasedStreams(speedStream, activityType));
682
+ if (options.includeDerivedTypes) {
683
+ baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeSpeedBasedStreams(speedStream, activityType));
684
+ }
685
+ else {
686
+ baseUnitStreams.push(speedStream);
687
+ }
678
688
  }
679
689
  const gradeAdjustedSpeedStream = streams.find(stream => stream.type === DataGradeAdjustedSpeed.type);
680
690
  if (gradeAdjustedSpeedStream) {
681
- baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeAltiDistanceSpeedBasedStreams(gradeAdjustedSpeedStream, activityType));
691
+ if (options.includeDerivedTypes) {
692
+ baseUnitStreams = baseUnitStreams.concat(this.createByActivityTypeAltiDistanceSpeedBasedStreams(gradeAdjustedSpeedStream, activityType));
693
+ }
694
+ else {
695
+ baseUnitStreams.push(gradeAdjustedSpeedStream);
696
+ }
682
697
  }
683
698
  const verticalSpeedStream = streams.find(stream => stream.type === DataVerticalSpeed.type);
684
699
  if (verticalSpeedStream) {
@@ -689,6 +704,9 @@ export class ActivityUtilities {
689
704
  }
690
705
  // @todo add distance ?
691
706
  const startWith = baseUnitStreams.filter(baseUnitStream => unitStreamTypesToCreate.indexOf(baseUnitStream.type) !== -1 && streams.indexOf(baseUnitStream) === -1);
707
+ if (options.includeUnitVariants === false) {
708
+ return startWith;
709
+ }
692
710
  return Object.keys(DynamicDataLoader.dataTypeUnitGroups).reduce((array, baseDataType) => {
693
711
  const baseStream = baseUnitStreams.find(stream => stream.type === baseDataType);
694
712
  if (!baseStream) {
@@ -844,7 +862,7 @@ export class ActivityUtilities {
844
862
  activity.addStream(leftPowerStream);
845
863
  }
846
864
  // If left stance time stream available, then add the right balance stream too
847
- if (activity.hasStreamData(DataStanceTimeBalanceLeft.type)) {
865
+ if (activity.hasStreamData(DataStanceTimeBalanceLeft.type) && !activity.hasStreamData(DataStanceTimeBalanceRight.type)) {
848
866
  const rightStanceBalanceTimeStream = activity.createStream(DataStanceTimeBalanceRight.type);
849
867
  const leftStanceBalanceTimeStream = activity.getStreamData(DataStanceTimeBalanceLeft.type);
850
868
  const rightStanceBalanceTimeData = leftStanceBalanceTimeStream.map(leftBalance => {
@@ -15,6 +15,8 @@ import { LapTypes } from '../../laps/lap.types';
15
15
  import { DataTime } from '../../data/data.time';
16
16
  import { FileType } from '../adapters/file-type.enum';
17
17
  import { EventImporterJSON } from '../adapters/importers/json/importer.json';
18
+ import { DataPace, DataPaceMinutesPerMile } from '../../data/data.pace';
19
+ import { DataSpeedKilometersPerHour } from '../../data/data.speed';
18
20
  describe('Activity Utilities', () => {
19
21
  let event;
20
22
  beforeEach(() => {
@@ -222,4 +224,39 @@ describe('Activity Utilities', () => {
222
224
  done();
223
225
  });
224
226
  });
227
+ describe('createUnitStreamsFromStreams', () => {
228
+ it('should include derived types and unit variants by default', () => {
229
+ const streams = [new Stream(DataSpeed.type, [10, 20])];
230
+ const result = ActivityUtilities.createUnitStreamsFromStreams(streams, ActivityTypes.Running);
231
+ const paceStream = result.find(s => s.type === DataPaceMinutesPerMile.type);
232
+ const kmhStream = result.find(s => s.type === DataSpeedKilometersPerHour.type);
233
+ expect(paceStream).toBeDefined();
234
+ expect(kmhStream).toBeDefined();
235
+ });
236
+ it('should exclude derived types when includeDerivedTypes is false', () => {
237
+ const streams = [new Stream(DataSpeed.type, [10, 20])];
238
+ const result = ActivityUtilities.createUnitStreamsFromStreams(streams, ActivityTypes.Running, undefined, { includeDerivedTypes: false, includeUnitVariants: true });
239
+ const paceStream = result.find(s => s.type === DataPaceMinutesPerMile.type);
240
+ const kmhStream = result.find(s => s.type === DataSpeedKilometersPerHour.type);
241
+ expect(paceStream).toBeUndefined();
242
+ expect(kmhStream).toBeDefined();
243
+ });
244
+ it('should exclude unit variants when includeUnitVariants is false', () => {
245
+ const streams = [new Stream(DataSpeed.type, [10, 20])];
246
+ // We pass DataPace.type in unitStreamTypes so we can check if the derived base stream is present
247
+ const result = ActivityUtilities.createUnitStreamsFromStreams(streams, ActivityTypes.Running, [DataPace.type], { includeDerivedTypes: true, includeUnitVariants: false });
248
+ const paceStream = result.find(s => s.type === DataPace.type);
249
+ const paceUnitStream = result.find(s => s.type === DataPaceMinutesPerMile.type);
250
+ expect(paceStream).toBeDefined(); // Derived type should be there
251
+ expect(paceUnitStream).toBeUndefined(); // Unit variant should be gone
252
+ });
253
+ it('should exclude both derived types and unit variants', () => {
254
+ const streams = [new Stream(DataSpeed.type, [10, 20])];
255
+ const result = ActivityUtilities.createUnitStreamsFromStreams(streams, ActivityTypes.Running, [DataPace.type], { includeDerivedTypes: false, includeUnitVariants: false });
256
+ const paceStream = result.find(s => s.type === DataPace.type);
257
+ const paceUnitStream = result.find(s => s.type === DataPaceMinutesPerMile.type);
258
+ expect(paceStream).toBeUndefined();
259
+ expect(paceUnitStream).toBeUndefined();
260
+ });
261
+ });
225
262
  });
@@ -16,7 +16,6 @@ export declare class User implements UserInterface {
16
16
  displayName?: string;
17
17
  description?: string;
18
18
  settings?: UserSettingsInterface;
19
- lastSeenPromo?: number;
20
19
  constructor(userID: string, displayName?: string, photoURL?: string, privacy?: Privacy, description?: string);
21
20
  toJSON(): {
22
21
  uid: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sports-alliance/sports-lib",
3
- "version": "6.1.5",
3
+ "version": "6.1.7",
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",