OSDN Git Service

Fix a but. Now it can correctly search directories to find csa files.
[shogi-server/shogi-server.git] / mk_html
1 #!/usr/bin/ruby
2 ## $Id$
3
4 ## Copyright (C) 2006 Daigo Moriwaki <daigo at debian dot org>
5 ##
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.
10 ##
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.
15 ##
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
19
20 #
21 # This generates html pages from players.yaml.
22 #
23 # Sample:
24 #   $ ./mk_html < players.yaml > rating.html
25 #   
26
27 require 'yaml'
28 require 'erb'
29
30 include ERB::Util
31
32 def show_date(time)
33   time.strftime("%Y-%m-%d")
34 end
35
36 def usage
37   $stderr.puts <<-EOF
38 USAGE: #{$0} 
39   EOF
40   exit 1
41 end
42
43 def main
44   lines = ""
45   while l = gets do
46     lines << l
47   end
48   yaml = YAML::load(lines)
49
50   sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']}
51
52   erb = ERB.new( DATA.read, nil, "%<>" )
53   body = erb.result(binding)
54   puts body
55 end
56
57 if __FILE__ == $0
58   main
59 end
60
61 # vim: ts=2 sw=2 sts=0
62
63 __END__
64 <html>
65 <head>
66   <title>Shogi Server Rating</title>
67 </head>
68 <body>
69
70 <h1>Shogi Server Rating</h1>
71
72 <table>
73 <tr>
74   <th>name</th> <th>rate</th> <th>win</th> <th>loss</th> <th>win_rate</th> <th>last_modified</th>
75 </tr>
76 <% sorted_keys.each do |key| %>
77   <%
78     win  = yaml[key]['win']
79     loss = yaml[key]['loss']
80     win_rate = win.to_f / (win + loss)
81     last_modified = yaml[key]['last_modified']
82   %>
83   <tr>
84     <td><%=h yaml[key]['name']%></td>
85     <td><%=yaml[key]['rate']%></td>
86     <td><%=win%></td>
87     <td><%=loss%></td>
88     <td><%="%.3f" % [win_rate]%></td>
89     <td><%=show_date(last_modified)%></td>
90   </tr>
91 <% end %>
92 </table>
93
94 </body>
95 </html>
96