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"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
53 sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} # sort players in a group by one's rate
55 table = ERB.new(<<ENDTABLE, nil, "%>")
56 % sorted_keys.each do |key|
58 win = yaml[key]['win']
59 loss = yaml[key]['loss']
60 win_rate = win.to_f / (win + loss)
61 last_modified = yaml[key]['last_modified']
63 player_decoration = "default"
65 case (Time.now - last_modified)/(60*60*24)
66 when (0..1) then player_decoration = "today"
67 when (0..7) then player_decoration = "this_week"
71 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
72 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
75 <tr class="<%=player_decoration%>">
76 <td class="name"> <%= h yaml[key]['name'] %> </td>
77 <td class="rate"> <%= "%5d" % [ yaml[key]['rate'] ] %> </td>
78 <td class="ngames"> <%= "%5d" % [ win ] %> </td>
79 <td class="ngames"> <%= "%5d" % [ loss ] %> </td>
80 <td class="win_rate"> <%= "%.3f" % [win_rate] %> </td>
81 <td class="last_modified"><%= show_date(last_modified) %> </td>
86 tables << table.result(binding)
89 body = erb.result(binding)
97 # vim: ts=2 sw=2 sts=0
102 <title>Shogi Server Rating</title>
103 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
104 <style type="text/css"><!--
105 BODY {margin: 10px 60px;
107 TABLE {margin-left: auto;
109 border-collapse: collapse;
112 CAPTION { caption-side: left;}
113 TH {border: solid 1px;}
114 TD {padding-left: 10px;
117 .name {text-align: center;
119 .rate, .ngames, .win_rate {text-align: right;}
120 .last_modified {text-align: left;}
121 .gps, .yowai_gps {background-color: lightgreen;}
122 .today {background-color: #FFD700;}
123 .this_week {background-color: #FFDAB9;}
125 DIV.footer {text-align: right;
131 <h1>Shogi Server Rating</h1>
133 % tables.each_with_index do |t, index|
135 <caption>Group: <%=index%></caption>
141 <col class="win_rate">
142 <col class="last_modified">
151 <th>last_modified</th>
159 <hr style="width:50%; margin:1em auto;">
163 <p>Groups are independently rated. You can not compare rates across them.
164 <p>The average of the rates in a group is always 1000.
165 <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
170 <p>Last modified at <%=Time.now%>