From 25a657df602024f0d32b7ee4c58b0b6a8e3af48b Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Tue, 12 Dec 2017 20:38:14 -0500 Subject: [PATCH] Add a KReducer struct. --- xonstat/util/xs_glicko.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 -- 2.39.2