require 'fastercsv' require 'SVG/Graph/TimeSeries' h = Hash.new linen = 0 dategroup = Date.new #.select{ |l| l =~ /[a-zA-Z0-9]+/ } `git log --pretty=format:%aD --shortstat . | grep [a-zA-Z0-9]`.each { |line| if line =~ /\d\d:\d\d:\d\d/ then date = Date.parse(line) dategroup = Date.new(date.year, date.month, 1) if h[dategroup] then h[dategroup][:commits] += 1 else h[dategroup] = Hash.new h[dategroup][:commits] = 1 end else line =~ /([\d]+) files changed, ([\d]+) insertions\(\+\), ([\d]+) deletions\(-\)/ h[dategroup][:insert] = (h[dategroup][:insert])? h[dategroup][:insert].to_i + $2.to_i : $2.to_i h[dategroup][:delete] = (h[dategroup][:delete])? h[dategroup][:delete].to_i + $3.to_i : $3.to_i end } FasterCSV.open("/tmp/count.csv", "w") do |csv| h.sort.each { |date, value| csv << [ "#{date.month}/1/#{date.year}", value[:commits], value[:insert] + value[:delete] ] } end commits = Array.new h.each_pair { |date,value| commits.push( date.to_s ) commits.push( value[:commits] ) } graph = SVG::Graph::TimeSeries.new( { :width => 640, :height => 480, :graph_title => "Commits/Month", :show_graph_title => true, :no_css => false, :key => false, :scale_x_integers => true, :scale_y_integers => true, # :min_x_value => 0, # :min_y_value => 0, :show_data_labels => false, :show_x_guidelines => true, :show_x_title => true, :x_title => "Months", :show_y_title => true, :y_title => "Commits", :y_title_text_direction => :bt, :stagger_x_labels => true, :x_label_format => "%m/%d/%y", }) graph.add_data({ :data => commits, :title => 'commits', }) print graph.burn