by_hour and lines_by_date charts

This commit is contained in:
Tomasz Gieniusz 2012-10-13 16:52:25 +02:00
parent d4a144066c
commit 71c06cd8e3
7 changed files with 43 additions and 4 deletions

View File

@ -0,0 +1,5 @@
class Hash
def to_key_indexed_array
self.inject([]) { |acc, (k, v)| acc[k] = v; acc }
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

1
templates/activity.haml Normal file
View File

@ -0,0 +1 @@
= high_chart("by_hour", by_hour)

View File

@ -1 +1,2 @@
= high_chart("files_by_date", files_by_date)
= high_chart("lines_by_date", lines_by_date)