Last active
February 17, 2020 05:36
-
-
Save Pamblam/b0c86db2fb9c8f4ff8b1c240cbd18b07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BodyMetrics { | |
| constructor(params) { | |
| Object.keys(params).forEach(key => { | |
| this[key] = params[key]; | |
| }); | |
| this.results = {}; | |
| this.bodyFatPercentage(); | |
| this.bodyFatWeight(); | |
| this.bodyFatDensity(); | |
| } | |
| bodyFatDensity() { | |
| var age = +this.age; | |
| var gender = this.gender; | |
| var chest = +this.measurements.calipers.chest; | |
| var abdomen = +this.measurements.calipers.abdomen; | |
| var thigh = +this.measurements.calipers.thigh; | |
| var waist = +this.measurements.girth.waist; | |
| var forearm = +this.measurements.girth.forearm; | |
| var triceps = +this.measurements.calipers.triceps; | |
| var suprailiac = +this.measurements.calipers.suprailiac; | |
| var glute = +this.measurements.girth.glute; | |
| var canCalcBFD = (gender === 'M' && (age && thigh && chest && abdomen && waist && forearm)) || (triceps && thigh && suprailiac && age && glute); | |
| if (!canCalcBFD) { | |
| this.results.bodyFatDensity = null; | |
| return; | |
| } | |
| if (gender === 'M') { | |
| var sum = chest + abdomen + thigh; | |
| var sum_sq = sum * sum; | |
| this.results.bodyFatDensity = 1.0990750 - (0.0008209 * sum) + (0.0000026 * sum_sq) - (0.0002017 * age) - (0.005675 * (waist / 100)) + (0.018586 * (forearm / 100)); | |
| } else { | |
| var sum = triceps + thigh + suprailiac; | |
| var sum_sq = sum * sum; | |
| this.results.bodyFatDensity = 1.1470292 - (0.0009376 * sum) + (0.0000030 * sum_sq) - (0.0001156 * age) - (0.0005839 * glute); | |
| } | |
| } | |
| bodyFatWeight() { | |
| if (!this.results.BodyFatPercentage || !this.weight) { | |
| this.results.BodyFatWeight = null; | |
| this.results.LeanBodyWeight = null; | |
| return; | |
| } | |
| this.results.BodyFatWeight = (this.weight * this.results.BodyFatPercentage) / 100; | |
| this.results.LeanBodyWeight = this.weight - this.results.BodyFatWeight; | |
| } | |
| bodyFatPercentage() { | |
| var gender = this.gender; | |
| var age = +this.age; | |
| var triceps = +this.measurements.calipers.triceps; | |
| var abdomen = +this.measurements.calipers.abdomen; | |
| var thigh = +this.measurements.calipers.thigh; | |
| var suprailiac = +this.measurements.calipers.suprailiac; | |
| var canCalcBFP = gender && age && triceps && abdomen && thigh && suprailiac; | |
| if (!canCalcBFP) { | |
| this.results.BodyFatPercentage = null; | |
| this.results.BodyFatWeight = null; | |
| this.results.LeanBodyWeight = null; | |
| this.results.BodyFatDensity = null; | |
| return; | |
| } | |
| var sum = triceps + suprailiac + abdomen + thigh; | |
| var sum_sq = sum * sum; | |
| var bfp = gender === 'M' ? | |
| (0.29288 * sum) - (0.0005 * sum_sq) + (0.15845 * age) - 5.76377 : | |
| (0.29669 * sum) - (0.00043 * sum_sq) + (0.02963 * age) + 1.4072; | |
| this.results.BodyFatPercentage = bfp; | |
| } | |
| } | |
| // formulas from: https://www.topendsports.com/testing/density-jackson-pollock.htm | |
| var bm = new BodyMetrics({ | |
| age: 31, // years | |
| gender: 'M', | |
| weight: 240, // lbs | |
| measurements: { | |
| calipers: { // millimeters | |
| chest: 30, | |
| triceps: 20, | |
| abdomen: 45, | |
| thigh: 30, | |
| suprailiac: 5 | |
| }, | |
| girth: { // centimeters | |
| waist: 100, | |
| forearm: 25 | |
| } | |
| } | |
| }); | |
| console.log(bm.results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment