#! /usr/bin/env ruby # # tdiaryplot - a tool to plot a chart of tDiary's access counter. # # Copyright (C) 2003 Satoru Takabayashi # All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # # You can redistribute it and/or modify it under the terms of # the GNU General Public License version 2. # require 'mingchart' def read_file (file_name) data = [] File.open(file_name) {|f| f.readlines.map {|line| if m = /^(\d\d\d\d-\d\d-\d\d) : (\d+),(\d+),(\d+)$/.match(line) time = Time.parse(m[1]).to_i total = m[2].to_i today = m[3].to_i data.push([time, today, total]) end } } return data end if ARGV.length != 3 puts "Usage: tdiaryplot FONT-FILE LOG-FILE FLASH-FILE" exit(1) end font_file_name = ARGV.shift counter_log_file_name = ARGV.shift flash_file_name = ARGV.shift data = read_file(counter_log_file_name) flash_file_name = flash_file_name chart = MingChart.new(:flash_font => font_file_name, :x_time_scale => true, :drawing_methods => [:draw_dotted_line, :draw_dotted_filled_line], :y_axes => [:left, :right], :right_y_label => "total count", :left_y_label => "daily count", :font_size => 42, :x_time_scale_format => "%m/%d", :line_titles => ["daily count", "total count"] ) (data.first.length - 1).times {|i| chart.add_data(data, i + 1) } chart.draw chart.save(flash_file_name)