From: Ant Zucaro Date: Wed, 13 Dec 2017 01:38:14 +0000 (-0500) Subject: Add a KReducer struct. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=25a657df602024f0d32b7ee4c58b0b6a8e3af48b;p=xonotic%2Fxonstat.git Add a KReducer struct. --- diff --git a/xonstat/util/xs_glicko.go b/xonstat/util/xs_glicko.go index c34c326..1a8d8a5 100644 --- a/xonstat/util/xs_glicko.go +++ b/xonstat/util/xs_glicko.go @@ -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