From 9005f4d0d07ee81efd5313f9f9faae6791d6dd60 Mon Sep 17 00:00:00 2001 From: Madhav Bhagat Date: Sun, 29 Nov 2015 18:02:20 +0530 Subject: [PATCH] Add files/lines by extension by date --- config/locales/en.yml | 2 + lib/git_stats/git_data/repo.rb | 53 +++++++++++++++++-- lib/git_stats/stats_view/charts/charts.rb | 2 +- .../stats_view/charts/repo_charts.rb | 20 +++++++ templates/files/_files.haml | 4 ++ templates/files/by_extension_by_date.haml | 1 + templates/lines/_lines.haml | 4 ++ templates/lines/by_extension_by_date.haml | 1 + 8 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 templates/files/by_extension_by_date.haml create mode 100644 templates/lines/by_extension_by_date.haml diff --git a/config/locales/en.yml b/config/locales/en.yml index f32c61870..4c918964a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/lib/git_stats/git_data/repo.rb b/lib/git_stats/git_data/repo.rb index 5fd2440f3..efece77a8 100644 --- a/lib/git_stats/git_data/repo.rb +++ b/lib/git_stats/git_data/repo.rb @@ -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) diff --git a/lib/git_stats/stats_view/charts/charts.rb b/lib/git_stats/stats_view/charts/charts.rb index 5b94c0337..f12fdcb55 100644 --- a/lib/git_stats/stats_view/charts/charts.rb +++ b/lib/git_stats/stats_view/charts/charts.rb @@ -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 diff --git a/lib/git_stats/stats_view/charts/repo_charts.rb b/lib/git_stats/stats_view/charts/repo_charts.rb index 3b6172259..7413211d2 100644 --- a/lib/git_stats/stats_view/charts/repo_charts.rb +++ b/lib/git_stats/stats_view/charts/repo_charts.rb @@ -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( diff --git a/templates/files/_files.haml b/templates/files/_files.haml index fd234f55e..67ad0f36e 100644 --- a/templates/files/_files.haml +++ b/templates/files/_files.haml @@ -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) diff --git a/templates/files/by_extension_by_date.haml b/templates/files/by_extension_by_date.haml new file mode 100644 index 000000000..d31c9220e --- /dev/null +++ b/templates/files/by_extension_by_date.haml @@ -0,0 +1 @@ += render_partial('files/_files', page: :files_by_extension_by_date) diff --git a/templates/lines/_lines.haml b/templates/lines/_lines.haml index 81292e105..fea1fc0a0 100644 --- a/templates/lines/_lines.haml +++ b/templates/lines/_lines.haml @@ -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) diff --git a/templates/lines/by_extension_by_date.haml b/templates/lines/by_extension_by_date.haml new file mode 100644 index 000000000..7969e4cb3 --- /dev/null +++ b/templates/lines/by_extension_by_date.haml @@ -0,0 +1 @@ += render_partial('lines/_lines', page: :lines_by_extension_by_date)