• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revision0e15a0c82b0e16fab234e3ce00b4e296262577d5 (tree)
Time2014-07-26 16:01:03
AuthorDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Log Message

Merge branch '201407-abnormal'

Change Summary

Incremental Difference

--- a/changelog
+++ b/changelog
@@ -1,3 +1,12 @@
1+2014-07-19 Daigo Moriwaki <daigo at debian dot org>
2+
3+ * [mk_rate]
4+ - Added a new option, --abnormal-threshold n:
5+ Games that end with the 'abnormal' status are counted in
6+ win/lost games for the rating calculation if a game plays more
7+ than n plies. Otherwise (or if n is zero), abnormal games are
8+ counted out of rating games.
9+
110 2013-12-29 Daigo Moriwaki <daigo at debian dot org>
211
312 * [shogi-server]
--- a/mk_rate
+++ b/mk_rate
@@ -35,12 +35,18 @@
3535 # ./mk_rate [options]
3636 #
3737 # GAME_RESULTS_FILE::
38-# a path to a file listing results of games, which is genrated by the
38+# a path to a file listing results of games, which is generated by the
3939 # mk_game_results command.
4040 # In the second style above, the file content can be read from the stdin.
4141 #
42+# --abnormal-threshold::
43+# n [plies] (default 30)
44+# Games that end with the 'abnormal' status are counted in win/lost games
45+# for the rating calculation if a game plays more than n plies. Otherwise
46+# (or if n is zero), abnormal games are counted out of rating games.
47+#
4248 # --base-date::
43-# a base time point for this calicuration (default now). Ex. '2009-10-31'
49+# a base time point for this calculation (default now). Ex. '2009-10-31'
4450 #
4551 # --half-life::
4652 # n [days] (default 60)
@@ -68,7 +74,7 @@
6874 #
6975 # == PREREQUIRE
7076 #
71-# Sample Command lines that isntall prerequires will work on Debian.
77+# Sample Command lines that install prerequires will work on Debian.
7278 #
7379 # * Ruby 1.9.3 or 1.8.7 (including Rubygems)
7480 #
@@ -101,6 +107,8 @@
101107 # * (Rated) players, who played more than $GAMES_LIMIT [15] (rated) games.
102108 #
103109
110+$:.unshift(File.dirname(File.expand_path(__FILE__)))
111+require 'utils/csa-filter'
104112 require 'yaml'
105113 require 'time'
106114 require 'getoptlong'
@@ -670,7 +678,12 @@ def parse(line)
670678 return
671679 end
672680
673- return if state == "abnormal"
681+ if state == "abnormal"
682+ csa = CsaFileReader.new(file, "EUC-JP")
683+ if $options["abnormal-threshold"] == 0 || csa.ply <= $options["abnormal-threshold"]
684+ return
685+ end
686+ end
674687 time = Time.parse(time)
675688 return if $options["base-date"] < time
676689 how_long_days = ($options["base-date"] - time)/(3600*24)
@@ -728,14 +741,15 @@ end
728741 def main
729742 $options = Hash::new
730743 parser = GetoptLong.new(
731- ["--base-date", GetoptLong::REQUIRED_ARGUMENT],
732- ["--half-life", GetoptLong::REQUIRED_ARGUMENT],
733- ["--half-life-ignore", GetoptLong::REQUIRED_ARGUMENT],
734- ["--help", "-h", GetoptLong::NO_ARGUMENT],
735- ["--ignore", GetoptLong::REQUIRED_ARGUMENT],
736- ["--fixed-rate-player", GetoptLong::REQUIRED_ARGUMENT],
737- ["--fixed-rate", GetoptLong::REQUIRED_ARGUMENT],
738- ["--skip-draw-games", GetoptLong::NO_ARGUMENT])
744+ ["--abnormal-threshold", GetoptLong::REQUIRED_ARGUMENT],
745+ ["--base-date", GetoptLong::REQUIRED_ARGUMENT],
746+ ["--half-life", GetoptLong::REQUIRED_ARGUMENT],
747+ ["--half-life-ignore", GetoptLong::REQUIRED_ARGUMENT],
748+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
749+ ["--ignore", GetoptLong::REQUIRED_ARGUMENT],
750+ ["--fixed-rate-player", GetoptLong::REQUIRED_ARGUMENT],
751+ ["--fixed-rate", GetoptLong::REQUIRED_ARGUMENT],
752+ ["--skip-draw-games", GetoptLong::NO_ARGUMENT])
739753 parser.quiet = true
740754 begin
741755 parser.each_option do |name, arg|
@@ -761,6 +775,8 @@ def main
761775 else
762776 $options["base-date"] = Time.now
763777 end
778+ $options["abnormal-threshold"] ||= 30
779+ $options["abnormal-threshold"] = $options["abnormal-threshold"].to_i
764780 $options["half-life"] ||= 60
765781 $options["half-life"] = $options["half-life"].to_i
766782 $options["half-life-ignore"] ||= 7
--- a/utils/csa-filter.rb
+++ b/utils/csa-filter.rb
@@ -42,21 +42,23 @@ class CsaFileReader
4242 attr_reader :winner, :loser
4343 attr_reader :state
4444 attr_reader :start_time, :end_time
45+ attr_reader :ply
4546
46- def initialize(file_name)
47+ def initialize(file_name, encoding="Shift_JIS:EUC-JP")
4748 @file_name = file_name
49+ @encoding = encoding
50+ @ply = 0
4851 grep
4952 end
5053
5154 def grep
52- @str = File.open(@file_name, "r:Shift_JIS:EUC-JP").read
55+ @str = File.open(@file_name, "r:#{@encoding}").read
5356
5457
5558 if /^N\+(.*)$/ =~ @str then @black_name = $1.strip end
5659 if /^N\-(.*)$/ =~ @str then @white_name = $1.strip end
5760 if /^'summary:(.*)$/ =~ @str
5861 @state, p1, p2 = $1.split(":").map {|a| a.strip}
59- return if @state == "abnormal"
6062 p1_name, p1_mark = p1.split(" ")
6163 p2_name, p2_mark = p2.split(" ")
6264 if p1_name == @black_name
@@ -92,6 +94,12 @@ class CsaFileReader
9294 end
9395 end
9496 end
97+
98+ @str.each_line do |line|
99+ if /^[\+\-]\d{4}[A-Z]{2}/ =~ line
100+ @ply += 1
101+ end
102+ end
95103 end
96104
97105 def movetimes
@@ -107,7 +115,8 @@ class CsaFileReader
107115 "BlackName #{@black_name}, WhiteName #{@white_name}\n" +
108116 "BlackId #{@black_id}, WhiteId #{@white_id}\n" +
109117 "Winner #{@winner}, Loser #{@loser}\n" +
110- "Start #{@start_time}, End #{@end_time}\n"
118+ "Start #{@start_time}, End #{@end_time}\n" +
119+ "Ply #{@ply}"
111120 end
112121
113122 def identify_id(id)