diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-26 21:32:44 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-26 21:32:44 +0400 |
commit | 6d0ddf45bada832a315d7f84b3cafd1a92beff34 (patch) | |
tree | bc52485858e00fca3a5d7968978d1534f079ac48 /app/controllers | |
parent | aa46a15d2adaa018b7d8c59e6def2643fb2acab1 (diff) |
Raw implementation of commits stats page
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/graphs_controller.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/controllers/projects/graphs_controller.rb b/app/controllers/projects/graphs_controller.rb index 92bb5607f81..d66465d9579 100644 --- a/app/controllers/projects/graphs_controller.rb +++ b/app/controllers/projects/graphs_controller.rb @@ -13,6 +13,37 @@ class Projects::GraphsController < Projects::ApplicationController end end + def commits + @commits = @project.repository.commits(nil, nil, 2000, 0, true) + @start_date = @commits.last.committed_date.to_date + @end_date = @commits.first.committed_date.to_date + @duration = (@end_date - @start_date).to_i + @authors = @commits.map(&:author_email).uniq.size + @commit_per_day = (@commits.size.to_f / @duration).round(1) + + @commits_per_week_days = {} + Date::DAYNAMES.each { |day| @commits_per_week_days[day] = 0 } + + @commits_per_time = {} + (0..23).to_a.each { |hour| @commits_per_time[hour] = 0 } + + @commits_per_month = {} + (1..31).to_a.each { |day| @commits_per_month[day] = 0 } + + @commits.each do |commit| + hour = commit.committed_date.strftime('%k').to_i + day_of_month = commit.committed_date.strftime('%e').to_i + weekday = commit.committed_date.strftime('%A') + + @commits_per_week_days[weekday] ||= 0 + @commits_per_week_days[weekday] += 1 + @commits_per_time[hour] ||= 0 + @commits_per_time[hour] += 1 + @commits_per_month[day_of_month] ||= 0 + @commits_per_month[day_of_month] += 1 + end + end + private def fetch_graph |