]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/elo.py
dos2unix file conversions for everything
[xonotic/xonstat.git] / xonstat / elo.py
1 import sys
2 import math
3 import random
4
5 class EloParms:
6     def __init__(self, global_K = 15, initial = 100, floor = 100, logdistancefactor = math.log(10)/float(400), maxlogdistance = math.log(10)):
7         self.global_K = global_K
8         self.initial = initial
9         self.floor = floor
10         self.logdistancefactor = logdistancefactor
11         self.maxlogdistance = maxlogdistance
12
13
14 class KReduction:
15     def __init__(self, fulltime, mintime, minratio, games_min, games_max, games_factor):
16         self.fulltime = fulltime
17         self.mintime = mintime
18         self.minratio = minratio
19         self.games_min = games_min
20         self.games_max = games_max
21         self.games_factor = games_factor
22
23     def eval(self, mygames, mytime, matchtime):
24         if mytime < self.mintime:
25             return 0
26         if mytime < self.minratio * matchtime:
27             return 0
28         if mytime < self.fulltime:
29             k = mytime / float(self.fulltime)
30         else:
31             k = 1.0
32         if mygames >= self.games_max:
33             k *= self.games_factor
34         elif mygames > self.games_min:
35             k *= 1.0 - (1.0 - self.games_factor) * (mygames - self.games_min) / float(self.games_max - self.games_min)
36         return k
37
38
39 # parameters for K reduction
40 # this may be touched even if the DB already exists
41 KREDUCTION = KReduction(600, 120, 0.5, 0, 32, 0.2)
42
43 # parameters for chess elo
44 # only global_K may be touched even if the DB already exists
45 # we start at K=200, and fall to K=40 over the first 20 games
46 ELOPARMS = EloParms(global_K = 200)