OSDN Git Service

use linear regression to solve system. this is a workaround for singular matrix.
[shogi-server/shogi-server.git] / mk_html
diff --git a/mk_html b/mk_html
index d8c6c53..0ee50e8 100755 (executable)
--- a/mk_html
+++ b/mk_html
@@ -1,29 +1,41 @@
 #!/usr/bin/ruby
-## $Id$
-
-## Copyright (C) 2006 Daigo Moriwaki <daigo at debian dot org>
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
+# $Id$
+#
+# = Copyright
+#
+# Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# = Synopsis
 #
-# This generates html pages from players.yaml.
+# mk_html generates an html page from players.yaml.
+#
+# = Usage
+#
+#   ./mk_html [OPTION] < players.yaml > rating.html
+#
+# -h, --help::
+#    show help
+#
+# -w,--wdoor::
+#    adpot wdoor style
 #
-# Sample:
-#   $ ./mk_html < players.yaml > rating.html
-#   
 
+require 'optparse'
+require 'rdoc/usage'
 require 'yaml'
 require 'erb'
 
@@ -40,9 +52,23 @@ USAGE: #{$0}
   exit 1
 end
 
+def remove_long_to_see_players(file)
+  return unless file["players"][999] # only for Not-Yet-Rated players
+
+  file["players"][999].delete_if do |key, value|
+    value['last_modified'] < Time.now - 24*3600*30 # 30 days
+  end
+end
+
 def main
+  $wdoor = false
+  opts = OptionParser.new
+  opts.on("-h", "--help"){ RDoc::usage(0, 'Synopsis', 'Usage') }
+  opts.on("-w","--wdoor") { $wdoor=true }
+  opts.parse(ARGV) rescue RDoc::usage(1, 'Synopsis', 'Usage')
+
   lines = ""
-  while l = gets do
+  while l = $stdin.gets do
     lines << l
   end
   file = YAML::load(lines)
@@ -56,11 +82,31 @@ def main
       group_names << "Not-Yet-Rated Players"
     end
   end
+  remove_long_to_see_players(file)
 
   popup_id = 0
 
+  if $wdoor
+    yss_rate = 0
+    file["players"].keys.each do |group_index|
+      file["players"][group_index].each do |player, yaml|
+        if player == "YSS+707d4f98d9d2620cdaab58f19d02a2e4"
+          yss_rate = yaml['rate']
+        end
+      end
+    end
+  end
+        
   file["players"].sort.each do |key, yaml| # sort groups in the order written in players.yaml
-  sorted_keys = yaml.keys.sort {|a,b| yaml[b]['rate'] <=> yaml[a]['rate']} # sort players in a group by one's rate
+  sorted_keys = yaml.keys.sort do |a,b| 
+    # sort players in a group by one's rate
+    if yaml[b]['rate'] == 0 && yaml[a]['rate'] == 0
+      # mainly for not-rated-yet players
+      yaml[b]['last_modified'] <=> yaml[a]['last_modified']
+    else
+      yaml[b]['rate'] <=> yaml[a]['rate']
+    end
+  end 
   top_rate = nil  
   table = ERB.new(<<ENDTABLE, nil, "%>")
 % sorted_keys.each do |key|
@@ -89,7 +135,7 @@ def main
   %>
   <tr class="<%=player_decoration%>">
     <td class="name">
-        <span id="popup<%=popup_id+=1%>"><%= h yaml[key]['name'] %></span>
+        <a id="popup<%=popup_id+=1%>" href="http://wdoor.c.u-tokyo.ac.jp/shogi/tools/view/show-player.cgi?event=LATEST&amp;filter=floodgate&amp;show_self_play=1&amp;user=<%= h yaml[key]['name'] %>"><%= h yaml[key]['name'] %></a>
         <script type="text/javascript">
           var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
             context:"popup<%=popup_id%>",
@@ -112,6 +158,10 @@ def main
         <%= "%.3f" % [win_rate] %> </td>
     <td class="last_modified">
         <%= show_date(last_modified) %> </td>
+% if $wdoor & yss_rate
+    <td class="rate">
+        <%= rate != 0 ? "%5d"  % [ 2400 - yss_rate + rate ] : "N/A" %> </td>
+% end
   </tr>
 % end
 ENDTABLE
@@ -178,6 +228,9 @@ __END__
   <col class="ngames">
   <col class="win_rate">
   <col class="last_modified">
+% if $wdoor
+  <col class="rate)">
+% end
 </colgroup>
 <thead>
 <tr>
@@ -187,6 +240,9 @@ __END__
   <th>loss</th> 
   <th>&#37;</th> 
   <th>last_modified</th>
+% if $wdoor
+  <th>(rate24)</th> 
+% end
 </tr>
 </thead>
 <tbody>