hevy-shared 1.0.828 → 1.0.829
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/built/tests/utils.test.js +133 -0
- package/built/utils.d.ts +6 -1
- package/built/utils.js +31 -7
- package/package.json +1 -1
|
@@ -321,6 +321,139 @@ describe('utils', () => {
|
|
|
321
321
|
expect((0, utils_1.formatDurationInput)('99:99')).toBe('99:99');
|
|
322
322
|
});
|
|
323
323
|
});
|
|
324
|
+
describe('getEstimatedExercisesDurationSeconds', () => {
|
|
325
|
+
const testCases = [
|
|
326
|
+
{
|
|
327
|
+
exercises: [
|
|
328
|
+
{
|
|
329
|
+
type: 'duration',
|
|
330
|
+
rest_seconds: 10,
|
|
331
|
+
sets: [{ duration_seconds: 50, indicator: 'normal' }],
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
expectedDuration: 50 + 10,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
exercises: [
|
|
338
|
+
{
|
|
339
|
+
type: 'floors_duration',
|
|
340
|
+
rest_seconds: 10,
|
|
341
|
+
sets: [{ duration_seconds: 0, indicator: 'normal' }],
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
expectedDuration: 10,
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
exercises: [
|
|
348
|
+
{
|
|
349
|
+
type: 'weight_duration',
|
|
350
|
+
rest_seconds: null,
|
|
351
|
+
sets: [{ duration_seconds: 30, indicator: 'normal' }],
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
expectedDuration: 30 + utils_1.ESTIMATED_REST_TIMER_DURATION,
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
exercises: [
|
|
358
|
+
{
|
|
359
|
+
type: 'distance_duration',
|
|
360
|
+
rest_seconds: 120,
|
|
361
|
+
sets: [{ duration_seconds: 40, indicator: 'normal' }],
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
expectedDuration: 40 + 120,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
exercises: [
|
|
368
|
+
{
|
|
369
|
+
type: 'weight_duration',
|
|
370
|
+
rest_seconds: 120,
|
|
371
|
+
sets: [{ duration_seconds: null, indicator: 'normal' }],
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
expectedDuration: 120 + utils_1.ESTIMATED_SET_DURATION,
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
exercises: [
|
|
378
|
+
{
|
|
379
|
+
type: 'duration',
|
|
380
|
+
rest_seconds: 0,
|
|
381
|
+
sets: [{ duration_seconds: null, indicator: 'normal' }],
|
|
382
|
+
},
|
|
383
|
+
],
|
|
384
|
+
expectedDuration: utils_1.ESTIMATED_SET_DURATION,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
exercises: [
|
|
388
|
+
{
|
|
389
|
+
type: 'reps_only',
|
|
390
|
+
rest_seconds: 180,
|
|
391
|
+
sets: [{ duration_seconds: null, indicator: 'normal' }],
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: 'reps_only',
|
|
395
|
+
rest_seconds: 180,
|
|
396
|
+
sets: [
|
|
397
|
+
{
|
|
398
|
+
duration_seconds: 0,
|
|
399
|
+
indicator: 'normal',
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
duration_seconds: 0,
|
|
403
|
+
indicator: 'normal',
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
duration_seconds: 0,
|
|
407
|
+
indicator: 'normal',
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
duration_seconds: 0,
|
|
411
|
+
indicator: 'normal',
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
expectedDuration: (180 + utils_1.ESTIMATED_SET_DURATION) * 5,
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
exercises: [
|
|
420
|
+
{
|
|
421
|
+
type: 'reps_only',
|
|
422
|
+
rest_seconds: null,
|
|
423
|
+
sets: [{ duration_seconds: null, indicator: 'normal' }],
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
type: 'reps_only',
|
|
427
|
+
rest_seconds: null,
|
|
428
|
+
sets: [
|
|
429
|
+
{
|
|
430
|
+
duration_seconds: 0,
|
|
431
|
+
indicator: 'normal',
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
duration_seconds: 0,
|
|
435
|
+
indicator: 'dropset',
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
duration_seconds: 0,
|
|
439
|
+
indicator: 'normal',
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
duration_seconds: 0,
|
|
443
|
+
indicator: 'dropset',
|
|
444
|
+
},
|
|
445
|
+
],
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
expectedDuration: utils_1.ESTIMATED_REST_TIMER_DURATION * 3 + 5 * utils_1.ESTIMATED_SET_DURATION,
|
|
449
|
+
},
|
|
450
|
+
];
|
|
451
|
+
testCases.forEach((testCase) => {
|
|
452
|
+
it(`getEstimatedExercisesDurationSeconds`, () => {
|
|
453
|
+
expect((0, utils_1.getEstimatedExercisesDurationSeconds)(testCase)).toBe(testCase.expectedDuration);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
324
457
|
describe('splitAtUsernamesAndLinks', () => {
|
|
325
458
|
it('Takes a string and returns an array of FormatAtText', () => {
|
|
326
459
|
const inputOutputs = [
|
package/built/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseExerciseTemplate, FormatAtText, Result, StrengthLevel, UserExerciseSet } from '.';
|
|
1
|
+
import { BaseExerciseTemplate, ExerciseType, FormatAtText, Result, SetType, StrengthLevel, UserExerciseSet, UserFacingSetIndicator } from '.';
|
|
2
2
|
/**
|
|
3
3
|
* Doesn't matter what you throw in the function it'll
|
|
4
4
|
* always return a number. Non number values will return
|
|
@@ -175,14 +175,19 @@ export interface TotalSetCountWorkout {
|
|
|
175
175
|
*/
|
|
176
176
|
export declare const userExerciseSetWeight: (set: UserExerciseSet, exerciseStore: BaseExerciseTemplate[], hundredPercentBodyweightExercise: boolean) => number;
|
|
177
177
|
export declare const workoutSetCount: (w: TotalSetCountWorkout) => number;
|
|
178
|
+
export declare const UserFacingIndicatorToSetIndicator: (indicator: UserFacingSetIndicator) => SetType;
|
|
178
179
|
interface GetEstimatedExercisesDuration {
|
|
179
180
|
exercises: {
|
|
180
181
|
rest_seconds: number | null;
|
|
182
|
+
type: ExerciseType;
|
|
181
183
|
sets: {
|
|
182
184
|
duration_seconds?: number | null;
|
|
185
|
+
indicator: SetType;
|
|
183
186
|
}[];
|
|
184
187
|
}[];
|
|
185
188
|
}
|
|
189
|
+
export declare const ESTIMATED_SET_DURATION = 45;
|
|
190
|
+
export declare const ESTIMATED_REST_TIMER_DURATION = 90;
|
|
186
191
|
export declare const getEstimatedExercisesDurationSeconds: ({ exercises, }: GetEstimatedExercisesDuration) => number;
|
|
187
192
|
export declare const oneRepMaxPercentageMap: {
|
|
188
193
|
[s: number]: number;
|
package/built/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getYoutubeVideoId = exports.validateYoutubeUrl = exports.splitAtUsernamesAndLinks = exports.isVersionAGreaterOrEqualToVersionB = exports.generateUserGroupValue = exports.generateUserGroup = exports.isBaseExerciseTemplate = exports.getStrengthLevelFromPercentile = exports.numberToLocaleString = exports.numberWithCommas = exports.setVolume = exports.oneRepMax = exports.oneRepMaxPercentageMap = exports.getEstimatedExercisesDurationSeconds = exports.workoutSetCount = exports.userExerciseSetWeight = exports.workoutDistanceMeters = exports.workoutReps = exports.workoutDurationSeconds = exports.removeAccents = exports.getClosestDataPointAroundTargetDate = exports.getClosestDataPointBeforeTargetDate = exports.findMapped = exports.stringToNumber = exports.forceStringToNumber = exports.formatDurationInput = exports.isValidFormattedTime = exports.isWholeNumber = exports.isNumber = exports.isValidUuid = exports.isValidPhoneNumber = exports.isValidWebUrl = exports.URL_REGEX = exports.isValidEmail = exports.secondsToWordFormatMinutes = exports.secondsToWordFormat = exports.secondsToClockFormat = exports.secondsToClockParts = exports.isValidUsername = exports.roundToWholeNumber = exports.roundToOneDecimal = exports.roundToTwoDecimal = exports.divide = exports.clampNumber = exports.num = void 0;
|
|
3
|
+
exports.getYoutubeVideoId = exports.validateYoutubeUrl = exports.splitAtUsernamesAndLinks = exports.isVersionAGreaterOrEqualToVersionB = exports.generateUserGroupValue = exports.generateUserGroup = exports.isBaseExerciseTemplate = exports.getStrengthLevelFromPercentile = exports.numberToLocaleString = exports.numberWithCommas = exports.setVolume = exports.oneRepMax = exports.oneRepMaxPercentageMap = exports.getEstimatedExercisesDurationSeconds = exports.ESTIMATED_REST_TIMER_DURATION = exports.ESTIMATED_SET_DURATION = exports.UserFacingIndicatorToSetIndicator = exports.workoutSetCount = exports.userExerciseSetWeight = exports.workoutDistanceMeters = exports.workoutReps = exports.workoutDurationSeconds = exports.removeAccents = exports.getClosestDataPointAroundTargetDate = exports.getClosestDataPointBeforeTargetDate = exports.findMapped = exports.stringToNumber = exports.forceStringToNumber = exports.formatDurationInput = exports.isValidFormattedTime = exports.isWholeNumber = exports.isNumber = exports.isValidUuid = exports.isValidPhoneNumber = exports.isValidWebUrl = exports.URL_REGEX = exports.isValidEmail = exports.secondsToWordFormatMinutes = exports.secondsToWordFormat = exports.secondsToClockFormat = exports.secondsToClockParts = exports.isValidUsername = exports.roundToWholeNumber = exports.roundToOneDecimal = exports.roundToTwoDecimal = exports.divide = exports.clampNumber = exports.num = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Doesn't matter what you throw in the function it'll
|
|
6
6
|
* always return a number. Non number values will return
|
|
@@ -444,18 +444,42 @@ const workoutSetCount = (w) => {
|
|
|
444
444
|
}, 0);
|
|
445
445
|
};
|
|
446
446
|
exports.workoutSetCount = workoutSetCount;
|
|
447
|
-
const
|
|
448
|
-
|
|
447
|
+
const UserFacingIndicatorToSetIndicator = (indicator) => {
|
|
448
|
+
if (indicator === 'dropset')
|
|
449
|
+
return 'dropset';
|
|
450
|
+
if (indicator === 'warmup')
|
|
451
|
+
return 'warmup';
|
|
452
|
+
if (indicator === 'failure')
|
|
453
|
+
return 'failure';
|
|
454
|
+
return 'normal';
|
|
455
|
+
};
|
|
456
|
+
exports.UserFacingIndicatorToSetIndicator = UserFacingIndicatorToSetIndicator;
|
|
457
|
+
exports.ESTIMATED_SET_DURATION = 45;
|
|
458
|
+
exports.ESTIMATED_REST_TIMER_DURATION = 90;
|
|
459
|
+
const isDurationExercise = (type) => {
|
|
460
|
+
return (type === 'duration' ||
|
|
461
|
+
type === 'weight_duration' ||
|
|
462
|
+
type === 'distance_duration' ||
|
|
463
|
+
type === 'floors_duration' ||
|
|
464
|
+
type === 'steps_duration');
|
|
465
|
+
};
|
|
449
466
|
const getEstimatedExercisesDurationSeconds = ({ exercises, }) => {
|
|
450
467
|
const totalSeconds = exercises.reduce((exercisesTotal, exercise) => {
|
|
451
468
|
var _a;
|
|
452
|
-
const restPerSet = (_a = exercise.rest_seconds) !== null && _a !== void 0 ? _a : ESTIMATED_REST_TIMER_DURATION;
|
|
453
|
-
const
|
|
469
|
+
const restPerSet = (_a = exercise.rest_seconds) !== null && _a !== void 0 ? _a : exports.ESTIMATED_REST_TIMER_DURATION;
|
|
470
|
+
const setsTotal = exercise.sets.reduce((setTotal, set) => {
|
|
454
471
|
var _a;
|
|
455
|
-
|
|
472
|
+
// Sometimes we get 0 values for duration on exercises that aren't duration.
|
|
473
|
+
// Added this check to prevent having a estimated duration of 0 for these.
|
|
474
|
+
const duration = isDurationExercise(exercise.type)
|
|
475
|
+
? (_a = set.duration_seconds) !== null && _a !== void 0 ? _a : exports.ESTIMATED_SET_DURATION
|
|
476
|
+
: exports.ESTIMATED_SET_DURATION;
|
|
477
|
+
// if it is a dropset, we don't add the rest time
|
|
478
|
+
if (set.indicator === 'dropset')
|
|
479
|
+
return setTotal + duration;
|
|
456
480
|
return setTotal + duration + restPerSet;
|
|
457
481
|
}, 0);
|
|
458
|
-
return exercisesTotal +
|
|
482
|
+
return exercisesTotal + setsTotal;
|
|
459
483
|
}, 0);
|
|
460
484
|
return totalSeconds;
|
|
461
485
|
};
|