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
46 class LargeFormat < Format
54 plot.format 'x "%y/%m/%d"'
62 class LargePngFormat < LargeFormat
68 def to_image_file(name)
69 return File.join(@root, "#{name}-large.#{ext}")
73 class SmallPngFormat < Format
79 def to_image_file(name)
80 return File.join(@root, "#{name}-small.#{ext}")
84 plot.terminal "png size 320,200 crop"
91 class SvgFormat < LargeFormat
97 def to_image_file(name)
98 return File.join(@root, "#{name}.#{ext}")
102 def plot(format, name, dates, rates, rdates, rrates)
104 Gnuplot::Plot.new( gp ) do |plot|
107 plot.output format.to_image_file(name)
109 #plot.size "ratio #{1/1.618}"
111 plot.timefmt '"%Y-%m-%d"'
112 plot.xrange "[\"%s\":\"%s\"]" %
113 [dates.first.strftime("%Y-%m-%d"),
114 dates.last.strftime("%Y-%m-%d")]
115 ymin = ((rates + rrates).min/50) * 50
116 ymax = ((rates + rrates).max/50 + 1) * 50
117 plot.yrange "[%s:%s]" % [ymin, ymax]
120 data << Gnuplot::DataSet.new([dates, rates]) do |ds|
123 ds.title = "original"
126 data << Gnuplot::DataSet.new([rdates, rrates]) do |ds|
129 ds.title = "relative (rate24)"
137 def load_file(file_name)
138 if /^.*-(\d{8}).yaml$/ =~ file_name
139 date = Date::parse($1)
143 db = YAML::load_file(file_name)
144 return unless db['players'][0]
145 db['players'][0].each do |name, hash|
146 $players[name] ||= {}
147 $players[name][date] = hash['rate'].to_i
153 puts "Usage: #{$0} [--output-dir dir] <players_yaml_files>..."
155 puts " --output-dir dir Images will be located in the dir."
161 parser = GetoptLong.new
162 parser.set_options(['--output-dir', '-o', GetoptLong::REQUIRED_ARGUMENT])
164 parser.each_option do |name, arg|
165 eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_').upcase} = '#{arg}'"
171 while file = ARGV.shift
175 formats = [LargePngFormat.new($OPT_OUTPUT_DIR),
176 SmallPngFormat.new($OPT_OUTPUT_DIR),
177 SvgFormat.new($OPT_OUTPUT_DIR)]
179 $players.each do |name, hash|
180 dates, rates = hash.sort.transpose
181 rdates = dates.find_all do |date|
182 $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"] &&
183 $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"][date]
185 rrates = rdates.map do |date|
186 2300 - $players["YSS+707d4f98d9d2620cdaab58f19d02a2e4"][date] + hash[date]
188 formats.each do |format|
189 plot(format, name, dates, rates, rdates, rrates)