root/lang/ruby/coderepos_stat/coderepos-stat.rb

Revision 3034, 0.9 kB (checked in by coji, 12 months ago)

lang/ruby/coderepos_stat: グラフの数値を0-100%でプロット

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id Date Author Rev URL
Line 
1#!/usr/bin/env ruby
2#
3# Author:: MIZOGUCHI Coji <mizoguchi.coji at gmail.com>
4# License:: Distribute under the same terms as Ruby
5#
6# $Id$
7#
8require 'cgi'
9
10stat = {}
11Dir.glob("data/*/*.yaml").sort.each do |f|
12  date = File.basename(File.dirname(f))
13  stat[date] ||= 0
14  stat[date] += 1
15end
16
17cgi = CGI.new
18size = '200x150'
19if cgi.has_key? 'size'
20  m = /(\d+)x(\d+)/.match(cgi['size'])
21  size = '%sx%s' % [m[1], m[2]] if m and m.size == 3
22end
23
24sorted_keys = stat.keys.sort
25sorted_label = sorted_keys.map{|k| "#{k[4..5]}-#{k[6..7]}"}
26sorted_data = sorted_keys.map{|k| stat[k]}
27max = sorted_data.max
28sorted_data = sorted_data.map{|e| (e * 100 / max)}
29
30params = Array.new
31params << "chs=#{CGI.escape(size)}"
32params << "cht=lc"
33params << "chxt=x,y"
34params << "chxl=0:|#{sorted_label.join('|')}|1:||#{max}"
35params << "chd=t:#{sorted_data.join(',')}"
36params << "chtt=CodeRepos%20commits/day"
37
38puts "Location: http://chart.apis.google.com/chart?#{params.join('&')}"
39puts
Note: See TracBrowser for help on using the browser.