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")
43 def remove_long_to_see_players(file)
44 return unless file["players"][999] # only for Not-Yet-Rated players
46 file["players"][999].delete_if do |key, value|
47 value['last_modified'] < Time.now - 24*3600*30 # 30 days
56 file = YAML::load(lines)
57 erb = ERB.new( DATA.read, nil, "%>" )
60 file["players"].keys.sort.each do |index|
62 group_names << "#{index}"
64 group_names << "Not-Yet-Rated Players"
67 remove_long_to_see_players(file)
71 file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
72 sorted_keys = yaml.keys.sort do |a,b|
73 # sort players in a group by one's rate
74 if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0
75 # mainly for not-rated-yet players
76 yaml[b]['last_modified'] <=> yaml[a]['last_modified']
78 yaml[b]['rate'] <=> yaml[a]['rate']
82 table = ERB.new(<<ENDTABLE, nil, "%>")
83 % sorted_keys.each do |key|
85 win = yaml[key]['win']
86 loss = yaml[key]['loss']
87 win_rate = win.to_f / (win + loss)
88 last_modified = yaml[key]['last_modified']
90 player_decoration = "default"
92 case (Time.now - last_modified)/(60*60*24)
93 when (0..1) then player_decoration = "today"
94 when (0..7) then player_decoration = "this_week"
98 when "yowai_gps+95908f6c18338f5340371f71523fc5e3" then player_decoration = "yowai_gps"
99 when "gps+11648e4e66e7ed6a86cb7f1d0cf604fe" then player_decoration = "gps"
102 rate = yaml[key]['rate']
104 diff_rate = rate - top_rate
105 diff_possibility = 1.0/(1.0 + 10**(-diff_rate/400.0))
107 <tr class="<%=player_decoration%>">
109 <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 yaml[key]['name'] %>"><%= h yaml[key]['name'] %></a>
110 <script type="text/javascript">
111 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
112 context:"popup<%=popup_id%>",
113 text:"<%= h key %>" } );
117 <span id="popup<%=popup_id+=1%>"><%= rate != 0 ? "%5d" % [ rate ] : "N/A" %></span>
118 <script type="text/javascript">
119 var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
120 context:"popup<%=popup_id%>",
121 text:"Behind <%= "%5d" % [ diff_rate ] %> (<%= "%.3f" % [ diff_possibility ] %>)" } );
125 <%= "%5d" % [ win ] %> </td>
127 <%= "%5d" % [ loss ] %> </td>
128 <td class="win_rate">
129 <%= "%.3f" % [win_rate] %> </td>
130 <td class="last_modified">
131 <%= show_date(last_modified) %> </td>
136 tables << table.result(binding)
139 body = erb.result(binding)
147 # vim: ts=2 sw=2 sts=0
152 <title>Shogi Server Rating</title>
153 <link rel="StyleSheet" type="text/css" href="http://wdoor.c.u-tokyo.ac.jp/shogi/shogi.css">
155 <!-- License: http://developer.yahoo.com/yui/license.html -->
156 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset-fonts-grids/reset-fonts-grids.css">
157 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/base/base-min.css">
158 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/container/assets/container.css">
159 <!-- Dependencies -->
160 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
161 <!-- OPTIONAL: Animation (only required if enabling Animation) -->
162 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/animation/animation-min.js"></script>
164 <script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/container/container-min.js"></script>
165 <style type="text/css"><!--
166 TABLE {margin-left: auto;
168 CAPTION { caption-side: left;}
169 .name {text-align: center;
171 .rate, .ngames, .win_rate {text-align: right;}
172 .last_modified {text-align: center;}
173 .gps, .yowai_gps {background-color: lightgreen;}
174 .today {background-color: #FFD700;}
175 .this_week {background-color: #FFDAB9;}
177 #bd {text-align: center;}
178 #ft {text-align: right;}
186 <h1>Shogi Server Rating</h1>
188 % tables.each_with_index do |t, index|
190 <caption>Group: <%=group_names[index]%></caption>
196 <col class="win_rate">
197 <col class="last_modified">
206 <th>last_modified</th>
214 <hr style="width:50%; margin:1em auto;">
218 <p>Groups are independently rated. You can not compare rates across them.
219 <p>The average of the rates in a group is always 1000.
220 <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
227 <p>Last modified at <%=Time.now%>