4 ## Copyright (C) 2006 Daigo Moriwaki <daigo at debian dot org>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # This generates html pages from players.yaml.
24 # $ ./mk_html < players.yaml > rating.html
33 time.strftime("%Y-%m-%d")
48 file = YAML::load(lines)
49 erb = ERB.new( DATA.read, nil, "%>" )
52 file["players"].keys.sort.each do |index|
54 group_names << "#{index}"
56 group_names << "Not-Yet-Rated Players"
60 file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
61 sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} # sort players in a group by one's rate
63 table = ERB.new(<<ENDTABLE, nil, "%>")
64 % sorted_keys.each do |key|
66 win = yaml[key]['win']
67 loss = yaml[key]['loss']
68 win_rate = win.to_f / (win + loss)
69 last_modified = yaml[key]['last_modified']
71 player_decoration = "default"
73 case (Time.now - last_modified)/(60*60*24)
74 when (0..1) then player_decoration = "today"
75 when (0..7) then player_decoration = "this_week"
79 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
80 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
83 rate = yaml[key]['rate']
85 diff_rate = rate - top_rate
86 diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
88 <tr class="<%=player_decoration%>">
90 <span class="popup"><%= key %></span>
91 <%= h yaml[key]['name'] %> </td>
93 <span class="popup"><%= "%5d" % [ diff_rate ] %> | <%= "%.3f" % [ diff_possibility ] %></span>
94 <%= rate != 0 ? "%5d" % [ rate ] : "N/A" %> </td>
96 <%= "%5d" % [ win ] %> </td>
98 <%= "%5d" % [ loss ] %> </td>
100 <%= "%.3f" % [win_rate] %> </td>
101 <td class="last_modified">
102 <%= show_date(last_modified) %> </td>
107 tables << table.result(binding)
110 body = erb.result(binding)
118 # vim: ts=2 sw=2 sts=0
123 <title>Shogi Server Rating</title>
124 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
125 <style type="text/css"><!--
126 BODY {margin: 10px 60px;
128 TABLE {margin-left: auto;
130 border-collapse: collapse;
133 CAPTION { caption-side: left;}
134 TH {border: solid 1px;}
135 TD {padding-left: 10px;
138 .name {text-align: center;
140 .rate, .ngames, .win_rate {text-align: right;}
141 .last_modified {text-align: left;}
142 .gps, .yowai_gps {background-color: lightgreen;}
143 .today {background-color: #FFD700;}
144 .this_week {background-color: #FFDAB9;}
146 DIV.footer {text-align: right;
152 background-color: #ffffaa;
155 .popup { display: none;
160 border: 1px solid black;
163 text-decoration:none;
169 <h1>Shogi Server Rating</h1>
171 % tables.each_with_index do |t, index|
173 <caption>Group: <%=group_names[index]%></caption>
179 <col class="win_rate">
180 <col class="last_modified">
189 <th>last_modified</th>
197 <hr style="width:50%; margin:1em auto;">
201 <p>Groups are independently rated. You can not compare rates across them.
202 <p>The average of the rates in a group is always 1000.
203 <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
208 <p>Last modified at <%=Time.now%>