OSDN Git Service

* [mk_rate] Now duplicated inputs are checked and skipped.
authorDaigo Moriwaki <daigo@debian.org>
Sat, 23 Nov 2013 13:48:34 +0000 (22:48 +0900)
committerDaigo Moriwaki <daigo@debian.org>
Sat, 23 Nov 2013 13:48:34 +0000 (22:48 +0900)
changelog
mk_rate

index 077bc80..a562e3d 100644 (file)
--- a/changelog
+++ b/changelog
@@ -2,6 +2,7 @@
 
        * [mk_rate]
          - gsl library may be provided as a gem
+         - Now duplicated inputs are checked and skipped.
        * test/TC_floodgate.rb
          - Improved randomness check so that it works on Ruby 2.0.0 as well
 
diff --git a/mk_rate b/mk_rate
index 6252991..1f9e54a 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
 require 'yaml'
 require 'time'
 require 'getoptlong'
+require 'set'
 require 'rubygems'
 require 'gsl'
 require 'rgl/adjacency'
@@ -123,6 +124,8 @@ DRAW_MARK = "draw"
 $players = Hash.new
 # Holds the last time when a player gamed
 $players_time = Hash.new { Time.at(0) }
+# Holds history of input lines to check duplicated inputs
+$history = Set.new
 
 
 #################################################
@@ -654,6 +657,12 @@ end
 # Parse a game result line
 #
 def parse(line)
+  if $history.include? line
+    $stderr.puts "[WARNING] Duplicated: #{line}"
+    return
+  end
+  $history.add line
+
   time, state, black_mark, black_id, white_id, white_mark, file = line.split("\t")
   unless time && state && black_mark && black_id &&
          white_id && white_mark && file