]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add a KReducer struct.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 13 Dec 2017 01:38:14 +0000 (20:38 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 13 Dec 2017 01:38:14 +0000 (20:38 -0500)
xonstat/util/xs_glicko.go

index c34c3261b2d2eb3f4bffd681ae8ce8817c84c882..1a8d8a5b5f78ad3e5a4e1ede395ed2eac233b163 100644 (file)
@@ -74,6 +74,35 @@ type PlayerGameStat struct {
        Score            int    `db:"score"`
 }
 
+type KReducer struct {
+       // Time in seconds required for full points
+       FullTime int
+
+       // The minimum time a player must play in the game
+       MinTime int
+
+       // The minimum ratio of time played in the game
+       MinRatio float64
+}
+
+func (kr *KReducer) Evaluate(pgstat PlayerGameStat, game Game) float64 {
+       k := 1.0
+
+       if pgstat.AliveTime < kr.FullTime {
+               k = float64(pgstat.AliveTime) / float64(kr.FullTime)
+       }
+
+       if pgstat.AliveTime < kr.MinTime || game.Duration < kr.MinTime {
+               k = 0
+       }
+
+       if (float64(pgstat.AliveTime) / float64(game.Duration)) < kr.MinRatio {
+               k = 0
+       }
+
+       return k
+}
+
 type GameProcessor struct {
        config *Config
        db     *sqlx.DB