4 # Author:: Daigo Moriwaki
5 # Homepage:: http://sourceforge.jp/projects/shogi-server/
8 # Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 # mk_html generates an html page from a players.yaml.
31 # ./mk_html [OPTION] < players.yaml > rating.html
41 # * Ruby 1.8.7 and RDoc
43 # $ sudo aptitude install ruby1.8 rdoc1.8
54 if (Time.now - time < 30*60)
56 elsif (Time.now - time < 24*60*60)
57 return time.strftime("%Y-%m-%d")
58 # return "%d hours ago" % [(Time.now - time)/3600]
60 return time.strftime("%Y-%m-%d")
71 def remove_long_to_see_players(file)
72 return unless file["players"][999] # only for Not-Yet-Rated players
74 file["players"][999].delete_if do |key, value|
75 value['last_modified'] < Time.now - 24*3600*30 # 30 days
81 opts = OptionParser.new
82 opts.on("-h", "--help"){ RDoc::usage(0, 'Synopsis', 'Usage') }
83 opts.on("-w","--wdoor") { $wdoor=true }
84 opts.parse(ARGV) rescue RDoc::usage(1, 'Synopsis', 'Usage')
87 while l = $stdin.gets do
90 file = YAML::load(lines)
91 erb = ERB.new( DATA.read, nil, "%>" )
94 file["players"].keys.sort.each do |index|
96 group_names << "#{index}"
98 group_names << "Not-Yet-Rated Players"
101 remove_long_to_see_players(file)
107 file["players"].keys.each do |group_index|
108 file["players"][group_index].each do |player, yaml|
109 if player == "YSS+707d4f98d9d2620cdaab58f19d02a2e4"
110 yss_rate = yaml['rate']
116 file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
117 sorted_keys = yaml.keys.sort do |a,b|
118 # sort players in a group by one's rate
119 if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0
120 # mainly for not-rated-yet players
121 yaml[b]['last_modified'] <=> yaml[a]['last_modified']
123 yaml[b]['rate'] <=> yaml[a]['rate']
127 table = ERB.new(<<ENDTABLE, nil, "%>")
128 % sorted_keys.each do |key|
130 win = yaml[key]['win']
131 loss = yaml[key]['loss']
132 win_rate = win.to_f / (win + loss)
133 last_modified = yaml[key]['last_modified']
135 player_decoration = "default"
137 case (Time.now - last_modified)/60 # minutes
138 when (0..30) then player_decoration = "current"
139 when (0..(1*60*24)) then player_decoration = "today"
140 when (0..(7*60*24)) then player_decoration = "this_week"
144 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
145 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
148 rate = yaml[key]['rate']
150 diff_rate = rate - top_rate
151 diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
153 <tr class="<%=player_decoration%>">
155 <a id="popup<%=popup_id+=1%>" href="http://wdoor.c.u-tokyo.ac.jp/shogi/tools/view/show-player.cgi?event=LATEST&filter=floodgate&show_self_play=1&user=<%=u key%>"><%= h yaml[key]['name'] %></a>
156 <script type="text/javascript">
157 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
158 context:"popup<%=popup_id%>",
159 text:"<%= h key %>" } );
163 <span id="popup<%=popup_id+=1%>"><%= rate != 0 ? "%5d" % [ rate ] : "N/A" %></span>
164 <script type="text/javascript">
165 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
166 context:"popup<%=popup_id%>",
167 text:"Behind <%= "%5d" % [ diff_rate ] %> (<%= "%.3f" % [ diff_possibility ] %>)" } );
171 <%= "%5d" % [ win ] %> </td>
173 <%= "%5d" % [ loss ] %> </td>
174 <td class="win_rate">
175 <%= "%.3f" % [win_rate] %> </td>
176 <td class="last_modified">
177 <%= show_date(last_modified) %> </td>
180 <%= rate != 0 && yss_rate > 0 ? ("%5d" % [2300 - yss_rate + rate]) : "N/A" %> </td>
186 tables << table.result(binding)
189 body = erb.result(binding)
197 # vim: ts=2 sw=2 sts=0
202 <title>Shogi Server Rating</title>
203 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
205 <!-- License: http://developer.yahoo.com/yui/license.html -->
206 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset-fonts-grids/reset-fonts-grids.css">
207 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/base/base-min.css">
208 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/container/assets/container.css">
209 <!-- Dependencies -->
210 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
211 <!-- OPTIONAL: Animation (only required if enabling Animation) -->
212 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/animation/animation-min.js"></script>
214 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/container/container-min.js"></script>
215 <style type="text/css"><!--
216 TABLE {margin-left: auto;
218 CAPTION { caption-side: left;}
219 .name {text-align: center;
221 .rate, .ngames, .win_rate {text-align: right;}
222 .last_modified {text-align: center;}
223 .gps, .yowai_gps {background-color: lightgreen;}
224 .current {background-color: #FFD700;}
225 .today {background-color: #FFFF00;}
226 .this_week {background-color: #FFFFAA;}
228 #bd {text-align: center;}
229 #ft {text-align: right;}
237 <h1>Shogi Server Rating</h1>
239 % tables.each_with_index do |t, index|
241 <caption>Group: <%=group_names[index]%></caption>
247 <col class="win_rate">
248 <col class="last_modified">
260 <th>last_modified</th>
271 <hr style="width:50%; margin:1em auto;">
275 <p>Groups are independently rated. You can not compare rates across them.
276 <p>The average of the rates in a group is always 1000.
277 <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
284 <p>Last modified at <%=Time.now%>