]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Apply ping adjustments to scorefactor_elo instead.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 24 Apr 2017 22:35:24 +0000 (18:35 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 24 Apr 2017 22:35:24 +0000 (18:35 -0400)
xonstat/elo.py

index aefe9e020f1a50a2d2f7fddc68171a8953a66a3d..536f16e4bf1c5de15eee0d93416c50a002a2ab1b 100644 (file)
@@ -218,46 +218,24 @@ class EloProcessor:
                     (float(ei.elo) - float(ej.elo)) * ep.logdistancefactor))
                 scorefactor_elo = 1 / (1 + math.exp(-elodiff))
 
-                # raw ping ratios
-                ping_ratio_i = self.pingfactor(pi, pj)
-                ping_ratio_j = self.pingfactor(pj, pi)
-
-                if ping_ratio_i > 0.5:
-                    if scorefactor_real > 0.5:
-                        log.debug("player i has the ping disadvantage and won")
-                        pingfactor_i = 1 + ping_ratio_i * ep.latency_trend_factor
-                        pingfactor_j = 1 + ping_ratio_j * ep.latency_trend_factor
-                    else:
-                        log.debug("player i has the ping disadvantage and lost")
-                        pingfactor_i = 1 - ping_ratio_i * ep.latency_trend_factor
-                        pingfactor_j = 1 - ping_ratio_j * ep.latency_trend_factor
-
-                elif ping_ratio_i < 0.5:
-                    if scorefactor_real > 0.5:
-                        log.debug("player j has the ping disadvantage and lost")
-                        pingfactor_i = 1 - ping_ratio_i * ep.latency_trend_factor
-                        pingfactor_j = 1 - ping_ratio_j * ep.latency_trend_factor
-                    else:
-                        log.debug("player j has the ping disadvantage and won")
-                        pingfactor_i = 1 + ping_ratio_i * ep.latency_trend_factor
-                        pingfactor_j = 1 + ping_ratio_j * ep.latency_trend_factor
-                else:
-                    log.debug("the pings are equal")
-                    pingfactor_i = pingfactor_j = 1
+                # adjust the elo prediction according to ping
+                ping_ratio = self.pingfactor(pi, pj)
+                scorefactor_ping = ep.latency_trend_factor * (0.5 - ping_ratio)
+                scorefactor_elo_adjusted = max(0, min(1, scorefactor_elo + scorefactor_ping))
 
                 # initial adjustment values, which we may modify with additional rules
-                adjustmenti = (scorefactor_real - scorefactor_elo) * pingfactor_i
-                adjustmentj = (scorefactor_elo - scorefactor_real) * pingfactor_j
+                adjustmenti = scorefactor_real - scorefactor_elo_adjusted
+                adjustmentj = scorefactor_elo_adjusted - scorefactor_real
 
                 # DEBUG
                 log.debug("(New) Player i: {0}".format(ei.player_id))
                 log.debug("(New) Player i's K: {0}".format(self.wip[pids[i]].k))
-                log.debug("(New) Player i's pingfactor: {0}".format(pingfactor_i))
                 log.debug("(New) Player j: {0}".format(ej.player_id))
                 log.debug("(New) Player j's K: {0}".format(self.wip[pids[j]].k))
-                log.debug("(New) Player j's pingfactor: {0}".format(pingfactor_j))
+                log.debug("(New) Ping ratio: {0}".format(ping_ratio))
                 log.debug("(New) Scorefactor real: {0}".format(scorefactor_real))
                 log.debug("(New) Scorefactor elo: {0}".format(scorefactor_elo))
+                log.debug("(New) Scorefactor ping: {0}".format(scorefactor_ping))
                 log.debug("(New) adjustment i: {0}".format(scorefactor_real - scorefactor_elo))
                 log.debug("(New) adjustment j: {0}".format(scorefactor_elo - scorefactor_real))
                 log.debug("(New) adjustment i with ping: {0}".format(adjustmenti))