#!/usr/bin/ruby # $Id$ # # Author:: Daigo Moriwaki # Homepage:: http://sourceforge.jp/projects/shogi-server/ # #-- # Copyright (C) 2008-2012 Daigo Moriwaki # # 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 # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #++ # # == Synopsis # # mk_rate reads CSA files, calculates rating scores of each player, and then # outputs a yaml file (players.yaml) that Shogi-server can recognize. # # == Usage # # (1) csa-file-filter.rb [options] DIR... # # [DIR] # where CSA files are looked for recursively # # (2) csa-file-filter.rb [options] # # CSA file names are put into STDIN. # # OPTOINS: # # [--within n [days]] # find records that were played last n days # # [--help] # show this message # # == Prerequire # # Sample Command lines that isntall prerequires will work on Debian. # # * Ruby 2.0.0 or later including RDoc # # $ sudo aptitude install ruby ruby # # == Example # # If you want kifu files that were played last 14 days to be rated, # # $ find /path/to/dir -name "wdoor+floodgate*.csa" | \ # ./csa-file-filter --within 14 | \ # ./mk_rate --half-life-ignore 14 # require 'date' require 'getoptlong' # # Filter the filename. If the file passes the criteria, it goes to STDOUT; # otherwise, it is ignored. # def filter(filename) # a within filter if $options["within"] return unless /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.csa$/ =~ filename file_date = Date.new($1.to_i, $2.to_i, $3.to_i) return if $now_date - file_date > $options["within"] end puts filename end # # Show an usage of this command # def usage(io) io.puts <