OSDN Git Service

util/statistics.rb: Updated to investigate floodgate-600-10 games.
[shogi-server/shogi-server.git] / mk_html
diff --git a/mk_html b/mk_html
index 0ee50e8..6dfd3b1 100755 (executable)
--- a/mk_html
+++ b/mk_html
@@ -1,9 +1,11 @@
 #!/usr/bin/ruby
 # $Id$
 #
-# = Copyright
+# Author:: Daigo Moriwaki
+# Homepage:: http://sourceforge.jp/projects/shogi-server/
 #
-# Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
+#--
+# Copyright (C) 2006-2012 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
 # 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
+# == Synopsis
 #
-# mk_html generates an html page from players.yaml.
+# mk_html generates an html page from players.yaml.
 #
-# = Usage
+# == Usage
 #
-#   ./mk_html [OPTION] < players.yaml > rating.html
+# ./mk_html [OPTION] < players.yaml > rating.html
 #
-# -h, --help::
+# [<tt>-h, --help</tt>]
 #    show help
 #
-# -w,--wdoor::
+# [<tt>-w,--wdoor</tt>]
 #    adpot wdoor style
 #
+# [<tt>--footer</tt> <i>filename</i>]
+#    insert contents in the filename at the bottom of a genrated page.
+#
+# == Prerequire
+#
+# * Ruby 2.0.0 or later
+#
+#   $ sudo aptitude install ruby ruby
+#
+# == Example
+#
+#   $ ./mk_html --footer ./wdoor_1000.html < players.yaml > players.html
+#
+#   $ cat ./wdoor-1000.html
+#   <p>The average of the rates in a group is always 1000. 
+#   <p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
+#
 
 require 'optparse'
-require 'rdoc/usage'
 require 'yaml'
 require 'erb'
 
 include ERB::Util
 
 def show_date(time)
-  time.strftime("%Y-%m-%d")
-end
-
-def usage
-  $stderr.puts <<-EOF
-USAGE: #{$0} 
-  EOF
-  exit 1
+  if (Time.now - time < 30*60)
+    return "on line"
+  elsif (Time.now - time < 24*60*60)
+    return time.strftime("%Y-%m-%d")
+    # return "%d hours ago" % [(Time.now - time)/3600]
+  else
+    return time.strftime("%Y-%m-%d")
+  end
 end
 
 def remove_long_to_see_players(file)
@@ -62,10 +81,27 @@ end
 
 def main
   $wdoor = false
+  $footer_content = nil
   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')
+  opts.banner = "Usage: mk_html [OPTIONS]"
+  opts.on("--footer filename", String, "Insert contents of the filename at the bottom of a genrated page") do |filename|
+    unless File.exist?(filename)
+      $stderr.puts "File not found: %s" % [filename]
+      raise
+    end
+    $footer_content = File.open(filename).read
+  end
+  opts.on("-w","--wdoor", "adopt a wdoor style") { $wdoor=true }
+  opts.on_tail("-h", "--help", "show this message") do
+    puts opts
+    exit
+  end
+  begin
+    opts.parse(ARGV) 
+  rescue
+    puts opts
+    exit -1
+  end
 
   lines = ""
   while l = $stdin.gets do
@@ -118,9 +154,10 @@ def main
     
     player_decoration = "default"
 
-    case (Time.now - last_modified)/(60*60*24)
-    when (0..1) then player_decoration = "today"
-    when (0..7) then player_decoration = "this_week"
+    case (Time.now - last_modified)/60 # minutes
+    when (0..30)        then player_decoration = "current"
+    when (0..(1*60*24)) then player_decoration = "today"
+    when (0..(7*60*24)) then player_decoration = "this_week"
     end
     
     case key
@@ -135,7 +172,7 @@ def main
   %>
   <tr class="<%=player_decoration%>">
     <td class="name">
-        <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>
+        <a id="popup<%=popup_id+=1%>" href="/shogi/view/show-player.cgi?event=LATEST&amp;filter=floodgate&amp;show_self_play=1&amp;user=<%=u key%>"><%= h yaml[key]['name'] %></a>
         <script type="text/javascript">
           var tooltip<%=popup_id%> = new YAHOO.widget.Tooltip("myTooltip", {
             context:"popup<%=popup_id%>",
@@ -158,9 +195,9 @@ def main
         <%= "%.3f" % [win_rate] %> </td>
     <td class="last_modified">
         <%= show_date(last_modified) %> </td>
-% if $wdoor & yss_rate
+% if $wdoor
     <td class="rate">
-        <%= rate != 0 ? "%5d"  % [ 2400 - yss_rate + rate ] : "N/A" %> </td>
+        <%= rate != 0 && yss_rate > 0 ? ("%5d"  % [2300 - yss_rate + rate]) : "N/A" %> </td>
 % end
   </tr>
 % end
@@ -204,8 +241,9 @@ __END__
     .rate, .ngames, .win_rate {text-align: right;}
     .last_modified {text-align: center;}
     .gps, .yowai_gps {background-color: lightgreen;}
-    .today     {background-color: #FFD700;}
-    .this_week {background-color: #FFDAB9;}
+    .current   {background-color: #FFD700;}
+    .today     {background-color: #FFFF00;}
+    .this_week {background-color: #FFFFAA;}
 
     #bd {text-align: center;}
     #ft {text-align: right;}
@@ -255,8 +293,8 @@ __END__
 % end
 
 <p>Groups are independently rated. You can not compare rates across them.
-<p>The average of the rates in a group is always 1000. 
-<p><a href="http://wdoor.c.u-tokyo.ac.jp/shogi/">BACK</a>
+
+<%= $footer_content %>
 
 <hr/>
 </div>