-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
73 lines (60 loc) · 1.49 KB
/
test.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
const calculateEloPoint = (data) => {
const eloA = parseInt(data.eloA);
const eloB = parseInt(data.eloB);
const goalA = parseInt(data.goalA);
const goalB = parseInt(data.goalB);
try {
const diffGoal = Math.abs(goalA - goalB);
const diffElo = (eloA - eloB);
// G
let G = 0;
if (diffGoal == 1) G = 1;
else if (diffGoal == 2) G = 1.5;
else G = (11 + diffGoal)/8;
// W0
const W0 = 1/(Math.pow(10, (-diffElo/400)) + 1);
// W
let W;
if (goalA > goalB) W = 1;
else if (goalA == goalB) W = 0.5;
else W = 0;
// P
const P = parseInt(32 * G * (W - W0), 10);
return [eloA + P, eloB - P, G, W, W0, P];
} catch (error) {
console.log(error);
throw error;
}
}
const calculateEloPointV2 = (data) => {
const eloA = parseInt(data.eloA);
const eloB = parseInt(data.eloB);
const goalA = parseInt(data.goalA);
const goalB = parseInt(data.goalB);
try {
const diffGoal = Math.abs(goalA - goalB);
const diffElo = eloA - eloB;
// // G
// const G = 0;
// if (diffGoal == 1) G = 1;
// else if (diffGoal == 1.5) G = 2;
// else G = (11 + diffGoal)/8
// W0
const W0 = 1/(Math.pow(10, (-diffElo/400)) + 1)
// W
const W = goalA - goalB
// P
const PA = parseInt(32 * (W - W0))
return [eloA + PA, eloB - PA]
} catch (error) {
console.log(error);
throw error;
}
}
const result = calculateEloPointV2({
eloA: 200,
eloB: 1000,
goalA: 1,
goalB: 0
})
console.log(result);