Commit 6d0ddf45 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Raw implementation of commits stats page

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent aa46a15d
......@@ -22,6 +22,7 @@
#= require raphael
#= require g.raphael-min
#= require g.bar-min
#= require chart-lib.min
#= require branch-graph
#= require highlight.pack
#= require ace/ace
......
@Chart =
labels: []
values: []
init: (labels, values, title) ->
r = Raphael('activity-chart')
fin = ->
@flag = r.popup(@bar.x, @bar.y, @bar.value or "0").insertBefore(this)
fout = ->
@flag.animate
opacity: 0, 300, -> @remove()
r.text(160, 10, title).attr font: "13px sans-serif"
r.barchart(
10, 20, 560, 200,
[values],
{colors:["#456"]}
).label(labels, true)
.hover(fin, fout)
......@@ -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
......
%ul.nav.nav-tabs
= nav_link(action: :show) do
= link_to 'Contributors', project_graph_path
= nav_link(action: :commits) do
= link_to 'Commits', commits_project_graph_path
= render 'head'
%p.lead
Commits statistic for
%strong #{@repository.root_ref}
#{@start_date.strftime('%b %d')} - #{@end_date.strftime('%b %d')}
.row
.col-md-6
%ul
%li
%p.lead
%strong #{@commits.size}
commits during
%strong #{@duration}
days
%li
%p.lead
Average
%strong #{@commit_per_day}
commits per day
%li
%p.lead
Contributed by
%strong #{@authors}
authors
.col-md-6
%div
%p.slead
Commits per day of month
%canvas#month-chart{width: 800, height: 400}
.row
.col-md-6
%div
%p.slead
Commits per day hour (UTC)
%canvas#hour-chart{width: 800, height: 400}
.col-md-6
%div
%p.slead
Commits per weekday
%canvas#weekday-chart{width: 800, height: 400}
:coffeescript
data = {
labels : #{@commits_per_time.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_time.values.to_json}
}]
}
ctx = $("#hour-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
data = {
labels : #{@commits_per_week_days.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_week_days.values.to_json}
}]
}
ctx = $("#weekday-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
data = {
labels : #{@commits_per_month.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_month.values.to_json}
}]
}
ctx = $("#month-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
= render 'head'
.loading-graph
.center
%h3.page-title
......
......@@ -206,7 +206,11 @@ Gitlab::Application.routes.draw do
resources :compare, only: [:index, :create]
resources :blame, only: [:show], constraints: {id: /.+/}
resources :network, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/}
resources :graphs, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/}
resources :graphs, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} do
member do
get :commits
end
end
match "/compare/:from...:to" => "compare#show", as: "compare", via: [:get, :post], constraints: {from: /.+/, to: /.+/}
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment