OSDN Git Service
(root)
/
shogi-server
/
shogi-server.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch '201312-usiToCsa'
[shogi-server/shogi-server.git]
/
utils
/
players_graph.rb
diff --git
a/utils/players_graph.rb
b/utils/players_graph.rb
index
3ca7f0e
..
32a9456
100755
(executable)
--- a/
utils/players_graph.rb
+++ b/
utils/players_graph.rb
@@
-2,12
+2,14
@@
# This generates graphs of evaluation values from comments in CSA files.
# Ruby libraries that are required:
# - RubyGems: http://rubyforge.org/projects/rubygems/
# This generates graphs of evaluation values from comments in CSA files.
# Ruby libraries that are required:
# - RubyGems: http://rubyforge.org/projects/rubygems/
-# - rgplot: http://rubyforge.org/projects/rgplot/
+# On Debian, $ sudo install rubygems1.8
+# - gnuplot: http://rubyforge.org/projects/rgplot/
+# On Debian, $ sudo gem install gnuplot
# OS librariles that is required:
# - Gnuplot: http://www.gnuplot.info/
# On Debian, $ sudo apt-get install gnuplot
#
# OS librariles that is required:
# - Gnuplot: http://www.gnuplot.info/
# On Debian, $ sudo apt-get install gnuplot
#
-# Copyright (C) 2008
Daigo Moriwaki <daigo@debian.org>
+# Copyright (C) 2008
-2012
Daigo Moriwaki <daigo@debian.org>
#
# Version: $Id$
#
#
# Version: $Id$
#
@@
-30,9
+32,12
@@
require 'getoptlong'
require 'yaml'
require 'date'
require 'set'
require 'yaml'
require 'date'
require 'set'
+require 'logger'
require 'rubygems'
require 'gnuplot'
require 'rubygems'
require 'gnuplot'
+$log = Logger.new(STDERR)
+$log.level = Logger::WARN
$players = {}
class Format
$players = {}
class Format
@@
-103,7
+108,7
@@
def plot(format, name, dates, rates, rdates, rrates)
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|
format.apply(plot)
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|
format.apply(plot)
- plot.title
name
+ plot.title name
plot.output format.to_image_file(name)
#plot.size "ratio #{1/1.618}"
plot.output format.to_image_file(name)
#plot.size "ratio #{1/1.618}"
@@
-138,19
+143,36
@@
def load_file(file_name)
if /^.*-(\d{8}).yaml$/ =~ file_name
date = Date::parse($1)
else
if /^.*-(\d{8}).yaml$/ =~ file_name
date = Date::parse($1)
else
+ $log.error("Invalid file name: %s" % [file_name])
return
end
db = YAML::load_file(file_name)
return
end
db = YAML::load_file(file_name)
- return unless db['players'][0]
+ unless db['players'] && db['players'][0]
+ $log.error("Invalid file format: %s" % [file_name])
+ return
+ end
db['players'][0].each do |name, hash|
$players[name] ||= {}
$players[name][date] = hash['rate'].to_i
end
end
db['players'][0].each do |name, hash|
$players[name] ||= {}
$players[name][date] = hash['rate'].to_i
end
end
+def empty_file?(file)
+ if !FileTest.exists?(file)
+ $log.error("Could not find the file: %s" % [file])
+ return true
+ end
+ if FileTest.zero?(file)
+ $log.error("Empty file: %s" % [file])
+ return true
+ end
+
+ return false
+end
+
if $0 == __FILE__
def usage
if $0 == __FILE__
def usage
- puts "Usage: #{$0}
[--output-dir dir] <players_yaml_files
>..."
+ puts "Usage: #{$0}
--output-dir dir <players_yaml_file> <players_yaml_file
>..."
puts "Options:"
puts " --output-dir dir Images will be located in the dir."
exit 1
puts "Options:"
puts " --output-dir dir Images will be located in the dir."
exit 1
@@
-167,10
+189,16
@@
if $0 == __FILE__
rescue
usage
end
rescue
usage
end
+ usage if !$OPT_OUTPUT_DIR || ARGV.size < 2
while file = ARGV.shift
while file = ARGV.shift
+ next if empty_file?(file)
load_file(file)
end
load_file(file)
end
+
+ if !$players || $players.empty?
+ exit 0
+ end
formats = [LargePngFormat.new($OPT_OUTPUT_DIR),
SmallPngFormat.new($OPT_OUTPUT_DIR),
formats = [LargePngFormat.new($OPT_OUTPUT_DIR),
SmallPngFormat.new($OPT_OUTPUT_DIR),