-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathELO.java
More file actions
85 lines (76 loc) · 2.13 KB
/
ELO.java
File metadata and controls
85 lines (76 loc) · 2.13 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.ArrayList;
public class ELO {
ArrayList<Data> dl;
ArrayList<Team> tl;
//Global K-Values
int K_Value = 100;
public ELO(ArrayList<Data> d,ArrayList<Team> t) {
dl = d;
tl = t;
calculateELO();
}
private void calculateELO(){
String winner,loser;
Team winnerT, loserT;
int w_id = 0, l_id = 0;
for(int i = 0;i < dl.size();i++) {
//OutPut for CSV of DataScience
double h_elo = 0;
double a_elo = 0;
int ho = 0,aw = 0;
winner = dl.get(i).winner;
loser = dl.get(i).loser;
winnerT = null;
loserT = null;
for(int a = 0;a < tl.size();a++) {
if(tl.get(a).name.equals(winner)) {
winnerT = tl.get(a);
w_id = a;
//Data Science
if(winner.equals(dl.get(i).homeT)) {
h_elo = tl.get(a).ELO;
ho = a;
}
else if(winner.equals(dl.get(i).awayT)) {
a_elo = tl.get(a).ELO;
aw = a;
}
}
else if(tl.get(a).name.equals(loser)) {
loserT = tl.get(a);
l_id = a;
//Data Science
if(loser.equals(dl.get(i).homeT)) {
h_elo = tl.get(a).ELO;
ho = a;
}
else if(loser.equals(dl.get(i).awayT)) {
a_elo = tl.get(a).ELO;
aw = a;
}
}
}
//Data Science Output
int w_diff = (tl.get(ho).W-tl.get(aw).W);
int l_diff = (tl.get(ho).L-tl.get(aw).L);
if(winnerT.ELO != 1500 && loserT.ELO != 1500) {
System.out.println(dl.get(i).DM_W+","+dl.get(i).P5_dif+","+ w_diff +","+ l_diff +"," +(h_elo-a_elo)+","+
dl.get(i).week);
}
//ELO Calculation
//First we Transform rating
double winnerTransElo = Math.pow(10,winnerT.ELO/400);
double loserTransElo = Math.pow(10,loserT.ELO/400);
//Next we get expected score
double winnerExpected = winnerTransElo/(winnerTransElo+loserTransElo);
double loserExpected = loserTransElo/(winnerTransElo+loserTransElo);
//Updated Elo
double newWinnerElo = winnerT.ELO + (K_Value*(1.0-winnerExpected));
double newLoserElo = loserT.ELO + (K_Value*(0.0-loserExpected));
tl.get(w_id).ELO = newWinnerElo;
tl.get(l_id).ELO = newLoserElo;
tl.get(w_id).W = tl.get(w_id).W+1;
tl.get(l_id).L = tl.get(w_id).L+1;
}
}
}