From: Daigo Moriwaki Date: Sun, 26 Feb 2017 05:32:07 +0000 (+0900) Subject: Fix #37023: utils/csa-filter.rb: Allow csa-filter.rb to filter games by a winner... X-Git-Tag: 20170902^2~4 X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=commitdiff_plain;h=da06093f093b62e4ac2de28dac584412ad0e86d8;hp=bda0cbd86a4e0e7c18fcfaf3a783c584cd7a86ad;ds=sidebyside Fix #37023: utils/csa-filter.rb: Allow csa-filter.rb to filter games by a winner or loser New command lines, --winner or --loser , are now supported to supply extra filtering conditions. Note that each filter is combined as AND condition. --- diff --git a/changelog b/changelog index e10812c..9e650fd 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,14 @@ +2017-02-26 Daigo Moriwaki + + * utils/csa-filter.rb: Allow csa-filter.rb to filter games by a winner or loser + New command lines, --winner or --loser , are now + supported to supply extra filtering conditions. Note that each + filter is combined as AND condition. + E.g. + - % ./csa-filter.rb ~/Downloads/20160314 --white gpsfish_xeon --loser gpsfish_xeon + - % ./csa-filter.rb ~/Downloads/20160314 --white gpsfish_xeon --winner gpsfish_xeon + (Closes #37023) + 2016-12-11 Daigo Moriwaki * Update Revision to 20161211. diff --git a/utils/csa-filter.rb b/utils/csa-filter.rb index 72a8662..deadf21 100755 --- a/utils/csa-filter.rb +++ b/utils/csa-filter.rb @@ -5,7 +5,7 @@ # you will see such files under the some_dir directory. # # Author:: Daigo Moriwaki -# Copyright:: Copyright (C) 2006-2012 Daigo Moriwaki +# Copyright:: Copyright (C) 2006-2017 Daigo Moriwaki # # $Id$ # @@ -77,20 +77,18 @@ class CsaFileReader if /^'\$END_TIME:(.*)$/ =~ @str @end_time = Time.parse($1.strip) end - if /^'rating:(.*)$/ =~ @str - black_id, white_id = $1.split(":").map {|a| a.strip} + if /^'summary:.*?:(.*)$/ =~ @str + black_id, bresult, white_id, wresult = $1.split(":").map {|a| a.strip.split(" ")}.flatten @black_id = identify_id(black_id) @white_id = identify_id(white_id) - if @black_id && @white_id && (@black_id != @white_id) && - @black_mark && @white_mark + if @black_id && @white_id if black_mark == WIN_MARK && white_mark == LOSS_MARK @winner, @loser = @black_id, @white_id elsif black_mark == LOSS_MARK && white_mark == WIN_MARK @winner, @loser = @white_id, @black_id - elsif black_mark == DRAW_MARK && white_mark == DRAW_MARK + else + # draw or errors @winner, @loser = nil, nil - else - raise "Never reached!" end end end @@ -135,6 +133,8 @@ if $0 == __FILE__ puts " --players player_a,player_b select games of the player_a vs the player_b" puts " --black player select games of which the player is Black" puts " --white player select games of which the player is White" + puts " --winner player select games that the player won" + puts " --loser player select games that the player lose" exit 1 end @@ -143,7 +143,9 @@ if $0 == __FILE__ parser = GetoptLong.new( ['--black', GetoptLong::REQUIRED_ARGUMENT], ['--white', GetoptLong::REQUIRED_ARGUMENT], - ['--players', GetoptLong::REQUIRED_ARGUMENT] + ['--players', GetoptLong::REQUIRED_ARGUMENT], + ['--winner', GetoptLong::REQUIRED_ARGUMENT], + ['--loser', GetoptLong::REQUIRED_ARGUMENT] ) begin parser.each_option do |name, arg| @@ -175,6 +177,14 @@ if $0 == __FILE__ if $OPT_WHITE next unless csa.white_id.downcase.index($OPT_WHITE.downcase) == 0 end + + if $OPT_WINNER + next unless csa.winner && csa.winner.downcase.index($OPT_WINNER.downcase) == 0 + end + if $OPT_LOSER + next unless csa.loser && csa.loser.downcase.index($OPT_LOSER.downcase) == 0 + end + puts csa.file_name end end