OSDN Git Service

If the computed ratings do not stabilize, then mk_rate aborts.
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Tue, 4 Mar 2008 15:09:56 +0000 (15:09 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Tue, 4 Mar 2008 15:09:56 +0000 (15:09 +0000)
  $ ./mk_rate dir && ./mk_rate dir > players.yaml
can avoid rewriting the invalid ratings to the file.

changelog
mk_rate

index c4a9c9c..7e58998 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+2008-03-04 Daigo Moriwaki <daigo at debian dot org>
+
+       * [mk_rate]
+         - If the computed ratings do not stabilize, then mk_rate aborts.
+             $ ./mk_rate dir && ./mk_rate dir > players.yaml 
+           can avoid rewriting the invalid ratings to the file.
+
 2008-02-23 Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
diff --git a/mk_rate b/mk_rate
index 9982ce8..f8046f0 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -1,7 +1,7 @@
 #!/usr/bin/ruby
 ## $Id$
 
-## Copyright (C) 2006 Daigo Moriwaki <daigo at debian dot org>
+## Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #
 # Sample:
 #   $ ./mk_rate . > players.yaml
+#   $ ./mk_rate . && ./mk_rate . > players.yaml
 #
 # The conditions that games and players are rated as following:
 #   * Rated games, which were played by both rated players.
@@ -619,6 +620,19 @@ USAGE: #{$0} dir [...]
   exit 1
 end
 
+def validate(yaml)
+  yaml["players"].each do |group_key, group|
+    group.each do |player_key, player|
+      rate = player['rate']
+      next unless rate
+      if rate > 10000 || rate < -10000
+        return false
+      end
+    end
+  end
+  return true
+end
+
 def main
   usage if ARGV.empty?
   while dir = ARGV.shift do
@@ -677,6 +691,10 @@ def main
         'win'  => v[0],
         'loss' => v[1]}
   end
+  unless validate(yaml)
+    $stderr.puts "Aborted. It did not result in valid ratings."
+    exit 10
+  end
   puts yaml.to_yaml
 end