hevy-shared 1.0.648 → 1.0.649

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/index.d.ts CHANGED
@@ -772,10 +772,6 @@ export interface WorkoutVideo {
772
772
  thumbnail_url: string;
773
773
  }
774
774
  export type WorkoutMedia = WorkoutImage | WorkoutVideo;
775
- export type PreviewWorkoutLike = {
776
- username: string;
777
- profile_pic: string;
778
- };
779
775
  export interface Workout {
780
776
  id: string;
781
777
  short_id: string | null;
@@ -783,9 +779,7 @@ export interface Workout {
783
779
  name: string;
784
780
  description?: string;
785
781
  like_count: number;
786
- /** @deprecated 2.3.4 */
787
782
  like_images: string[];
788
- preview_workout_likes: PreviewWorkoutLike[];
789
783
  comment_count: number;
790
784
  comments: WorkoutComment[];
791
785
  /** @deprecated 1.28.13 */
@@ -1,4 +1,4 @@
1
- import { MuscleGroup, SetType } from '.';
1
+ import { MuscleGroup, SetType, SimplifiedMuscleGroup } from '.';
2
2
  interface SetCountableSet {
3
3
  indicator: SetType;
4
4
  }
@@ -7,18 +7,13 @@ interface SetCountableExercise {
7
7
  other_muscles: MuscleGroup[];
8
8
  sets: SetCountableSet[];
9
9
  }
10
- interface SetCountableWorkoutOrRoutine {
10
+ export interface SetCountableWorkoutOrRoutine {
11
11
  exercises: SetCountableExercise[];
12
12
  }
13
- export declare const getSetContributionsForMuscleGroups: (muscle_group: MuscleGroup, other_muscles: MuscleGroup[]) => {
14
- core: number;
15
- shoulders: number;
16
- arms: number;
17
- legs: number;
18
- back: number;
19
- chest: number;
20
- };
21
- export declare const calculateSimplifiedMuscleSplit: (workoutsOrRoutines: SetCountableWorkoutOrRoutine[], shouldIncludeWarmupSets: boolean) => {
13
+ export declare const calculateSetContributionsForSimplifiedMuscleGroups: ({ muscle_group, other_muscles, }: {
14
+ muscle_group: MuscleGroup;
15
+ other_muscles: MuscleGroup[];
16
+ }) => {
22
17
  core: number;
23
18
  shoulders: number;
24
19
  arms: number;
@@ -26,5 +21,16 @@ export declare const calculateSimplifiedMuscleSplit: (workoutsOrRoutines: SetCou
26
21
  back: number;
27
22
  chest: number;
28
23
  };
29
- export declare const getSetCountPerMuscleGroups: (workout: SetCountableWorkoutOrRoutine, shouldIncludeWarmupSets: boolean) => Partial<{ [key in MuscleGroup]: number; }>;
24
+ export declare const calculateSimplifiedMuscleSplit: ({ workoutsOrRoutines, includeWarmupSets, }: {
25
+ workoutsOrRoutines: SetCountableWorkoutOrRoutine[];
26
+ includeWarmupSets: boolean;
27
+ }) => Record<SimplifiedMuscleGroup, number>;
28
+ export declare const calculateSetContributionsForMuscleGroups: ({ muscleGroup, otherMuscles, }: {
29
+ muscleGroup: MuscleGroup;
30
+ otherMuscles: MuscleGroup[];
31
+ }) => Record<MuscleGroup, number>;
32
+ export declare const calculateSetCountPerMuscleGroups: ({ workoutsOrRoutines, includeWarmupSets, }: {
33
+ workoutsOrRoutines: SetCountableWorkoutOrRoutine[];
34
+ includeWarmupSets: boolean;
35
+ }) => Record<MuscleGroup, number>;
30
36
  export {};
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSetCountPerMuscleGroups = exports.calculateSimplifiedMuscleSplit = exports.getSetContributionsForMuscleGroups = void 0;
6
+ exports.calculateSetCountPerMuscleGroups = exports.calculateSetContributionsForMuscleGroups = exports.calculateSimplifiedMuscleSplit = exports.calculateSetContributionsForSimplifiedMuscleGroups = void 0;
7
7
  const intersection_1 = __importDefault(require("lodash/intersection"));
8
8
  const _1 = require(".");
9
- const getSetContributionsForMuscleGroups = (muscle_group, other_muscles) => {
9
+ const calculateSetContributionsForSimplifiedMuscleGroups = ({ muscle_group, other_muscles, }) => {
10
10
  const getContribution = (mg) => {
11
11
  if (mg.includes(muscle_group)) {
12
12
  return 1;
@@ -28,8 +28,8 @@ const getSetContributionsForMuscleGroups = (muscle_group, other_muscles) => {
28
28
  chest: getContribution(_1.chestMuscles),
29
29
  };
30
30
  };
31
- exports.getSetContributionsForMuscleGroups = getSetContributionsForMuscleGroups;
32
- const calculateSimplifiedMuscleSplit = (workoutsOrRoutines, shouldIncludeWarmupSets) => {
31
+ exports.calculateSetContributionsForSimplifiedMuscleGroups = calculateSetContributionsForSimplifiedMuscleGroups;
32
+ const calculateSimplifiedMuscleSplit = ({ workoutsOrRoutines, includeWarmupSets, }) => {
33
33
  const totals = {
34
34
  core: 0,
35
35
  shoulders: 0,
@@ -40,11 +40,14 @@ const calculateSimplifiedMuscleSplit = (workoutsOrRoutines, shouldIncludeWarmupS
40
40
  };
41
41
  for (const workoutOrRoutine of workoutsOrRoutines) {
42
42
  for (const exercise of workoutOrRoutine.exercises) {
43
- const trimmedSets = shouldIncludeWarmupSets
43
+ const trimmedSets = includeWarmupSets
44
44
  ? exercise.sets
45
45
  : exercise.sets.filter((s) => s.indicator !== 'warmup');
46
46
  const setCount = trimmedSets.length;
47
- const contributions = (0, exports.getSetContributionsForMuscleGroups)(exercise.muscle_group, exercise.other_muscles);
47
+ const contributions = (0, exports.calculateSetContributionsForSimplifiedMuscleGroups)({
48
+ muscle_group: exercise.muscle_group,
49
+ other_muscles: exercise.other_muscles,
50
+ });
48
51
  totals.core += contributions.core * setCount;
49
52
  totals.shoulders += contributions.shoulders * setCount;
50
53
  totals.arms += contributions.arms * setCount;
@@ -56,16 +59,42 @@ const calculateSimplifiedMuscleSplit = (workoutsOrRoutines, shouldIncludeWarmupS
56
59
  return totals;
57
60
  };
58
61
  exports.calculateSimplifiedMuscleSplit = calculateSimplifiedMuscleSplit;
59
- const getSetCountPerMuscleGroups = (workout, shouldIncludeWarmupSets) => {
60
- return workout.exercises.reduce((acc, e) => {
61
- const trimmedSets = shouldIncludeWarmupSets
62
- ? e.sets
63
- : e.sets.filter((s) => s.indicator !== 'warmup');
64
- acc[e.muscle_group] = (acc[e.muscle_group] || 0) + trimmedSets.length;
65
- e.other_muscles.forEach((muscle) => {
66
- acc[muscle] = (acc[muscle] || 0) + trimmedSets.length / 2;
67
- });
62
+ const calculateSetContributionsForMuscleGroups = ({ muscleGroup, otherMuscles, }) => {
63
+ const getContribution = (mg) => {
64
+ if (mg === muscleGroup) {
65
+ return 1;
66
+ }
67
+ else if (otherMuscles.includes(mg)) {
68
+ return 0.5;
69
+ }
70
+ return 0;
71
+ };
72
+ return _1.muscleGroups.reduce((acc, mg) => {
73
+ acc[mg] = getContribution(mg);
74
+ return acc;
75
+ }, {});
76
+ };
77
+ exports.calculateSetContributionsForMuscleGroups = calculateSetContributionsForMuscleGroups;
78
+ const calculateSetCountPerMuscleGroups = ({ workoutsOrRoutines, includeWarmupSets, }) => {
79
+ const totals = _1.muscleGroups.reduce((acc, muscleGroup) => {
80
+ acc[muscleGroup] = 0;
68
81
  return acc;
69
82
  }, {});
83
+ for (const workoutOrRoutine of workoutsOrRoutines) {
84
+ for (const exercise of workoutOrRoutine.exercises) {
85
+ const trimmedSets = includeWarmupSets
86
+ ? exercise.sets
87
+ : exercise.sets.filter((s) => s.indicator !== 'warmup');
88
+ const setCount = trimmedSets.length;
89
+ const contributions = (0, exports.calculateSetContributionsForMuscleGroups)({
90
+ muscleGroup: exercise.muscle_group,
91
+ otherMuscles: exercise.other_muscles,
92
+ });
93
+ for (const muscleGroup of _1.muscleGroups) {
94
+ totals[muscleGroup] += contributions[muscleGroup] * setCount;
95
+ }
96
+ }
97
+ }
98
+ return totals;
70
99
  };
71
- exports.getSetCountPerMuscleGroups = getSetCountPerMuscleGroups;
100
+ exports.calculateSetCountPerMuscleGroups = calculateSetCountPerMuscleGroups;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const muscleSplits_1 = require("../muscleSplits");
4
+ class SetCountableWorkoutOrRoutineBuilder {
5
+ constructor() {
6
+ this.exercises = [];
7
+ }
8
+ addExercise(muscle_group, other_muscles, sets) {
9
+ this.exercises.push({
10
+ muscle_group,
11
+ other_muscles,
12
+ sets: sets.map((indicator) => ({ indicator })),
13
+ });
14
+ return this;
15
+ }
16
+ build() {
17
+ return {
18
+ exercises: this.exercises,
19
+ };
20
+ }
21
+ }
22
+ describe('muscleSplits', () => {
23
+ describe('calculateSetContributionsForSimplifiedMuscleGroups', () => {
24
+ it('should return 1 for the main muscle group', () => {
25
+ const contributions = (0, muscleSplits_1.calculateSetContributionsForSimplifiedMuscleGroups)({
26
+ muscle_group: 'chest',
27
+ other_muscles: [],
28
+ });
29
+ expect(contributions.chest).toBe(1);
30
+ expect(contributions.back).toBe(0);
31
+ expect(contributions.shoulders).toBe(0);
32
+ expect(contributions.arms).toBe(0);
33
+ expect(contributions.legs).toBe(0);
34
+ expect(contributions.core).toBe(0);
35
+ });
36
+ it('should return 0.5 for other muscle groups', () => {
37
+ const contributions = (0, muscleSplits_1.calculateSetContributionsForSimplifiedMuscleGroups)({
38
+ muscle_group: 'shoulders',
39
+ other_muscles: ['triceps'],
40
+ });
41
+ expect(contributions.shoulders).toBe(1);
42
+ expect(contributions.arms).toBe(0.5);
43
+ });
44
+ it('should return 1/6 for full body exercises', () => {
45
+ const contributions = (0, muscleSplits_1.calculateSetContributionsForSimplifiedMuscleGroups)({
46
+ muscle_group: 'full_body',
47
+ other_muscles: [],
48
+ });
49
+ const expected = 1 / 6;
50
+ expect(contributions.chest).toBe(expected);
51
+ expect(contributions.back).toBe(expected);
52
+ expect(contributions.shoulders).toBe(expected);
53
+ expect(contributions.arms).toBe(expected);
54
+ expect(contributions.legs).toBe(expected);
55
+ expect(contributions.core).toBe(expected);
56
+ });
57
+ });
58
+ describe('calculateSimplifiedMuscleSplit', () => {
59
+ it('should calculate the split correctly', () => {
60
+ const workout = new SetCountableWorkoutOrRoutineBuilder()
61
+ .addExercise('chest', ['triceps'], ['normal', 'normal', 'normal'])
62
+ .addExercise('lats', ['biceps'], ['normal', 'normal'])
63
+ .build();
64
+ const split = (0, muscleSplits_1.calculateSimplifiedMuscleSplit)({
65
+ workoutsOrRoutines: [workout],
66
+ includeWarmupSets: false,
67
+ });
68
+ expect(split.chest).toBe(3);
69
+ expect(split.arms).toBe(3 * 0.5 + 2 * 0.5); // 1.5 from chest day, 1 from back day
70
+ expect(split.back).toBe(2);
71
+ });
72
+ it('should handle warmup sets', () => {
73
+ const workout = new SetCountableWorkoutOrRoutineBuilder()
74
+ .addExercise('chest', ['triceps'], ['warmup', 'normal', 'normal', 'failure'])
75
+ .build();
76
+ const splitWithWarmup = (0, muscleSplits_1.calculateSimplifiedMuscleSplit)({
77
+ workoutsOrRoutines: [workout],
78
+ includeWarmupSets: true,
79
+ });
80
+ expect(splitWithWarmup.chest).toBe(4);
81
+ expect(splitWithWarmup.arms).toBe(4 * 0.5);
82
+ const splitWithoutWarmup = (0, muscleSplits_1.calculateSimplifiedMuscleSplit)({
83
+ workoutsOrRoutines: [workout],
84
+ includeWarmupSets: false,
85
+ });
86
+ expect(splitWithoutWarmup.chest).toBe(3);
87
+ expect(splitWithoutWarmup.arms).toBe(3 * 0.5);
88
+ });
89
+ it('should count a set as 1 for a simplified group even if primary and other muscles are in the same group', () => {
90
+ const workout = new SetCountableWorkoutOrRoutineBuilder()
91
+ .addExercise('quadriceps', ['hamstrings', 'glutes'], // also in legs
92
+ ['normal'])
93
+ .build();
94
+ const split = (0, muscleSplits_1.calculateSimplifiedMuscleSplit)({
95
+ workoutsOrRoutines: [workout],
96
+ includeWarmupSets: false,
97
+ });
98
+ expect(split.legs).toBe(1);
99
+ expect(split.chest).toBe(0);
100
+ expect(split.back).toBe(0);
101
+ expect(split.shoulders).toBe(0);
102
+ expect(split.arms).toBe(0);
103
+ expect(split.core).toBe(0);
104
+ });
105
+ });
106
+ describe('calculateSetContributionsForMuscleGroups', () => {
107
+ it('should return 1 for the main muscle group and 0.5 for others', () => {
108
+ const contributions = (0, muscleSplits_1.calculateSetContributionsForMuscleGroups)({
109
+ muscleGroup: 'chest',
110
+ otherMuscles: ['shoulders', 'triceps'],
111
+ });
112
+ expect(contributions.chest).toBe(1);
113
+ expect(contributions.shoulders).toBe(0.5);
114
+ expect(contributions.triceps).toBe(0.5);
115
+ expect(contributions.lats).toBe(0);
116
+ });
117
+ });
118
+ describe('calculateSetCountPerMuscleGroups', () => {
119
+ it('should calculate the set count per muscle group', () => {
120
+ const workout = new SetCountableWorkoutOrRoutineBuilder()
121
+ .addExercise('chest', ['shoulders', 'triceps'], ['normal', 'normal', 'normal'])
122
+ .addExercise('lats', ['biceps'], ['normal', 'normal'])
123
+ .build();
124
+ const counts = (0, muscleSplits_1.calculateSetCountPerMuscleGroups)({
125
+ workoutsOrRoutines: [workout],
126
+ includeWarmupSets: false,
127
+ });
128
+ expect(counts.chest).toBe(3);
129
+ expect(counts.shoulders).toBe(3 * 0.5);
130
+ expect(counts.triceps).toBe(3 * 0.5);
131
+ expect(counts.lats).toBe(2);
132
+ expect(counts.biceps).toBe(2 * 0.5);
133
+ expect(counts.abdominals).toBe(0);
134
+ });
135
+ it('should handle warmup sets correctly', () => {
136
+ const workout = new SetCountableWorkoutOrRoutineBuilder()
137
+ .addExercise('chest', ['shoulders', 'triceps'], ['warmup', 'normal', 'normal'])
138
+ .build();
139
+ const countsWithWarmup = (0, muscleSplits_1.calculateSetCountPerMuscleGroups)({
140
+ workoutsOrRoutines: [workout],
141
+ includeWarmupSets: true,
142
+ });
143
+ expect(countsWithWarmup.chest).toBe(3);
144
+ expect(countsWithWarmup.shoulders).toBe(3 * 0.5);
145
+ const countsWithoutWarmup = (0, muscleSplits_1.calculateSetCountPerMuscleGroups)({
146
+ workoutsOrRoutines: [workout],
147
+ includeWarmupSets: false,
148
+ });
149
+ expect(countsWithoutWarmup.chest).toBe(2);
150
+ expect(countsWithoutWarmup.shoulders).toBe(2 * 0.5);
151
+ });
152
+ });
153
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hevy-shared",
3
- "version": "1.0.648",
3
+ "version": "1.0.649",
4
4
  "description": "",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",