Add files/lines by extension by date

This commit is contained in:
Madhav Bhagat 2015-11-29 18:02:20 +05:30
parent 7314b0349f
commit 9005f4d0d0
8 changed files with 83 additions and 4 deletions

View file

@ -61,3 +61,5 @@ en:
insertions_by_date: Lines added by date
deletions_by_date: Lines deleted by date
changed_lines_by_date: Changed lines by date
lines_by_extension_by_date: Lines per extension by date
files_by_extension_by_date: Files per extension by date

View file

@ -39,6 +39,10 @@ module GitStats
@tree ||= Tree.new(repo: self, relative_path: @tree_path)
end
def command_memoization
@command_memoization_map ||= {}
end
def authors
@authors ||= run_and_parse("git shortlog -se #{commit_range} #{tree_path}").map do |author|
Author.new(repo: self, name: author[:name], email: author[:email])
@ -95,6 +99,44 @@ module GitStats
}].fill_empty_days!(aggregated: true)
end
def files_by_extension_by_date
file_counts_by_date_by_extension = {}
extensions_sums = {}
commits.map do |commit|
commit.files_by_extension_count.map do |ext, count|
extensions_sums[ext] ||= 0;
extensions_sums[ext] = count;
file_counts_by_date_by_extension[ext] ||= {};
file_counts_by_date_by_extension[ext][commit.date.to_date] = extensions_sums[ext]
end
end
@multi_data_file_counts_by_date ||= file_counts_by_date_by_extension.map { |ext, data|
{
name: ext || "NO EXTENSION",
data: data.fill_empty_days!(aggregated:true)
}
}
end
def lines_by_extension_by_date
lines_by_date_by_extension = {}
extensions_sums = {}
commits.map do |commit|
commit.lines_by_extension.map do |ext, count|
extensions_sums[ext] ||= 0;
extensions_sums[ext] = count;
lines_by_date_by_extension[ext] ||= {};
lines_by_date_by_extension[ext][commit.date.to_date] = extensions_sums[ext]
end
end
@multi_data_lines_by_date ||= lines_by_date_by_extension.map { |ext, data|
{
name: ext || "NO EXTENSION",
data: data.fill_empty_days!(aggregated:true)
}
}
end
def last_commit
commits.last
end
@ -124,9 +166,14 @@ module GitStats
end
def run(command)
result = command_runner.run(path, command)
invoke_command_observers(command, result)
result
if (command_memoization[command])
command_memoization[command]
else
result = command_runner.run(path, command)
invoke_command_observers(command, result)
command_memoization[command] = result
result
end
end
def run_and_parse(command)

View file

@ -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, :comments_by_date, to: :repo_charts
delegate :files_by_extension, :files_by_extension_by_date, :lines_by_extension, :lines_by_extension_by_date, :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

View file

@ -27,6 +27,26 @@ module GitStats
end
end
def files_by_extension_by_date
Chart.new do |f|
f.multi_date_chart(
data: @repo.files_by_extension_by_date,
title: :files_by_extension_by_date.t,
y_text: :files.t
)
end
end
def lines_by_extension_by_date
Chart.new do |f|
f.multi_date_chart(
data: @repo.lines_by_extension_by_date,
title: :lines_by_extension_by_date.t,
y_text: :files.t
)
end
end
def files_by_date
Chart.new do |f|
f.date_chart(

View file

@ -4,6 +4,8 @@
%a{:href => 'by_date.html'}= :files_by_date.t
%li{class: page == :files_by_extension ? "active" : ""}
%a{:href => 'by_extension.html'}= :files_by_extension.t
%li{class: page == :files_by_extension_by_date ? "active" : ""}
%a{:href => 'by_extension_by_date.html'}= :files_by_extension_by_date.t
.tab-content
.tab-pane.active
@ -13,3 +15,5 @@
= high_stock("files_by_date", charts.files_by_date)
- elsif page == :files_by_extension
= high_chart("files_by_extension", charts.files_by_extension)
- elsif page == :files_by_extension_by_date
= high_stock("files_by_extension_by_date", charts.files_by_extension_by_date)

View file

@ -0,0 +1 @@
= render_partial('files/_files', page: :files_by_extension_by_date)

View file

@ -4,6 +4,8 @@
%a{:href => 'by_date.html'}= :lines_by_date.t
%li{class: page == :lines_by_extension ? "active" : ""}
%a{:href => 'by_extension.html'}= :lines_by_extension.t
%li{class: page == :lines_by_extension_by_date ? "active" : ""}
%a{:href => 'by_extension_by_date.html'}= :lines_by_extension_by_date.t
.tab-content
.tab-pane.active
@ -13,3 +15,5 @@
= high_stock("lines_by_date", charts.lines_by_date)
- elsif page == :lines_by_extension
= high_chart("lines_by_extension", charts.lines_by_extension)
- elsif page == :lines_by_extension_by_date
= high_stock("lines_by_extension_by_date", charts.lines_by_extension_by_date)

View file

@ -0,0 +1 @@
= render_partial('lines/_lines', page: :lines_by_extension_by_date)