#!/usr/bin/ruby ## $Id$ ## Copyright (C) 2006 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 # # This generates html pages from players.yaml. # # Sample: # $ ./mk_html < players.yaml > rating.html # require 'yaml' require 'erb' include ERB::Util def show_date(time) time.strftime("%Y-%m-%d") end def usage $stderr.puts <<-EOF USAGE: #{$0} EOF exit 1 end def main lines = "" while l = gets do lines << l end yaml = YAML::load(lines) sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} erb = ERB.new( DATA.read, nil, "%<>" ) body = erb.result(binding) puts body end if __FILE__ == $0 main end # vim: ts=2 sw=2 sts=0 __END__ Shogi Server Rating

Shogi Server Rating

<% sorted_keys.each do |key| %> <% win = yaml[key]['win'] loss = yaml[key]['loss'] win_rate = win.to_f / (win + loss) last_modified = yaml[key]['last_modified'] %> <% end %>
name rate win loss win_rate last_modified
<%=h yaml[key]['name']%> <%="%5d" % [ yaml[key]['rate'] ]%> <%="%5d" % [ win ]%> <%="%5d" % [ loss ]%> <%="%.3f" % [win_rate]%> <%=show_date(last_modified)%>

The average of the rates is 1000.