#!/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 file = YAML::load(lines) erb = ERB.new( DATA.read, nil, "%>" ) tables = [] file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} # sort players in a group by one's rate top_rate = nil table = ERB.new(<") % 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'] player_decoration = "default" case (Time.now - last_modified)/(60*60*24) when (0..1) then player_decoration = "today" when (0..7) then player_decoration = "this_week" end case key when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps" when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps" end rate = yaml[key]['rate'] top_rate ||= rate diff_rate = rate - top_rate diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0)) %> <%= key %> <%= h yaml[key]['name'] %> <%= "%5d" % [ diff_rate ] %> | <%= "%.3f" % [ diff_possibility ] %> <%= "%5d" % [ rate ] %> <%= "%5d" % [ win ] %> <%= "%5d" % [ loss ] %> <%= "%.3f" % [win_rate] %> <%= show_date(last_modified) %> % end ENDTABLE tables << table.result(binding) end 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

% tables.each_with_index do |t, index| <%= t %>
Group: <%=index%>
name rate win loss win_rate last_modified

% end

Groups are independently rated. You can not compare rates across them.

The average of the rates in a group is always 1000.

BACK