From 6d0ddf45bada832a315d7f84b3cafd1a92beff34 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 26 Sep 2014 20:32:44 +0300 Subject: Raw implementation of commits stats page Signed-off-by: Dmitriy Zaporozhets --- app/controllers/projects/graphs_controller.rb | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'app/controllers/projects/graphs_controller.rb') 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 -- cgit v1.2.1