2 # This generates graphs of evaluation values from comments in CSA files.
3 # Ruby libraries that are required:
4 # - RubyGems: http://rubyforge.org/projects/rubygems/
5 # - rgplot: http://rubyforge.org/projects/rgplot/
6 # OS librariles that is required:
7 # - Gnuplot: http://www.gnuplot.info/
8 # On Debian, $ sudo apt-get install gnuplot
10 # Copyright (C) 2008 Daigo Moriwaki <daigo@debian.org>
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
39 attr_reader :ext, :size
51 class LargeFormat < Format
58 plot.format 'x "%y/%m/%d"'
64 class LargePngFormat < LargeFormat
70 def to_image_file(name)
71 return File.join(@root, "#{name}-large.#{ext}")
75 class SmallPngFormat < Format
82 def to_image_file(name)
83 return File.join(@root, "#{name}-small.#{ext}")
94 class SvgFormat < LargeFormat
100 def to_image_file(name)
101 return File.join(@root, "#{name}.#{ext}")
105 def plot(format, name, dates, rates, rdates, rrates)
107 Gnuplot::Plot.new( gp ) do |plot|
110 plot.output format.to_image_file(name)
112 plot.size "ratio #{1/1.618}"
116 plot.timefmt '"%Y-%m-%d"'
117 plot.xrange "[\"%s\":\"%s\"]" %
118 [dates.first.strftime("%Y-%m-%d"),
119 dates.last.strftime("%Y-%m-%d")]
120 ymin = ((rates + rrates).min/50) * 50
121 ymax = ((rates + rrates).max/50 + 1) * 50
122 plot.yrange "[%s:%s]" % [ymin, ymax]
125 data << Gnuplot::DataSet.new([dates, rates]) do |ds|
128 ds.title = "original"
131 data << Gnuplot::DataSet.new([rdates, rrates]) do |ds|
134 ds.title = "relative (rate24)"
142 def load_file(file_name)
143 if /^.*-(\d{8}).yaml$/ =~ file_name
144 date = Date::parse($1)
148 db = YAML::load_file(file_name)
149 return unless db['players'][0]
150 db['players'][0].each do |name, hash|
151 $players[name] ||= {}
152 $players[name][date] = hash['rate'].to_i
158 puts "Usage: #{$0} [--output-dir dir] <players_yaml_files>..."
160 puts " --output-dir dir Images will be located in the dir."
166 parser = GetoptLong.new
167 parser.set_options(['--output-dir', '-o', GetoptLong::REQUIRED_ARGUMENT])
169 parser.each_option do |name, arg|
170 eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_').upcase} = '#{arg}'"
176 while file = ARGV.shift
180 formats = [LargePngFormat.new($OPT_OUTPUT_DIR),
181 SmallPngFormat.new($OPT_OUTPUT_DIR),
182 SvgFormat.new($OPT_OUTPUT_DIR)]
184 $players.each do |name, hash|
185 dates, rates = hash.sort.transpose
186 rdates = dates.find_all do |date|
187 $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"] &&
188 $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"][date]
190 rrates = rdates.map do |date|
191 2300 - $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"][date] + hash[date]
193 formats.each do |format|
194 plot(format, name, dates, rates, rdates, rrates)