This commit is contained in:
Tomasz Gieniusz 2012-10-21 23:03:41 +02:00
parent bab4f54430
commit 28ca30ad78
10 changed files with 55 additions and 67 deletions

View File

@ -34,16 +34,16 @@ en:
activity: Activity
activity_by_date: Activity by date
commits_by_date: Commits by date
lines_added_by_author: Lines added by author
lines_deleted_by_author: Lines deleted by author
insertions_by_author: Lines added by author
deletions_by_author: Lines deleted by author
best_authors_shown: best authors shown
commits_count_by_author: Commits count by author
commits_sum_by_author_by_date: Commits sum by author by date
lines_added_by_author_by_date: Lines added by author by date
lines_deleted_by_author_by_date: Lines deleted by author by date
insertions_by_author_by_date: Lines added by author by date
deletions_by_author_by_date: Lines deleted by author by date
best_authors: Best authors
lines_added: Lines added
lines_deleted: Lines deleted
insertions: Lines added
deletions: Lines deleted
first_commit: First_commit
last_commit: Last commit
author: Author

View File

@ -11,14 +11,6 @@ module GitStats
@commits ||= repo.commits.select { |commit| commit.author == self }
end
def lines_added
short_stats.map(&:insertions).sum
end
def lines_deleted
short_stats.map(&:deletions).sum
end
def commits_sum_by_date
sum = 0
commits.map { |commit|
@ -28,6 +20,10 @@ module GitStats
end
[:insertions, :deletions].each do |method|
define_method method do
short_stats.map { |s| s.send(method)} .sum
end
define_method "#{method}_by_date" do
sum = 0
commits.map { |commit|

View File

@ -41,7 +41,7 @@ module GitStats
Hash[authors.map { |author| [author, author.commits.size] }.sort_by { |author, commits| -commits }[0..limit]]
end
[:lines_added, :lines_deleted].each do |method|
[:insertions, :deletions].each do |method|
define_method "#{method}_by_author" do |limit = 4|
Hash[authors.map { |author| [author, author.send(method)] }.sort_by { |author, lines| -lines }[0..limit]]
end

View File

@ -16,23 +16,15 @@ module GitStats
end
end
def lines_added_by_author_by_date(limit = 4)
Chart.new do |f|
f.multi_date_chart(
data: @authors.sort_by { |author| -author.lines_added }[0..limit].map { |author| {name: author.email, data: author.insertions_by_date} },
title: :lines_by_date.t,
y_text: :lines.t
)
end
end
def lines_deleted_by_author_by_date(limit = 4)
Chart.new do |f|
f.multi_date_chart(
data: @authors.sort_by { |author| -author.lines_deleted }[0..limit].map { |author| {name: author.email, data: author.deletions_by_date} },
title: :lines_by_date.t,
y_text: :lines.t
)
[:insertions, :deletions].each do |method|
define_method "#{method}_by_author_by_date" do |limit = 4|
Chart.new do |f|
f.multi_date_chart(
data: @authors.sort_by { |author| -author.send(method) }[0..limit].map { |author| {name: author.email, data: author.send("#{method}_by_date")} },
title: :lines_by_date.t,
y_text: :lines.t
)
end
end
end

View File

@ -3,9 +3,9 @@ module GitStats
module Charts
class All
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date,
:commits_count_by_author, :lines_added_by_author, :lines_deleted_by_author, to: :repo_charts
:commits_count_by_author, :insertions_by_author, :deletions_by_author, to: :repo_charts
delegate :commits_sum_by_author_by_date, :lines_added_by_author_by_date, :lines_deleted_by_author_by_date, to: :authors_charts
delegate :commits_sum_by_author_by_date, :insertions_by_author_by_date, :deletions_by_author_by_date, to: :authors_charts
delegate :activity_by_date, :activity_by_hour, :activity_by_wday, :activity_by_month,
:activity_by_year, to: :activity_charts

View File

@ -46,7 +46,7 @@ module GitStats
end
end
[:commits_count_by_author, :lines_added_by_author, :lines_deleted_by_author].each do |method|
[:commits_count_by_author, :insertions_by_author, :deletions_by_author].each do |method|
define_method method do
Chart.new do |f|
f.column_hash_chart(

View File

@ -14,11 +14,11 @@ describe GitStats::GitData::Author do
end
it 'should count lines added from short stat' do
author.lines_added.should == 50
author.insertions.should == 50
end
it 'should count lines deleted from short stat' do
author.lines_deleted.should == 100
author.deletions.should == 100
end
end

View File

@ -49,14 +49,14 @@ describe GitStats::GitData::Activity do
jd.commits_sum_by_date.map { |d, s| s }.should == [1, 2]
end
it 'should count lines_added_by_date' do
it 'should count insertions_by_date' do
tg.insertions_by_date.map { |d, s| d }.should == tg_commit_dates
tg.insertions_by_date.map { |d, s| s }.should == [4, 9, 14, 15, 20, 1020, 1021, 1021]
jd.insertions_by_date.map { |d, s| d }.should == jd_commit_dates
jd.insertions_by_date.map { |d, s| s }.should == [3, 103]
end
it 'should count lines_deleted_by_date' do
it 'should count deletions_by_date' do
tg.deletions_by_date.map { |d, s| d }.should == tg_commit_dates
tg.deletions_by_date.map { |d, s| s }.should == [0, 0, 4, 4, 9, 9, 10, 10]
jd.deletions_by_date.map { |d, s| d }.should == jd_commit_dates

View File

@ -55,13 +55,13 @@ describe GitStats::GitData::Repo do
end
it 'should count lines_added_by_author' do
repo.lines_added_by_author.keys.should == expected_authors
repo.lines_added_by_author.values.should == [1021, 103]
repo.insertions_by_author.keys.should == expected_authors
repo.insertions_by_author.values.should == [1021, 103]
end
it 'should count lines_deleted_by_author' do
repo.lines_deleted_by_author.keys.should == expected_authors
repo.lines_deleted_by_author.values.should == [10, 0]
repo.deletions_by_author.keys.should == expected_authors
repo.deletions_by_author.values.should == [10, 0]
end
end

View File

@ -5,15 +5,15 @@
%li
%a{:href => '#commits_count_by_author', 'data-toogle' => 'tab'}= :commits_count_by_author.t
%li
%a{:href => '#lines_added_by_author', 'data-toogle' => 'tab'}= :lines_added_by_author.t
%a{:href => '#insertions_by_author', 'data-toogle' => 'tab'}= :insertions_by_author.t
%li
%a{:href => '#lines_deleted_by_author', 'data-toogle' => 'tab'}= :lines_deleted_by_author.t
%a{:href => '#deletions_by_author', 'data-toogle' => 'tab'}= :deletions_by_author.t
%li
%a{:href => '#commits_sum_by_author_by_date', 'data-toogle' => 'tab'}= :commits_sum_by_author_by_date.t
%li
%a{:href => '#lines_added_by_author_by_date', 'data-toogle' => 'tab'}= :lines_added_by_author_by_date.t
%a{:href => '#insertions_by_author_by_date', 'data-toogle' => 'tab'}= :insertions_by_author_by_date.t
%li
%a{:href => '#lines_deleted_by_author_by_date', 'data-toogle' => 'tab'}= :lines_deleted_by_author_by_date.t
%a{:href => '#deletions_by_author_by_date', 'data-toogle' => 'tab'}= :deletions_by_author_by_date.t
.tab-content
.tab-pane.active{id: 'best_authors'}
@ -23,8 +23,8 @@
%tr
%th= :author.t
%th= :commits.t
%th= :lines_added.t
%th= :lines_deleted.t
%th= :insertions.t
%th= :deletions.t
%th= :first_commit.t
%th= :last_commit.t
%th
@ -33,8 +33,8 @@
%tr
%th= author.name
%td= author.commits.size
%td= author.lines_added
%td= author.lines_deleted
%td= author.insertions
%td= author.deletions
%td= author.commits.first.try(:date).try(:to_formatted_s, :long)
%td= author.commits.last.try(:date).try(:to_formatted_s, :long)
%td
@ -58,24 +58,17 @@
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_added_by_author'}
.tab-pane{id: 'insertions_by_author'}
.page-header
%h1.pagination-centered= :lines_added_by_author.t
= high_chart("charts.lines_added_by_author", charts.lines_added_by_author)
%h1.pagination-centered= :insertions_by_author.t
= high_chart("charts.insertions_by_author", charts.insertions_by_author)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_deleted_by_author'}
.tab-pane{id: 'deletions_by_author'}
.page-header
%h1.pagination-centered= :lines_deleted_by_author.t
= high_chart("charts.lines_deleted_by_author", charts.lines_deleted_by_author)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_added_by_author_by_date'}
.page-header
%h1.pagination-centered= :lines_added_by_author_by_date.t
= high_stock("charts.lines_added_by_author_by_date", charts.lines_added_by_author_by_date)
%h1.pagination-centered= :deletions_by_author.t
= high_chart("charts.deletions_by_author", charts.insertions_by_author)
%small
%center= "5 #{:best_authors_shown.t}"
@ -86,9 +79,16 @@
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_deleted_by_author_by_date'}
.tab-pane{id: 'insertions_by_author_by_date'}
.page-header
%h1.pagination-centered= :lines_deleted_by_author_by_date.t
= high_stock("charts.lines_deleted_by_author_by_date", charts.lines_deleted_by_author_by_date)
%h1.pagination-centered= :insertions_by_author_by_date.t
= high_stock("charts.insertions_by_author_by_date", charts.insertions_by_author_by_date)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'deletions_by_author_by_date'}
.page-header
%h1.pagination-centered= :deletions_by_author_by_date.t
= high_stock("charts.deletions_by_author_by_date", charts.deletions_by_author_by_date)
%small
%center= "5 #{:best_authors_shown.t}"