From 08a0507b72fce743054d531fc815de77cca4699d Mon Sep 17 00:00:00 2001 From: Lars Olesen Date: Mon, 10 Feb 2020 19:24:53 +0000 Subject: [PATCH] Some improvements to js code --- assets/js/bundle.js | 96 +++++++++++++++++++++++++++++----- src/js/plate-calc.js | 115 +++++++++++++++++++++++++++++++++++++++++ src/test/plate-calc.js | 25 +++++++++ 3 files changed, 224 insertions(+), 12 deletions(-) create mode 100644 src/js/plate-calc.js create mode 100644 src/test/plate-calc.js diff --git a/assets/js/bundle.js b/assets/js/bundle.js index a5d1279a1761..d7d8f7f446ce 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -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; @@ -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) { @@ -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)); } /** @@ -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, @@ -306,7 +377,8 @@ motionsplan.Estimate1RM = function(weight, repetitions) { getWathan: getWathan, getMOL: getMOL, getMOLBrzycki : getMOLBrzycki, - getPercentOfRm : getPercentOfRm + getPercentOfRm : getPercentOfRm, + getWendler : getWendler }; return publicAPI; diff --git a/src/js/plate-calc.js b/src/js/plate-calc.js new file mode 100644 index 000000000000..953533864141 --- /dev/null +++ b/src/js/plate-calc.js @@ -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; diff --git a/src/test/plate-calc.js b/src/test/plate-calc.js new file mode 100644 index 000000000000..5845e9b9139e --- /dev/null +++ b/src/test/plate-calc.js @@ -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); + }); + }); +});