fitness-progression-calculator 1.2.0 → 1.3.0

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.
Files changed (2) hide show
  1. package/dist/calculator.js +31 -12
  2. package/package.json +1 -1
@@ -20,6 +20,8 @@ const DEFAULT_EQUIPMENT_SETTINGS = {
20
20
  };
21
21
  // Constants
22
22
  const STARTING_HYPERTROPHY_REPS = 10; // Rep count to cycle back to after reaching MAX_REPS
23
+ const LIGHT_DUMBBELL_MAX = 10; // Maximum weight for light dumbbells
24
+ const LIGHT_DUMBBELL_INCREMENT = 1.0; // Increment for light dumbbells
23
25
  // Helper functions
24
26
  function isSpecialBodyweightExercise(exerciseName) {
25
27
  return SPECIAL_BODYWEIGHT_EXERCISES.includes(exerciseName.toUpperCase());
@@ -27,7 +29,11 @@ function isSpecialBodyweightExercise(exerciseName) {
27
29
  /**
28
30
  * Gets base increment for the given equipment type from user settings
29
31
  */
30
- function getBaseIncrement(equipmentType, userSettings = DEFAULT_EQUIPMENT_SETTINGS) {
32
+ function getBaseIncrement(equipmentType, currentWeight, userSettings = DEFAULT_EQUIPMENT_SETTINGS) {
33
+ // Special case for light dumbbells
34
+ if (equipmentType === "DUMBBELL" && currentWeight < LIGHT_DUMBBELL_MAX) {
35
+ return LIGHT_DUMBBELL_INCREMENT;
36
+ }
31
37
  switch (equipmentType) {
32
38
  case "BARBELL":
33
39
  return (userSettings.barbellIncrement ||
@@ -47,6 +53,13 @@ function getBaseIncrement(equipmentType, userSettings = DEFAULT_EQUIPMENT_SETTIN
47
53
  return 2.5; // Default fallback
48
54
  }
49
55
  }
56
+ /**
57
+ * Rounds a weight to the nearest multiple of the increment
58
+ */
59
+ function roundToIncrementMultiple(weight, equipmentType, userSettings = DEFAULT_EQUIPMENT_SETTINGS) {
60
+ const increment = getBaseIncrement(equipmentType, weight, userSettings);
61
+ return Math.round(weight / increment) * increment;
62
+ }
50
63
  /**
51
64
  * Calculate the total volume for a given exercise configuration
52
65
  */
@@ -122,22 +135,27 @@ function calculateProgression(data, programType, userSettings = DEFAULT_EQUIPMEN
122
135
  return handleBodyweightExercise(data);
123
136
  }
124
137
  // Get the base increment for this equipment type
125
- const baseIncrement = getBaseIncrement(data.equipment_type, userSettings);
138
+ const baseIncrement = getBaseIncrement(data.equipment_type, data.weight, userSettings);
126
139
  console.log(`Using ${data.equipment_type} increment: ${baseIncrement}kg`);
127
140
  // Calculate weight change based on rating
128
141
  const weightChange = getWeightChangeForRating(data.rating, baseIncrement);
129
142
  // For strength programs, focus on weight increases
130
143
  if (programType === "STRENGTH") {
144
+ const rawNewWeight = Math.max(0, data.weight + weightChange);
145
+ // Round the weight to the nearest multiple of the increment
146
+ const roundedWeight = roundToIncrementMultiple(rawNewWeight, data.equipment_type, userSettings);
131
147
  return {
132
- newWeight: Math.max(0, data.weight + weightChange),
148
+ newWeight: roundedWeight,
133
149
  newReps: data.reps,
134
150
  };
135
151
  }
136
152
  // HYPERTROPHY program logic
137
153
  // For ratings 4 (Hard) and 5 (Too Hard), no rep increase, only potential weight decrease
138
154
  if (data.rating >= 4) {
155
+ const rawNewWeight = Math.max(0, data.weight + weightChange);
156
+ const roundedWeight = roundToIncrementMultiple(rawNewWeight, data.equipment_type, userSettings);
139
157
  return {
140
- newWeight: Math.max(0, data.weight + weightChange),
158
+ newWeight: roundedWeight,
141
159
  newReps: data.reps,
142
160
  };
143
161
  }
@@ -150,15 +168,18 @@ function calculateProgression(data, programType, userSettings = DEFAULT_EQUIPMEN
150
168
  // Ensure the weight increases by at least the rating-based increment
151
169
  const volumeBasedIncrement = data.weight * (MAX_REPS / STARTING_HYPERTROPHY_REPS) - data.weight;
152
170
  const actualIncrement = Math.max(weightChange, volumeBasedIncrement);
171
+ const rawNewWeight = Math.max(0, data.weight + actualIncrement);
172
+ const roundedWeight = roundToIncrementMultiple(rawNewWeight, data.equipment_type, userSettings);
153
173
  return {
154
- newWeight: Math.max(0, data.weight + actualIncrement),
174
+ newWeight: roundedWeight,
155
175
  newReps: STARTING_HYPERTROPHY_REPS,
156
176
  };
157
177
  }
158
178
  // For ratings 1-3 with non-maxed reps, compare volume increases
159
179
  // Option 1: Increase weight
160
- const newWeight = Math.max(0, data.weight + weightChange);
161
- const volumeWithWeightIncrease = calculateVolume(data.sets, data.reps, newWeight);
180
+ const rawNewWeight = Math.max(0, data.weight + weightChange);
181
+ const roundedNewWeight = roundToIncrementMultiple(rawNewWeight, data.equipment_type, userSettings);
182
+ const volumeWithWeightIncrease = calculateVolume(data.sets, data.reps, roundedNewWeight);
162
183
  // Option 2: Increase reps
163
184
  const newReps = data.reps + 1;
164
185
  const volumeWithRepIncrease = calculateVolume(data.sets, newReps, data.weight);
@@ -176,7 +197,7 @@ function calculateProgression(data, programType, userSettings = DEFAULT_EQUIPMEN
176
197
  // For very easy (rating 1), always increase both weight and reps if compound
177
198
  if (data.rating === 1 && data.is_compound) {
178
199
  return {
179
- newWeight: newWeight,
200
+ newWeight: roundedNewWeight,
180
201
  newReps: Math.min(newReps, MAX_REPS),
181
202
  };
182
203
  }
@@ -184,7 +205,7 @@ function calculateProgression(data, programType, userSettings = DEFAULT_EQUIPMEN
184
205
  // This helps make sure progression is steady and not too aggressive
185
206
  if (volumeChangeWithWeight <= volumeChangeWithReps) {
186
207
  return {
187
- newWeight: newWeight,
208
+ newWeight: roundedNewWeight,
188
209
  newReps: data.reps,
189
210
  };
190
211
  }
@@ -198,7 +219,5 @@ function calculateProgression(data, programType, userSettings = DEFAULT_EQUIPMEN
198
219
  * Useful for client-side adjustments
199
220
  */
200
221
  function roundToClosestIncrement(weight, equipmentType, userSettings = DEFAULT_EQUIPMENT_SETTINGS) {
201
- const baseIncrement = getBaseIncrement(equipmentType, userSettings);
202
- // Round to nearest multiple of baseIncrement
203
- return Math.round(weight / baseIncrement) * baseIncrement;
222
+ return roundToIncrementMultiple(weight, equipmentType, userSettings);
204
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fitness-progression-calculator",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Workout progression calculator for fitness applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",