X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=mk_html;h=e472670d7f4e327b1a4b55c864051a053293605b;hp=31bfe802dc23bf0567ffbc02869699f6c2ac1d8e;hb=d7dc48d302a0b0ffaeba2f7a05099912e148a1c6;hpb=d5c2258ffe8f234420d38763bc4f8b51cd3567fd diff --git a/mk_html b/mk_html index 31bfe80..e472670 100755 --- a/mk_html +++ b/mk_html @@ -1,56 +1,148 @@ -#!/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 -# +#!/usr/bin/ruby1.9.1 +# $Id$ +# +# Author:: Daigo Moriwaki +# Homepage:: http://sourceforge.jp/projects/shogi-server/ +# +#-- +# Copyright (C) 2006-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_html generates an html page from a players.yaml. +# +# == Usage +# +# ./mk_html [OPTION] < players.yaml > rating.html +# +# [-h, --help] +# show help +# +# [-w,--wdoor] +# adpot wdoor style +# +# [--footer filename] +# insert contents in the filename at the bottom of a genrated page. +# +# == Prerequire +# +# * Ruby 1.9.3 or 1.8.7 +# +# $ sudo aptitude install ruby ruby1.9.1 +# +# == Example +# +# $ ./mk_html --footer ./wdoor_1000.html < players.yaml > players.html +# +# $ cat ./wdoor-1000.html +#

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

BACK +# +require 'optparse' require 'yaml' require 'erb' include ERB::Util def show_date(time) - time.strftime("%Y-%m-%d") + if (Time.now - time < 30*60) + return "on line" + elsif (Time.now - time < 24*60*60) + return time.strftime("%Y-%m-%d") + # return "%d hours ago" % [(Time.now - time)/3600] + else + return time.strftime("%Y-%m-%d") + end end -def usage - $stderr.puts <<-EOF -USAGE: #{$0} - EOF - exit 1 +def remove_long_to_see_players(file) + return unless file["players"][999] # only for Not-Yet-Rated players + + file["players"][999].delete_if do |key, value| + value['last_modified'] < Time.now - 24*3600*30 # 30 days + end end def main + $wdoor = false + $footer_content = nil + opts = OptionParser.new + opts.banner = "Usage: mk_html [OPTIONS]" + opts.on("--footer filename", String, "Insert contents of the filename at the bottom of a genrated page") do |filename| + unless File.exist?(filename) + $stderr.puts "File not found: %s" % [filename] + raise + end + $footer_content = File.open(filename).read + end + opts.on("-w","--wdoor", "adopt a wdoor style") { $wdoor=true } + opts.on_tail("-h", "--help", "show this message") do + puts opts + exit + end + begin + opts.parse(ARGV) + rescue + puts opts + exit -1 + end + lines = "" - while l = gets do + while l = $stdin.gets do lines << l end file = YAML::load(lines) erb = ERB.new( DATA.read, nil, "%>" ) tables = [] + group_names = [] + file["players"].keys.sort.each do |index| + if index < 999 + group_names << "#{index}" + else + group_names << "Not-Yet-Rated Players" + end + end + remove_long_to_see_players(file) + + popup_id = 0 + if $wdoor + yss_rate = 0 + file["players"].keys.each do |group_index| + file["players"][group_index].each do |player, yaml| + if player == "YSS+707d4f98d9d2620cdaab58f19d02a2e4" + yss_rate = yaml['rate'] + end + end + end + end + 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 + sorted_keys = yaml.keys.sort do |a,b| + # sort players in a group by one's rate + if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0 + # mainly for not-rated-yet players + yaml[b]['last_modified'] <=> yaml[a]['last_modified'] + else + yaml[b]['rate'] <=> yaml[a]['rate'] + end + end top_rate = nil table = ERB.new(<") % sorted_keys.each do |key| @@ -62,9 +154,10 @@ def main 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" + case (Time.now - last_modified)/60 # minutes + when (0..30) then player_decoration = "current" + when (0..(1*60*24)) then player_decoration = "today" + when (0..(7*60*24)) then player_decoration = "this_week" end case key @@ -79,11 +172,21 @@ def main %> - <%= key %> - <%= h yaml[key]['name'] %> + <%= h yaml[key]['name'] %> + + - <%= "%5d" % [ diff_rate ] %> | <%= "%.3f" % [ diff_possibility ] %> - <%= "%5d" % [ rate ] %> + <%= rate != 0 ? "%5d" % [ rate ] : "N/A" %> + + <%= "%5d" % [ win ] %> @@ -92,6 +195,10 @@ def main <%= "%.3f" % [win_rate] %> <%= show_date(last_modified) %> +% if $wdoor + + <%= rate != 0 && yss_rate > 0 ? ("%5d" % [2300 - yss_rate + rate]) : "N/A" %> +% end % end ENDTABLE @@ -114,55 +221,44 @@ __END__ Shogi Server Rating + + + + + + + + + + + - +

+ +
+

Shogi Server Rating

% tables.each_with_index do |t, index| - +@@ -170,6 +266,9 @@ __END__ +% if $wdoor + +% end @@ -177,8 +276,11 @@ __END__ - + +% if $wdoor + +% end @@ -191,16 +293,18 @@ __END__ % end

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

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

BACK + +<%= $footer_content %>


+ + -
Group: <%=index%>Group: <%=group_names[index]%>
rate win losswin_rate% last_modified(rate24)