OSDN Git Service

* [mk_rate]
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 15 Nov 2009 13:24:45 +0000 (13:24 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Sun, 15 Nov 2009 13:24:45 +0000 (13:24 +0000)
  - Added a new command line option: --base-date. You can specify a
    base date to calculate rating scores. Games in the `future' are
    ignored for the calculation.

changelog
mk_rate

index fe7794b..2fec24f 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+2009-11-11 Daigo Moriwaki <daigo at debian dot org>
+
+       * [mk_rate]
+         - Added a new command line option: --base-date. You can specify a
+           base date to calculate rating scores. Games in the `future' are
+           ignored for the calculation.
+
 2009-11-10 Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
@@ -10,7 +17,7 @@
               % ./mk_game_results dir_of_csa_files > 00LIST
            2. Run the server. It appends a result of each game to
               '00LIST' when the game finishes.
-           3. From the list of game results, calcurate rating scores of
+           3. From the list of game results, calculate rating scores of
               players.
               % ./mk_rate 00LIST > players.yaml
 
diff --git a/mk_rate b/mk_rate
index e3350e5..1409df3 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -34,6 +34,9 @@
 # DIR::
 #   CSA files are recursively looked up the directories.
 #
+# --base-date::
+#   a base time point for this calicuration (default now). Ex. '2009-10-31'
+#
 # --half-life::
 #   n [days] (default 60)
 #   
@@ -591,7 +594,7 @@ def half_life(days)
 end
 
 def _add_win_loss(winner, loser, time)
-  how_long_days = (Time.now - time)/(3600*24)
+  how_long_days = ($options["base-date"] - time)/(3600*24)
   $players[winner] ||= Hash.new { GSL::Vector[0,0] }
   $players[loser]  ||= Hash.new { GSL::Vector[0,0] }
   $players[winner][loser] += GSL::Vector[1.0*half_life(how_long_days),0]
@@ -635,6 +638,7 @@ def parse(line)
 
   return if state == "abnormal"
   time = Time.parse(time)
+  return if $options["base-date"] < time
   black_id = identify_id(black_id)
   white_id = identify_id(white_id)
 
@@ -662,6 +666,7 @@ def usage(io)
 USAGE: #{$0} [options] DIR..
   DIR                where CSA files are looked up recursively
 OPTOINS:
+  --base-date         a base time point for this calicuration (default now). Ex. '2009-10-31'
   --half-life         n [days] (default 60)
   --half-life-ignore  m [days] (default  7)
                       after m days, half-life effect works
@@ -674,6 +679,7 @@ end
 def main
   $options = Hash::new
   parser = GetoptLong.new(
+    ["--base-date",         GetoptLong::REQUIRED_ARGUMENT],
     ["--half-life",         GetoptLong::REQUIRED_ARGUMENT],
     ["--half-life-ignore",  GetoptLong::REQUIRED_ARGUMENT],
     ["--help", "-h",        GetoptLong::NO_ARGUMENT],
@@ -699,6 +705,11 @@ def main
     usage($stdout) 
     exit 0
   end
+  if $options["base-date"]
+    $options["base-date"] = Time::parse $options["base-date"]
+  else
+    $options["base-date"] = Time.now
+  end
   $options["half-life"] ||= 60
   $options["half-life"] = $options["half-life"].to_i
   $options["half-life-ignore"] ||= 7