summaryrefslogtreecommitdiff
path: root/lib/scoring/winner_takes_all.rb
blob: db494c66a60e343e6c1d55476c45a16aa5219416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Scoring
	module WinnerTakesAll
		def self.stats_needed(match)
			return ["win"]
		end

		def self.score(match)
			scores = {}
			match.users.each do |user|
				stats = Statistic.where(user: user, match: match)
				scores[user] = score_user(stats.where(name: "win").first)
			end
			scores
		end

		private
		def self.score_user(win)
			win.nil? ? 0.5 : win ? 1 : 0
		end
	end
end