diff --git a/mk_rate b/mk_rate
index 07736ac..9982ce8 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -28,7 +28,7 @@
#   * Rated games, which were played by both rated players.
#   * Rated players, who logged in the server with a name followed by a trip:
#     "name,trip".
#   * Rated games, which were played by both rated players.
#   * Rated players, who logged in the server with a name followed by a trip:
#     "name,trip".
-#   * (Rated) players, who played more than \$GAMES_LIMIT [ten] (rated) games.
+#   * (Rated) players, who played more than \$GAMES_LIMIT  (rated) games.
#
#
# PREREQUIRE
#
#
# PREREQUIRE
@@ -60,7 +60,7 @@ require 'rgl/connected_components'
#

# Count out players who play less games than \$GAMES_LIMIT
#

# Count out players who play less games than \$GAMES_LIMIT
-\$GAMES_LIMIT = \$DEBUG ? 0 : 10
+\$GAMES_LIMIT = \$DEBUG ? 0 : 15
WIN_MARK  = "win"
LOSS_MARK = "lose"
DRAW_MARK = "draw"
WIN_MARK  = "win"
LOSS_MARK = "lose"
DRAW_MARK = "draw"
@@ -210,9 +210,9 @@ class Rating
end

##
end

##
-  # The initial value of the rate, which is of very importance for Newton method.
-  # This is based on my huristics; the higher the win probablity of a player is,
-  # the greater points he takes.
+  # The initial value of the rate, which is of very importance for Newton
+  # method.  This is based on my huristics; the higher the win probablity of
+  # a player is, the greater points he takes.
#
def initial_rate
possibility =
#
def initial_rate
possibility =
@@ -368,7 +368,7 @@ class WinLossMatrix
keys = players.keys.sort
size = keys.size
matrix =
keys = players.keys.sort
size = keys.size
matrix =
-      Matrix[*
+      GSL::Matrix[*
((0...size).collect do |k|
p1 = keys[k]
p1_hash = players[p1]
((0...size).collect do |k|
p1 = keys[k]
p1_hash = players[p1]
@@ -424,11 +424,15 @@ class WinLossMatrix
copied_cols = []
(0...size).each do |i|
next if i == delete_index
copied_cols = []
(0...size).each do |i|
next if i == delete_index
-      row = @matrix.get_row(i)  # get_row returns a copy of the row
+      row = @matrix.row(i).clone
row.delete_at(delete_index)
copied_cols << row
end
row.delete_at(delete_index)
copied_cols << row
end
-    new_matrix = Matrix[*copied_cols]
+    if copied_cols.size == 0
+      new_matrix = GSL::Matrix.new
+    else
+      new_matrix = GSL::Matrix[*copied_cols]
+    end
new_keys = @keys.clone
new_keys.delete_at(delete_index)
return WinLossMatrix.new(new_keys, new_matrix)
new_keys = @keys.clone
new_keys.delete_at(delete_index)
return WinLossMatrix.new(new_keys, new_matrix)
@@ -446,7 +450,8 @@ class WinLossMatrix
end

##
end

##
-  # Removes players who do not pass a criteria to be rated, and returns a new object.
+  # Removes players who do not pass a criteria to be rated, and returns a
+  # new object.
#
def filter
\$stderr.puts @keys.inspect if \$DEBUG
#
def filter
\$stderr.puts @keys.inspect if \$DEBUG
@@ -497,7 +502,7 @@ class WinLossMatrix

result = subsets.collect do |keys|
matrix =

result = subsets.collect do |keys|
matrix =
-        Matrix[*
+        GSL::Matrix[*
((0...keys.size).collect do |k|
p1 = @keys.index(keys[k])
((0...keys.size).collect do |j|
((0...keys.size).collect do |k|
p1 = @keys.index(keys[k])
((0...keys.size).collect do |j|
@@ -505,7 +510,7 @@ class WinLossMatrix
0
else
p2 = @keys.index(keys[j])
0
else
p2 = @keys.index(keys[j])
-              @matrix[p1][p2]
+              @matrix[p1,p2]
end
end)
end)]
end
end)
end)]
@@ -620,31 +625,57 @@ def main
Dir.glob( File.join(dir, "**", "*.csa") ) {|f| grep(f)}
end

Dir.glob( File.join(dir, "**", "*.csa") ) {|f| grep(f)}
end

-  obj = WinLossMatrix::mk_win_loss_matrix(\$players)
yaml = {}
yaml["players"] = {}
rating_group = 0
yaml = {}
yaml["players"] = {}
rating_group = 0
-  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!
-
-    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("+"),
-          'rating_group' => rating_group,
-          'rate' => rating.rate[i],
-          'last_modified' => \$players_time[p].dup,
-          'win'  => win,
-          'loss' => loss}
+  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!
+
+      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("+"),
+            '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
end
-    rating_group += 1
+    next if found
+
+    v = GSL::Vector[0, 0]
+    \$players[id].each_value {|value| v += value}
+    next if v < 1 && v < 1
+
+    yaml["players"][non_rated_group][id] =
+      { 'name' => id.split("+"),
+        'rating_group' => non_rated_group,
+        'rate' => 0,
+        'last_modified' => \$players_time[id].dup,
+        'win'  => v,
+        'loss' => v}
end
puts yaml.to_yaml
end
end
puts yaml.to_yaml
end