-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppv2.js
154 lines (127 loc) · 4.82 KB
/
ppv2.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
window.addEventListener("DOMContentLoaded", function () {
setActive("acc");
displayOD();
calcPP();
var ez = document.getElementById("EZ");
var hr = document.getElementById("HR");
var ht = document.getElementById("HT");
var dt = document.getElementById("DT");
ez.addEventListener("click", uncheck(hr));
hr.addEventListener("click", uncheck(ez));
ht.addEventListener("click", uncheck(dt));
dt.addEventListener("click", uncheck(ht));
var inputs = document.getElementsByTagName('input');
for (var i in inputs) {
switch (inputs[i].type) {
case "number":
inputs[i].addEventListener("input", calcPP);
break;
case "checkbox":
inputs[i].addEventListener("click", calcPP);
inputs[i].addEventListener("click", displayOD);
break;
}
}
});
function setActive(name) {
activeInput = name;
if (name == "acc") {
document.getElementById("acc").className = "active";
document.getElementById("100s").className = "inactive";
} else {
document.getElementById("acc").className = "inactive";
document.getElementById("100s").className = "active";
}
}
function uncheck(elem) {
return function () {
elem.checked = false;
};
}
function scaleOd(od) {
if (document.getElementById("EZ").checked) {
od /= 2;
}
if (document.getElementById("HR").checked) {
od *= 1.4;
}
od = Math.max(Math.min(od, 10), 0);
return od;
};
function hitWindow(od) {
od = scaleOd(od);
let hitWindow = 35
if (od > 5) {
hitWindow += (20 - 35) * (od - 5) / 5
} else if (od < 5) {
hitWindow -= (35 - 50) * (5 - od) / 5
}
if (document.getElementById("HT").checked) {
hitWindow /= 0.75;
}
if (document.getElementById("DT").checked) {
hitWindow /= 1.5;
}
// 2 decimals
return Math.round(hitWindow * 100) / 100;
};
function displayOD() {
var od = +document.getElementById("od-input").value;
var scaled = scaleOd(od);
scaled = Math.round(scaled * 100) / 100;
var hitWin = hitWindow(od);
document.getElementById("od-label").textContent = "300 Hit Window: " + hitWin + "ms";
document.getElementById("od-scaled").textContent = "OD w/mods: " + scaled;
};
function calcPP() {
let strain = +document.getElementById("strain").value;
let hitcount = +document.getElementById("numcircles").value;
let misses = +document.getElementById("misses").value;
let usercombo = hitcount - misses;
let OD300 = hitWindow(+document.getElementById("od-input").value);
let acc = +document.getElementById("acc").value;
const effectiveMissCount = Math.max(1.0, 1000.0 / usercombo) * misses;
let hundreds = -1;
if (activeInput == "acc") {
hundreds = Math.round((1 - misses / hitcount - acc / 100) * 2 * hitcount);
document.getElementById("100s").value = hundreds;
} else {
hundreds = +document.getElementById("100s").value;
acc = 100 * (1 - misses / hitcount - hundreds / 2 / hitcount);
// 2 decimals
document.getElementById("acc").value = Math.round(acc * 100) / 100;
}
if (strain < 0 || hitcount <= 0 || misses < 0 || usercombo < 0 || acc < 0 || acc > 100 || OD300 < 0 ||
(misses + hundreds) > hitcount || hundreds < 0) {
document.getElementById("pp").innerHTML = "Something is wrong with at least one of your inputs."
return;
}
let strainValue = Math.pow(5 * Math.max(1.0, strain / 0.115) - 4.0, 2.25) / 1150.0;
let strainLengthBonus = 1 + 0.1 * Math.min(1.0, hitcount / 1500.0);
let accLengthBonus = Math.min(1.15, Math.pow(hitcount / 1500.0, 0.3))
strainValue *= strainLengthBonus;
strainValue *= Math.pow(0.986, effectiveMissCount);
strainValue *= Math.pow(acc / 100, 2.0);
let accValue = Math.pow(60.0 / OD300, 1.1) * Math.pow(acc / 100, 8.0) * Math.pow(strain, 0.4) * 27.0;
accValue *= Math.min(Math.pow(hitcount / 1500, 0.3), 1.15);
let globalMultiplier = 1.13;
if (document.getElementById("HD").checked) {
globalMultiplier *= 1.075
strainValue *= 1.025
}
if (document.getElementById("EZ").checked) {
globalMultiplier *= 0.975
strainValue *= 0.985
}
if (document.getElementById("FL").checked) {
strainValue *= 1.05 * strainLengthBonus
}
if (document.getElementById("HR").checked) {
strainValue *= 1.05
}
if (document.getElementById("HD").checked && document.getElementById("FL").checked) {
accValue *= Math.max(1.050, 1.075 * accLengthBonus);
}
let totalValue = Math.pow(Math.pow(strainValue, 1.1) + Math.pow(accValue, 1.1), 1.0 / 1.1) * globalMultiplier;
document.getElementById("pp").innerHTML = Math.round(totalValue * 1000) / 1000 + " pp"
};