OSDN Git Service

* [shogi-server]
[shogi-server/shogi-server.git] / mk_html
diff --git a/mk_html b/mk_html
index cf29e4e..52a2f76 100755 (executable)
--- a/mk_html
+++ b/mk_html
@@ -1,36 +1,55 @@
 #!/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
+#
+# mk_html generates an html page from players.yaml.
+#
+# = Usage
+#
+#   ./mk_html [OPTION] < players.yaml > rating.html
 #
-# This generates html pages from players.yaml.
+# -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'
 
 include ERB::Util
 
 def show_date(time)
-  time.strftime("%Y-%m-%d")
+  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 usage
@@ -49,8 +68,14 @@ def remove_long_to_see_players(file)
 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)
@@ -67,6 +92,17 @@ def main
   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 do |a,b| 
@@ -89,9 +125,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
@@ -129,6 +166,10 @@ def main
         <%= "%.3f" % [win_rate] %> </td>
     <td class="last_modified">
         <%= show_date(last_modified) %> </td>
+% if $wdoor
+    <td class="rate">
+        <%= rate != 0 && yss_rate > 0 ? ("%5d"  % [2300 - yss_rate + rate]) : "N/A" %> </td>
+% end
   </tr>
 % end
 ENDTABLE
@@ -171,8 +212,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;}
@@ -195,6 +237,9 @@ __END__
   <col class="ngames">
   <col class="win_rate">
   <col class="last_modified">
+% if $wdoor
+  <col class="rate)">
+% end
 </colgroup>
 <thead>
 <tr>
@@ -204,6 +249,9 @@ __END__
   <th>loss</th> 
   <th>&#37;</th> 
   <th>last_modified</th>
+% if $wdoor
+  <th>(rate24)</th> 
+% end
 </tr>
 </thead>
 <tbody>