mirror of
https://github.com/tomgi/git_stats.git
synced 2025-01-11 06:21:56 +01:00
Added comment stats. Only lines beginning with three slashes are counted, since these stats should reflect comments used for documentation, not inline explanations.
This commit is contained in:
parent
47788e1012
commit
3532de2807
11 changed files with 80 additions and 3 deletions
config/locales
lib/git_stats
templates/comments
|
@ -12,8 +12,10 @@ de:
|
|||
commits_by_hour: Commits in der Stunde
|
||||
files: Dateien
|
||||
lines: Zeilen
|
||||
comments: Kommentare
|
||||
files_by_date: Dateien nach Datum
|
||||
lines_by_date: Zeilen nach Datum
|
||||
comments_by_date: Kommentare nach Datum
|
||||
files_by_extension: Dateien nach Erweiterungen
|
||||
lines_by_extension: Zeilen nach Erweiterungen
|
||||
hour_of_day: Tagesstunden
|
||||
|
|
|
@ -12,8 +12,10 @@ en:
|
|||
commits_by_hour: Commits by hour
|
||||
files: Files
|
||||
lines: Lines
|
||||
comments: Comments
|
||||
files_by_date: Files by date
|
||||
lines_by_date: Lines by date
|
||||
comments_by_date: Comments by date
|
||||
files_by_extension: Files by extension
|
||||
lines_by_extension: Lines by extension
|
||||
hour_of_day: Hour of day
|
||||
|
|
|
@ -18,6 +18,7 @@ require 'git_stats/git_data/command_runner'
|
|||
require 'git_stats/git_data/commit'
|
||||
require 'git_stats/git_data/repo'
|
||||
require 'git_stats/git_data/short_stat'
|
||||
require 'git_stats/git_data/comment_stat'
|
||||
|
||||
require 'git_stats/stats_view/template'
|
||||
require 'git_stats/stats_view/view'
|
||||
|
|
32
lib/git_stats/git_data/comment_stat.rb
Normal file
32
lib/git_stats/git_data/comment_stat.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module GitStats
|
||||
module GitData
|
||||
class CommentStat
|
||||
attr_reader :commit, :insertions, :deletions
|
||||
|
||||
def initialize(commit)
|
||||
@commit = commit
|
||||
calculate_stat
|
||||
end
|
||||
|
||||
def changed_lines
|
||||
insertions + deletions
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{self.class} #@commit"
|
||||
end
|
||||
|
||||
private
|
||||
def calculate_stat
|
||||
stat_line = commit.repo.run("git show #{commit.sha} | awk 'BEGIN {adds=0; dels=0} {if ($0 ~ /^\\+\\/\\/\\//) adds++; if ($0 ~ /^\-\\/\\/\\//) dels++} END {print adds \" insertions \" dels \" deletes\"}'").lines.to_a[0]
|
||||
if stat_line.blank?
|
||||
@insertions = @deletions = 0
|
||||
else
|
||||
@insertions = stat_line[/(\d+) insertions?/, 1].to_i
|
||||
@deletions = stat_line[/(\d+) deletes?/, 1].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -50,6 +50,10 @@ module GitStats
|
|||
@short_stat ||= ShortStat.new(self)
|
||||
end
|
||||
|
||||
def comment_stat
|
||||
@comment_stat ||= CommentStat.new(self)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{self.class} #@sha"
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module GitStats
|
|||
attr_reader :path, :first_commit_sha, :last_commit_sha
|
||||
|
||||
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
|
||||
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit
|
||||
:files_count, :binary_files, :text_files, :lines_count, :comments_count, to: :last_commit
|
||||
|
||||
def initialize(params)
|
||||
super(params)
|
||||
|
@ -63,6 +63,15 @@ module GitStats
|
|||
}].fill_empty_days!(aggregated: true)
|
||||
end
|
||||
|
||||
def comments_count_by_date
|
||||
sum = 0
|
||||
@comment_count_each_day ||= Hash[commits.map { |commit|
|
||||
sum += commit.comment_stat.insertions
|
||||
sum -= commit.comment_stat.deletions
|
||||
[commit.date.to_date, sum]
|
||||
}].fill_empty_days!(aggregated: true)
|
||||
end
|
||||
|
||||
def last_commit
|
||||
commits.last
|
||||
end
|
||||
|
@ -79,6 +88,10 @@ module GitStats
|
|||
@short_stats ||= commits.map(&:short_stat)
|
||||
end
|
||||
|
||||
def comment_stats
|
||||
@comment_stats ||= commits.map(&:comment_stat)
|
||||
end
|
||||
|
||||
def activity
|
||||
@activity ||= Activity.new(commits)
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module GitStats
|
|||
module StatsView
|
||||
module Charts
|
||||
class All
|
||||
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date, to: :repo_charts
|
||||
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date, :comments_by_date, to: :repo_charts
|
||||
|
||||
delegate :commits_sum_by_author_by_date, :changed_lines_by_author_by_date,
|
||||
:insertions_by_author_by_date, :deletions_by_author_by_date, to: :authors_charts
|
||||
|
|
|
@ -47,6 +47,16 @@ module GitStats
|
|||
end
|
||||
end
|
||||
|
||||
def comments_by_date
|
||||
Chart.new do |f|
|
||||
f.date_chart(
|
||||
data: @repo.comments_count_by_date,
|
||||
title: :comments_by_date.t,
|
||||
y_text: :comments.t
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,7 +55,8 @@ module GitStats
|
|||
activity: 'activity/by_date.html',
|
||||
authors: 'authors/best_authors.html',
|
||||
files: 'files/by_date.html',
|
||||
lines: 'lines/by_date.html'
|
||||
lines: 'lines/by_date.html',
|
||||
comments: 'comments/by_date.html'
|
||||
}
|
||||
end
|
||||
|
||||
|
|
11
templates/comments/_comments.haml
Normal file
11
templates/comments/_comments.haml
Normal file
|
@ -0,0 +1,11 @@
|
|||
.tabbable.tabs-left
|
||||
%ul.nav.nav-tabs
|
||||
%li{class: page == :comments_by_date ? "active" : ""}
|
||||
%a{:href => 'by_date.html'}= :comments_by_date.t
|
||||
|
||||
.tab-content
|
||||
.tab-pane.active
|
||||
.page-header
|
||||
%h1.pagination-centered= page.t
|
||||
- if page == :comments_by_date
|
||||
= high_stock("comments_by_date", charts.comments_by_date)
|
1
templates/comments/by_date.haml
Normal file
1
templates/comments/by_date.haml
Normal file
|
@ -0,0 +1 @@
|
|||
= render_partial('comments/_comments', page: :comments_by_date)
|
Loading…
Reference in a new issue