Class: GitPm::CommitsPerMonth
- Inherits:
-
Object
- Object
- GitPm::CommitsPerMonth
- Defined in:
- lib/git_pm/commits_per_month.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ CommitsPerMonth
constructor
A new instance of CommitsPerMonth.
- #run! ⇒ Object
Constructor Details
#initialize(options) ⇒ CommitsPerMonth
Returns a new instance of CommitsPerMonth.
5 6 7 |
# File 'lib/git_pm/commits_per_month.rb', line 5 def initialize() @branch = .shift || "master" end |
Instance Method Details
#run! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/git_pm/commits_per_month.rb', line 9 def run! h = Hash.new linen = 0 dategroup = Date.new `git log --pretty=format:%aD --shortstat #{@branch} | grep [a-zA-Z0-9]`.each do |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 end CSV.open("/tmp/count.csv", "w") do |csv| h.sort.each do |date, value| csv << [ "#{date.month}/1/#{date.year}", value[:commits], value[:insert] + value[:delete] ] end end commits = Array.new h.each_pair do |date,value| commits.push( date.to_s ) commits.push( value[:commits] ) end 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, :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", }) if commits.size < 2 $stderr.puts "not enought data to generate the graph" return "" end graph.add_data({ :data => commits, :title => 'commits', }) graph.burn end |