authors charts

This commit is contained in:
Tomasz Gieniusz 2012-10-21 17:34:05 +02:00
parent 35d77a6392
commit ab5795a645
8 changed files with 136 additions and 16 deletions

View file

@ -34,3 +34,10 @@ 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
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

View file

@ -19,6 +19,30 @@ module GitStats
short_stats.map(&:deletions).sum
end
def commits_sum_by_date
sum = 0
commits.map { |commit|
sum += 1
[commit.date, sum]
}
end
def lines_added_by_date
sum = 0
commits.map { |commit|
sum += commit.short_stat.insertions
[commit.date, sum]
}
end
def lines_deleted_by_date
sum = 0
commits.map { |commit|
sum += commit.short_stat.deletions
[commit.date, sum]
}
end
def short_stats
commits.map(&:short_stat)
end

View file

@ -37,12 +37,16 @@ module GitStats
commits.map(&:date).minmax
end
def commits_count_by_author
Hash[authors.map { |author| [author, author.commits.size] }.sort_by { |author, commits| -commits }[0..5]]
end
def lines_added_by_author
Hash[authors.map { |author| [author, author.lines_added] }]
Hash[authors.map { |author| [author, author.lines_added] }.sort_by { |author, lines| -lines }[0..5]]
end
def lines_deleted_by_author
Hash[authors.map { |author| [author, author.lines_deleted] }]
Hash[authors.map { |author| [author, author.lines_deleted] }.sort_by { |author, lines| -lines }[0..5]]
end
def files_count_by_date

View file

@ -6,17 +6,36 @@ module GitStats
@authors = authors
end
def by_authors_wday
def commits_sum_by_author_by_date
Chart.new do |f|
f.multiple_column_chart(
title: :by_authors_wday.t,
y_text: :commits.t,
data_x: Date::ABBR_DAYNAMES,
data_y: @authors.map { |author| {name: author.email, data: author.activity.by_wday.to_key_indexed_array} }
f.multi_date_chart(
data: @authors.sort_by { |author| -author.commits.size }[0..5].map { |author| {name: author.email, data: author.commits_sum_by_date} },
title: :lines_by_date.t,
y_text: :lines.t
)
f.default_legend
end
end
def lines_added_by_author_by_date
Chart.new do |f|
f.multi_date_chart(
data: @authors.sort_by { |author| -author.lines_added }[0..5].map { |author| {name: author.email, data: author.lines_added_by_date} },
title: :lines_by_date.t,
y_text: :lines.t
)
end
end
def lines_deleted_by_author_by_date
Chart.new do |f|
f.multi_date_chart(
data: @authors.sort_by { |author| -author.lines_deleted }[0..5].map { |author| {name: author.email, data: author.lines_deleted_by_date} },
title: :lines_by_date.t,
y_text: :lines.t
)
end
end
end
end
end

View file

@ -42,6 +42,18 @@ module GitStats
)
end
def multi_date_chart(params)
common_options(params)
rangeSelector(selected: 1)
params[:data].each do |s|
series(
name: s[:name],
type: "spline",
data: s[:data].map { |date, value| [date.to_i * 1000, value] }
)
end
end
def date_column_chart(params)
date_chart(params)
data[0][:type] = 'column'

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,
:lines_added_by_author, :lines_deleted_by_author, to: :repo_charts
:commits_count_by_author, :lines_added_by_author, :lines_deleted_by_author, to: :repo_charts
delegate :by_authors_wday, to: :authors_charts
delegate :commits_sum_by_author_by_date, :lines_added_by_author_by_date, :lines_deleted_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,13 +46,13 @@ module GitStats
end
end
[:lines_added_by_author, :lines_deleted_by_author].each do |method|
[:commits_count_by_author, :lines_added_by_author, :lines_deleted_by_author].each do |method|
define_method method do
Chart.new do |f|
f.column_hash_chart(
data: Hash[@repo.send(method).map { |a, l| [a.email, l] }],
title: method.t,
y_text: :lines.t
y_text: method.to_s.split('_').first.to_sym
)
end
end

View file

@ -1,3 +1,57 @@
= high_chart("by_authors_wday", charts.by_authors_wday)
= high_chart("lines_added_by_author", charts.lines_added_by_author)
= high_chart("lines_deleted_by_author", charts.lines_deleted_by_author)
.tabbable.tabs-left
%ul.nav.nav-tabs
%li.active
%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
%li
%a{:href => '#lines_deleted_by_author', 'data-toogle' => 'tab'}= :lines_deleted_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
%li
%a{:href => '#lines_deleted_by_author_by_date', 'data-toogle' => 'tab'}= :lines_deleted_by_author_by_date.t
.tab-content
.tab-pane.active{id: 'commits_count_by_author'}
.page-header
%h1.pagination-centered= :commits_count_by_author.t
= high_chart("charts.commits_count_by_author", charts.commits_count_by_author)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_added_by_author'}
.page-header
%h1.pagination-centered= :lines_added_by_author.t
= high_chart("charts.lines_added_by_author", charts.lines_added_by_author)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_deleted_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)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'commits_sum_by_author_by_date'}
.page-header
%h1.pagination-centered= :commits_sum_by_author_by_date.t
= high_stock("charts.commits_sum_by_author_by_date", charts.commits_sum_by_author_by_date)
%small
%center= "5 #{:best_authors_shown.t}"
.tab-pane{id: 'lines_deleted_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)
%small
%center= "5 #{:best_authors_shown.t}"