- win_loss_matrix, keys = mk_win_loss_matrix($players)
- $stderr.puts keys.inspect if $DEBUG
- $stderr.puts win_loss_matrix.inspect if $DEBUG
- rating = Rating.new(win_loss_matrix)
- rating.rating
- rating.average!(Rating::AVERAGE_RATE)
- rating.integer!
-
- yaml = {}
- keys.each_with_index do |p, i| # player_id, index#
- win_loss = $players[p].values.inject(GSL::Vector[0,0]) {|sum, v| sum + v}
- win = win_loss_matrix
- yaml[p] =
- { 'name' => p.split("+")[0],
- 'rate' => rating.rate[i],
- 'last_modified' => $players_time[p].dup,
- 'win' => win_loss[0],
- 'loss' => win_loss[1]}
+ yaml = {}
+ yaml["players"] = {}
+ rating_group = 0
+ if $players.size > 0
+ obj = WinLossMatrix::mk_win_loss_matrix($players)
+ obj.connected_subsets.each do |win_loss_matrix|
+ yaml["players"][rating_group] = {}
+
+ rating = Rating.new(win_loss_matrix.matrix)
+ rating.rating
+ rating.average!(Rating::AVERAGE_RATE)
+ rating.integer!
+
+ if $options["fixed-rate-player"]
+ # first, try exact match
+ index = win_loss_matrix.keys.index($options["fixed-rate-player"])
+ # second, try regular match
+ unless index
+ win_loss_matrix.keys.each_with_index do |p, i|
+ if %r!#{$options["fixed-rate-player"]}! =~ p
+ index = i
+ end
+ end
+ end
+ if index
+ the_rate = rating.rate[index]
+ rating.translate!($options["fixed-rate"] - the_rate)
+ end
+ end
+
+ win_loss_matrix.keys.each_with_index do |p, i| # player_id, index#
+ win = win_loss_matrix.matrix.row(i).sum
+ loss = win_loss_matrix.matrix.col(i).sum
+
+ yaml["players"][rating_group][p] =
+ { 'name' => p.split("+")[0],
+ 'rating_group' => rating_group,
+ 'rate' => rating.rate[i],
+ 'last_modified' => $players_time[p].dup,
+ 'win' => win,
+ 'loss' => loss}
+ end
+ rating_group += 1
+ end
+ end
+ rating_group -= 1
+ non_rated_group = 999 # large enough
+ yaml["players"][non_rated_group] = {}
+ $players.each_key do |id|
+ # skip players who have already been rated
+ found = false
+ (0..rating_group).each do |i|
+ found = true if yaml["players"][i][id]
+ break if found
+ end
+ next if found
+
+ v = GSL::Vector[0, 0]
+ $players[id].each_value {|value| v += value}
+ next if v[0] < 1 && v[1] < 1
+
+ yaml["players"][non_rated_group][id] =
+ { 'name' => id.split("+")[0],
+ 'rating_group' => non_rated_group,
+ 'rate' => 0,
+ 'last_modified' => $players_time[id].dup,
+ 'win' => v[0],
+ 'loss' => v[1]}
+ end
+ unless validate(yaml)
+ $stderr.puts "Aborted. It did not result in valid ratings."
+ $stderr.puts yaml.to_yaml if $DEBUG
+ exit 10