diff --git a/lib/git_stats/core_extensions/hash.rb b/lib/git_stats/core_extensions/hash.rb new file mode 100644 index 000000000..995fb370a --- /dev/null +++ b/lib/git_stats/core_extensions/hash.rb @@ -0,0 +1,5 @@ +class Hash + def to_key_indexed_array + self.inject([]) { |acc, (k, v)| acc[k] = v; acc } + end +end \ No newline at end of file diff --git a/lib/git_stats/git_data/blob.rb b/lib/git_stats/git_data/blob.rb index 3e4f55254..d4b717290 100644 --- a/lib/git_stats/git_data/blob.rb +++ b/lib/git_stats/git_data/blob.rb @@ -8,7 +8,7 @@ module GitStats attr_reader :repo, :hash, :filename def lines_count - @lines ||= Command.new(repo, "git cat-file blob #{self.hash} | wc -l").run.to_i + @lines_count ||= Command.new(repo, "git cat-file blob #{self.hash} | wc -l").run.to_i end def content diff --git a/lib/git_stats/git_data/commit.rb b/lib/git_stats/git_data/commit.rb index 8b1a0c07b..7a4a85d7c 100644 --- a/lib/git_stats/git_data/commit.rb +++ b/lib/git_stats/git_data/commit.rb @@ -19,6 +19,10 @@ module GitStats @files_count ||= Command.new(repo, "git ls-tree -r --name-only #{self.hash} | wc -l").run.to_i end + def lines_count + @lines_count ||= files.map(&:lines_count).sum + end + def short_stat @short_stat ||= ShortStat.new(self) end diff --git a/lib/git_stats/stats_view/view.rb b/lib/git_stats/stats_view/view.rb index 65b5c8bf7..f0a09ee14 100644 --- a/lib/git_stats/stats_view/view.rb +++ b/lib/git_stats/stats_view/view.rb @@ -17,7 +17,7 @@ module GitStats end def all_templates - @all_templates ||= (Dir["templates/*.haml"] - Dir["templates/layout.haml"]).map { |t| File.basename(t, ".haml") } + %w(index activity authors files) end def prepare_assets diff --git a/lib/git_stats/stats_view/view_data.rb b/lib/git_stats/stats_view/view_data.rb index 258423fcc..7ebbe0eba 100644 --- a/lib/git_stats/stats_view/view_data.rb +++ b/lib/git_stats/stats_view/view_data.rb @@ -27,11 +27,21 @@ module GitStats shadow: true ) repo.authors.each do |email, author| - f.series(name: email, data: author.activity.by_wday.inject([]) { |acc, (k, v)| acc[k] = v; acc }) + f.series(name: email, data: author.activity.by_wday.to_key_indexed_array) end end end + def by_hour + @by_hour ||= LazyHighCharts::HighChart.new('graph') do |f| + f.chart(type: "column") + f.title(text: "Commits") + f.xAxis(categories: (0..23)) + f.yAxis(min: 0, title: {text: 'Commits'}) + f.series(name: "commits", data: repo.activity.by_hour.to_key_indexed_array) + end + end + def files_by_date @files_by_date ||= LazyHighCharts::HighChart.new('graph') do |f| f.title(text: "Files") @@ -49,6 +59,24 @@ module GitStats ) end end + + def lines_by_date + @lines_by_date ||= LazyHighCharts::HighChart.new('graph') do |f| + f.title(text: "Files") + f.xAxis(type: "datetime") + f.yAxis(min: 0, title: {text: 'Commits'}) + rcommits = repo.commits.reverse + f.series( + type: "area", + name: "commits", + pointInterval: 1.day * 1000, + pointStart: repo.commits.first.date.to_i * 1000, + data: repo.commits.first.date.midnight.upto((repo.commits.last.date + 1.day).midnight).map { |day| + rcommits.find { |c| c.date < day }.lines_count rescue 0 + } + ) + end + end end end end \ No newline at end of file diff --git a/templates/activity.haml b/templates/activity.haml new file mode 100644 index 000000000..1463eacb3 --- /dev/null +++ b/templates/activity.haml @@ -0,0 +1 @@ += high_chart("by_hour", by_hour) \ No newline at end of file diff --git a/templates/files.haml b/templates/files.haml index 9c93e343b..ed5987c6a 100644 --- a/templates/files.haml +++ b/templates/files.haml @@ -1 +1,2 @@ -= high_chart("files_by_date", files_by_date) \ No newline at end of file += high_chart("files_by_date", files_by_date) += high_chart("lines_by_date", lines_by_date) \ No newline at end of file