Skip to content

Commit

Permalink
Some improvements to js code
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Feb 10, 2020
1 parent 6c7a74b commit 08a0507
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 12 deletions.
96 changes: 84 additions & 12 deletions assets/js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ module.exports = {
},{}],3:[function(require,module,exports){
let motionsplan = {};

motionsplan.Estimate1RM = function(weight, repetitions) {
motionsplan.Estimate1RM = function(weight, repetitions = 5) {
weight = weight;
repetitions = repetitions;

Expand All @@ -204,6 +204,30 @@ motionsplan.Estimate1RM = function(weight, repetitions) {
return repmax / (36 / (37 - rm));
}

function getReynolds(body_part = "lower", rm = 1) {
if (repetitions != 5) {
throw Error('Reynolds only works with 5RM');
}
var repmax;
if (body_part == "lower") {
repmax = (1.09703 * weight) + 14.2546;
} else {
repmax = (1.1307 * weight) + 0.6998;
}
if (rm == 1) {
return repmax;
}
return getReynoldsPercent(body_part, rm) * repmax / 100;
}

function getReynoldsPercent(body_part = "lower", rm = 1) {
if (body_part == "lower") {
return 78.17 * Math.exp(-0.0569 * rm) + 26.41;
} else {
return 55.51 * Math.exp(-0.0723 * rm) + 48.47;
}
}

function getEpley(rm = 1) {
var repmax = (1 + (0.0333 * repetitions)) * weight;
if (rm == 1) {
Expand All @@ -212,24 +236,68 @@ motionsplan.Estimate1RM = function(weight, repetitions) {
return repmax / (1 + (0.0333 * rm));
}

function getLander() {
return (100 * weight) / (101.3 - 2.67123 * repetitions);
/**
* Women College Aged
*/
/*
function getAbadie(rm = 1) {
var repmax = 7.24 + (1.05 * weight * repetitions);
if (rm == 1) {
return repmax;
}
return repmax / (1 + (0.0333 * rm));
}
*/

function getLombardi() {
return weight * (Math.pow(repetitions, 0.1));
/**
* McGlothin on Wikipedia
*/
function getLander(rm = 1) {
var repmax = (100 * weight) / (101.3 - 2.67123 * repetitions);
if (rm == 1) {
return repmax;
}
return (repmax * (101.3 - 2.67123 * rm)) / 100;
}

function getMayhew() {
return (100 * weight) / (52.2 + (41.9 * Math.exp(-0.055 * repetitions)));
function getLombardi(rm = 1) {
var repmax = weight * (Math.pow(repetitions, 0.1));
if (rm == 1) {
return repmax;
}
return repmax / ((Math.pow(repetitions, 0.1)));
}

function getOconnor() {
return weight * (1 + 0.025 * repetitions);
function getMayhew(rm = 1) {
var repmax = (100 * weight) / (52.2 + (41.9 * Math.exp(-0.055 * repetitions)));
if (rm == 1) {
return repmax;
}
return repmax * (52.2 + (41.9 * Math.exp(-0.055 * rm))) / 100;
}

function getWathan() {
return (100 * weight) / (48.8 + (53.8 * Math.exp(-0.075 * repetitions)));
function getOconnor(rm = 1) {
var repmax = weight * (1 + 0.025 * repetitions);
if (rm == 1) {
return repmax;
}
return repmax / (1 + 0.025 * rm);
}

function getWathan(rm = 1) {
var repmax = (100 * weight) / (48.8 + (53.8 * Math.exp(-0.075 * repetitions)));
if (rm == 1) {
return repmax;
}
return repmax * (48.8 + (53.8 * Math.exp(-0.075 * rm))) / 100;
}

function getWendler(rm = 1) {
var repmax = weight * repetitions * 0.0333 + weight;
if (rm == 1) {
return repmax;
}
return 1 / (((rm * .0333) / repmax) + (1 / repmax));
}

/**
Expand Down Expand Up @@ -298,6 +366,9 @@ motionsplan.Estimate1RM = function(weight, repetitions) {

var publicAPI = {
getBrzycki: getBrzycki,
// getAbadie: getAbadie,
getReynolds: getReynolds,
getReynoldsPercent: getReynoldsPercent,
getEpley: getEpley,
getLander: getLander,
getLombardi: getLombardi,
Expand All @@ -306,7 +377,8 @@ motionsplan.Estimate1RM = function(weight, repetitions) {
getWathan: getWathan,
getMOL: getMOL,
getMOLBrzycki : getMOLBrzycki,
getPercentOfRm : getPercentOfRm
getPercentOfRm : getPercentOfRm,
getWendler : getWendler
};

return publicAPI;
Expand Down
115 changes: 115 additions & 0 deletions src/js/plate-calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
let motionsplan = {}

motionsplan.PlateRackCalc = function(weight, bar_weight = 20, collar_weight = 0, percentage = 1) {
weight = weight;
bar_weight = bar_weight;
collar_weight = collar_weight;
percentage = percentage;

var Final, Target, Diff;

var A25 = 2;
var A20 = 2;
var A15 = 2;
var A10 = 2;
var A5 = 2;
var A2 = 2;
var A2dot5 = 2;
var A1dot5 = 2;
var A1 = 2;
var A0dot5 = 2;

var Avail = [A25, A20, A15, A10, A5, A2dot5, A2, A1dot5, A1, A0dot5];
var plateWeight = [25, 20, 15, 10, 5, 2.5, 2, 1.5, 1, 0.5];
var NoPlateReq = [];

function setAvailablePlates() {

}

function startcalc() {

var diff;
var noplate, pairVal;

// Get basic weight to count plates needed
var rw = getPlatesWeight();

// loop to count number of plates
for (var i = 0; i < Avail.length; i++) {
pairVal = plateWeight[i] * 2;
if (rw >= pairVal) {
noplate = rw / pairVal;
if (noplate > Avail[i]) {
noplate = parseInt(Avail[i]);
NoPlateReq.push(parseInt(noplate));
if (NoPlateReq[i] > 0) {
rw = rw - parseFloat((NoPlateReq[i] * 2 * plateWeight[i]));
}
}
else {
NoPlateReq.push(parseInt(noplate));
if (NoPlateReq[i] > 0) {
rw = rw - parseFloat((NoPlateReq[i] * 2 * plateWeight[i]));
}
}
}
else {
NoPlateReq.push(0);
}
}

var finalval = 0;
for (var i = 0; i < NoPlateReq.length; i++) {
finalval = finalval + parseInt(NoPlateReq[i] * plateWeight[i] * 2);
}

var bs = parseFloat(collar_weight) + parseFloat(bar_weight);
diff = parseFloat(weight * percentage);

Final = parseFloat(finalval + bs);
Target = parseFloat(weight * percentage);
Diff = parseFloat(diff - (finalval + bs));

return true;
}

function getTarget() {
return Target;
}

function getDiff() {
return Diff;
}

function getFinal() {
return Final;
}

function getHowManyPlatesNeededOf(key) {
if (parseInt(NoPlateReq[key]) != 0) {
return parseInt(NoPlateReq[key]);
}
return 0;
}

function getPlatesWeight() {
var warmupWeight = weight * percentage;
var bs = parseFloat(collar_weight) + parseFloat(bar_weight);
var retWeight = parseFloat(warmupWeight) - parseFloat(bs);
return retWeight;
}

var publicAPI = {
getPlatesWeight: getPlatesWeight,
getTarget: getTarget,
getFinal: getFinal,
getDiff: getDiff,
getHowManyPlatesNeededOf: getHowManyPlatesNeededOf,
startcalc: startcalc
};

return publicAPI;
}

module.exports = motionsplan;
25 changes: 25 additions & 0 deletions src/test/plate-calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const motionsplan = require('../js/plate-calc.js');
var assert = require('assert');

describe('PlateCalc', function() {
describe('PlateCalc', function() {
it('should return the correct number', function() {

var hr = motionsplan.PlateRackCalc(100);
assert.equal(hr.getPlatesWeight(), 80);
hr.startcalc();
assert.equal(hr.getTarget(), 100);
assert.equal(hr.getFinal(), 100);
assert.equal(hr.getDiff(), 0);
assert.equal(hr.getHowManyPlatesNeededOf(0), 1);
assert.equal(hr.getHowManyPlatesNeededOf(1), 0);
assert.equal(hr.getHowManyPlatesNeededOf(2), 1);
assert.equal(hr.getHowManyPlatesNeededOf(3), 0);
assert.equal(hr.getHowManyPlatesNeededOf(4), 0);
assert.equal(hr.getHowManyPlatesNeededOf(5), 0);
assert.equal(hr.getHowManyPlatesNeededOf(6), 0);
assert.equal(hr.getHowManyPlatesNeededOf(7), 0);
assert.equal(hr.getHowManyPlatesNeededOf(8), 0);
});
});
});

0 comments on commit 08a0507

Please sign in to comment.