6 # Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 # mk_html generates an html page from players.yaml.
28 # ./mk_html [OPTION] < players.yaml > rating.html
45 if (Time.now - time < 30*60)
47 elsif (Time.now - time < 24*60*60)
48 return time.strftime("%Y-%m-%d")
49 # return "%d hours ago" % [(Time.now - time)/3600]
51 return time.strftime("%Y-%m-%d")
62 def remove_long_to_see_players(file)
63 return unless file["players"][999] # only for Not-Yet-Rated players
65 file["players"][999].delete_if do |key, value|
66 value['last_modified'] < Time.now - 24*3600*30 # 30 days
72 opts = OptionParser.new
73 opts.on("-h", "--help"){ RDoc::usage(0, 'Synopsis', 'Usage') }
74 opts.on("-w","--wdoor") { $wdoor=true }
75 opts.parse(ARGV) rescue RDoc::usage(1, 'Synopsis', 'Usage')
78 while l = $stdin.gets do
81 file = YAML::load(lines)
82 erb = ERB.new( DATA.read, nil, "%>" )
85 file["players"].keys.sort.each do |index|
87 group_names << "#{index}"
89 group_names << "Not-Yet-Rated Players"
92 remove_long_to_see_players(file)
98 file["players"].keys.each do |group_index|
99 file["players"][group_index].each do |player, yaml|
100 if player == "YSS+707d4f98d9d2620cdaab58f19d02a2e4"
101 yss_rate = yaml['rate']
107 file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
108 sorted_keys = yaml.keys.sort do |a,b|
109 # sort players in a group by one's rate
110 if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0
111 # mainly for not-rated-yet players
112 yaml[b]['last_modified'] <=> yaml[a]['last_modified']
114 yaml[b]['rate'] <=> yaml[a]['rate']
118 table = ERB.new(<<ENDTABLE, nil, "%>")
119 % sorted_keys.each do |key|
121 win = yaml[key]['win']
122 loss = yaml[key]['loss']
123 win_rate = win.to_f / (win + loss)
124 last_modified = yaml[key]['last_modified']
126 player_decoration = "default"
128 case (Time.now - last_modified)/60 # minutes
129 when (0..30) then player_decoration = "current"
130 when (0..(1*60*24)) then player_decoration = "today"
131 when (0..(7*60*24)) then player_decoration = "this_week"
135 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
136 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
139 rate = yaml[key]['rate']
141 diff_rate = rate - top_rate
142 diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
144 <tr class="<%=player_decoration%>">
146 <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=<%= h key.sub("+", "%2b") %>"><%= h yaml[key]['name'] %></a>
147 <script type="text/javascript">
148 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
149 context:"popup<%=popup_id%>",
150 text:"<%= h key %>" } );
154 <span id="popup<%=popup_id+=1%>"><%= rate != 0 ? "%5d" % [ rate ] : "N/A" %></span>
155 <script type="text/javascript">
156 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
157 context:"popup<%=popup_id%>",
158 text:"Behind <%= "%5d" % [ diff_rate ] %> (<%= "%.3f" % [ diff_possibility ] %>)" } );
162 <%= "%5d" % [ win ] %> </td>
164 <%= "%5d" % [ loss ] %> </td>
165 <td class="win_rate">
166 <%= "%.3f" % [win_rate] %> </td>
167 <td class="last_modified">
168 <%= show_date(last_modified) %> </td>
171 <%= rate != 0 && yss_rate > 0 ? ("%5d" % [2300 - yss_rate + rate]) : "N/A" %> </td>
177 tables << table.result(binding)
180 body = erb.result(binding)
188 # vim: ts=2 sw=2 sts=0
193 <title>Shogi Server Rating</title>
194 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
196 <!-- License: http://developer.yahoo.com/yui/license.html -->
197 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset-fonts-grids/reset-fonts-grids.css">
198 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/base/base-min.css">
199 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/container/assets/container.css">
200 <!-- Dependencies -->
201 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
202 <!-- OPTIONAL: Animation (only required if enabling Animation) -->
203 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/animation/animation-min.js"></script>
205 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/container/container-min.js"></script>
206 <style type="text/css"><!--
207 TABLE {margin-left: auto;
209 CAPTION { caption-side: left;}
210 .name {text-align: center;
212 .rate, .ngames, .win_rate {text-align: right;}
213 .last_modified {text-align: center;}
214 .gps, .yowai_gps {background-color: lightgreen;}
215 .current {background-color: #FFD700;}
216 .today {background-color: #FFFF00;}
217 .this_week {background-color: #FFFFAA;}
219 #bd {text-align: center;}
220 #ft {text-align: right;}
228 <h1>Shogi Server Rating</h1>
230 % tables.each_with_index do |t, index|
232 <caption>Group: <%=group_names[index]%></caption>
238 <col class="win_rate">
239 <col class="last_modified">
251 <th>last_modified</th>
262 <hr style="width:50%; margin:1em auto;">
266 <p>Groups are independently rated. You can not compare rates across them.
267 <p>The average of the rates in a group is always 1000.
268 <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
275 <p>Last modified at <%=Time.now%>