-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformula.js
More file actions
70 lines (64 loc) · 2.43 KB
/
formula.js
File metadata and controls
70 lines (64 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//New dots calculation
function dots_poly(a,b,c,d,e,x) {
var x2=x*x,x3=x2*x,x4=x3*x;
return 500.0 / (a*x4+b*x3+c*x2+d*x+e);
}
function dots_men(bw) {
bw = Math.min(Math.max(bw, 40.0), 210.0);
return dots_poly(-0.0000010930,0.0007391293,-0.1918759221,24.0900756,-307.75076,bw);
}
function dots_women(bw) {
bw = Math.min(Math.max(bw, 40.0), 150.0);
return dots_poly(-0.0000010706,0.0005158568,-0.1126655495,13.6175032,-57.96288,bw);
}
//Setting up our variables which we can then use in our equation
var PARAMETERS = {
"M": {
"Raw": {
"SBD": [1199.72839, 1025.18162, 0.009210],
"B": [320.98041, 281.40258, 0.01008]
},
"Single-ply": {
"SBD": [1236.25115, 1449.21864, 0.01644],
"B": [381.22073, 733.79378, 0.02398]
}
},
"F": {
"Raw": {
"SBD": [610.32796, 1045.59282, 0.03048],
"B": [142.40398, 442.52671, 0.04724]
},
"Single-ply": {
"SBD": [758.63878, 949.31382, 0.02435],
"B": [221.82209, 357.00377, 0.02937]
}
}
};
function getRadioValue(name) {
var radios = document.getElementsByName(name);
for (var i = 0; i < radios.length; ++i) {
if (radios[i].checked) { return radios[i].value; }
}
}
function calc() {
var units = getRadioValue("units");
var sex = getRadioValue("sex");
var equipment = getRadioValue("equipment");
var event = getRadioValue("event");
var bw = Number(document.getElementById("bodyweight").value);
var total = Number(document.getElementById("total").value);
if (units === "lbs") {
bw = bw / 2.20462262;
total = total / 2.20462262;
}
var dots = total * ((sex === "M") ? dots_men(bw) : dots_women(bw));
var params = PARAMETERS[sex][equipment][event];
var denom = params[0] - (params[1] * Math.exp(-1.0 * params[2] * bw))
var glp = (denom === 0) ? 0 : Math.max(0, total * 100.0 / denom)
if (isNaN(glp) || bw < 35) {
glp = 0;
}
document.getElementById("display-glp").innerHTML = glp.toFixed(2);
document.getElementById("display-dots").innerHTML = dots.toFixed(2) + " Dots";
}
document.addEventListener("DOMContentLoaded", function(e){calc()});