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"
62 file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
63 sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} # sort players in a group by one's rate
65 table = ERB.new(<<ENDTABLE, nil, "%>")
66 % sorted_keys.each do |key|
68 win = yaml[key]['win']
69 loss = yaml[key]['loss']
70 win_rate = win.to_f / (win + loss)
71 last_modified = yaml[key]['last_modified']
73 player_decoration = "default"
75 case (Time.now - last_modified)/(60*60*24)
76 when (0..1) then player_decoration = "today"
77 when (0..7) then player_decoration = "this_week"
81 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
82 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
85 rate = yaml[key]['rate']
87 diff_rate = rate - top_rate
88 diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
90 <tr class="<%=player_decoration%>">
92 <span id="popup<%=popup_id+=1%>"><%= h yaml[key]['name'] %></span>
93 <script type="text/javascript">
94 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
95 context:"popup<%=popup_id%>",
96 text:"<%= h key %>" } );
100 <span id="popup<%=popup_id+=1%>"><%= rate != 0 ? "%5d" % [ rate ] : "N/A" %></span>
101 <script type="text/javascript">
102 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
103 context:"popup<%=popup_id%>",
104 text:"Behind <%= "%5d" % [ diff_rate ] %> (<%= "%.3f" % [ diff_possibility ] %>)" } );
108 <%= "%5d" % [ win ] %> </td>
110 <%= "%5d" % [ loss ] %> </td>
111 <td class="win_rate">
112 <%= "%.3f" % [win_rate] %> </td>
113 <td class="last_modified">
114 <%= show_date(last_modified) %> </td>
119 tables << table.result(binding)
122 body = erb.result(binding)
130 # vim: ts=2 sw=2 sts=0
135 <title>Shogi Server Rating</title>
136 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
138 <!-- License: http://developer.yahoo.com/yui/license.html -->
139 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset-fonts-grids/reset-fonts-grids.css">
140 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/base/base-min.css">
141 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/container/assets/container.css">
142 <!-- Dependencies -->
143 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
144 <!-- OPTIONAL: Animation (only required if enabling Animation) -->
145 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/animation/animation-min.js"></script>
147 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/container/container-min.js"></script>
148 <style type="text/css"><!--
149 TABLE {margin-left: auto;
151 CAPTION { caption-side: left;}
152 .name {text-align: center;
154 .rate, .ngames, .win_rate {text-align: right;}
155 .last_modified {text-align: center;}
156 .gps, .yowai_gps {background-color: lightgreen;}
157 .today {background-color: #FFD700;}
158 .this_week {background-color: #FFDAB9;}
160 #bd {text-align: center;}
161 #ft {text-align: right;}
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>
210 <p>Last modified at <%=Time.now%>